Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contentstack Javascript setup with Rollup #105

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30,919 changes: 7,727 additions & 23,192 deletions package-lock.json

Large diffs are not rendered by default.

79 changes: 31 additions & 48 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
"test:e2e": "tape test/index.js | tap-html --out ./tap-html.html",
"test:typescript": "jest --config jest.config.js --testPathPattern=test/typescript",
"automate": "node test.js",
"build:node": "webpack --config webpack/webpack.node.js",
"build:web": "webpack --config webpack/webpack.web.js",
"build:react-native": "webpack --config webpack/webpack.react-native.js",
"build:native-script": "webpack --config webpack/webpack.nativescript.js",
"build": "npm run build:node && npm run build:web && npm run build:react-native && npm run build:native-script",
"build:node": "rollup -c ./rollup/node.config.mjs",
"build:web": "rollup -c ./rollup/web.config.mjs",
"build:react-native": "rollup -c ./rollup/react-native.config.mjs",
"build": "npm run build:node && npm run build:web && npm run build:react-native",
"generate-docs": "node_modules/.bin/jsdoc --configure docs-config.json --verbose",
"prepare": "npm run build",
"pretest": "npm run build"
"prepare": "npm run build"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -64,51 +62,36 @@
"host": "packages-18-east.internal.npmjs.com",
"tmp": "tmp/contentstack-3.15.0.tgz_1477830884275_0.9869455888401717"
},
"devDependencies": {
"@types/jest": "^26.0.24",
"babel-core": "6.26.0",
"babel-loader": "7.1.2",
"babel-plugin-transform-runtime": "6.23.0",
"babel-preset-env": "1.6.1",
"babel-preset-es2015": "6.24.1",
"babel-preset-es2016": "6.24.1",
"babel-preset-stage-1": "6.24.1",
"babel-runtime": "6.26.0",
"clean-webpack-plugin": "^4.0.0",
"compression-webpack-plugin": "^10.0.0",
"dotenv": "^16.0.3",
"es3ify-loader": "0.2.0",
"fetch-mock-jest": "^1.3.0",
"http-proxy-agent": "^3.0.0",
"jest": "^27.5.1",
"jest-html-reporters": "^2.1.7",
"jsdoc": "^4.0.2",
"jshint": "^2.13.6",
"minami": "^1.2.3",
"node-request-interceptor": "^0.6.3",
"nodemailer": "^6.9.1",
"request": "^2.88.2",
"string-replace-loader": "1.3.0",
"taffydb": "^2.7.3",
"tap": "^16.3.4",
"tap-html": "^1.1.0",
"tap-json": "1.0.0",
"tape": "4.8.0",
"terser-webpack-plugin": "^5.3.7",
"ts-jest": "^27.1.5",
"typescript": "^4.9.5",
"uglify-js": "2.8.29",
"webpack": "^5.76.3",
"webpack-cli": "^4.10.0",
"webpack-md5-hash": "0.0.5",
"webpack-merge": "4.1.0",
"webpack-node-externals": "^3.0.0"
},
"dependencies": {
"@contentstack/utils": "^1.2.0",
"@contentstack/utils": "^1.3.0",
"es6-promise": "^4.1.1",
"isomorphic-fetch": "^3.0.0",
"localStorage": "1.0.4",
"qs": "^6.11.2"
},
"devDependencies": {
"@babel/plugin-external-helpers": "^7.23.3",
"@rollup/plugin-alias": "^5.1.0",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.5",
"@rollup/plugin-swc": "^0.3.0",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.5",
"@types/jest": "^29.5.11",
"dotenv": "^16.3.1",
"jest": "^29.7.0",
"jest-html-reporters": "^3.1.5",
"jsdoc": "^4.0.2",
"lodash": "^4.17.21",
"minami": "^1.2.3",
"rollup": "^4.9.0",
"rollup-plugin-node-externals": "^6.1.2",
"taffydb": "^2.7.3",
"tap-html": "^1.1.0",
"tape": "^5.7.2",
"ts-jest": "^29.1.1",
"tslib": "^2.6.2",
"typescript": "^5.3.3"
}
}
55 changes: 55 additions & 0 deletions rollup/node.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { fileURLToPath } from 'node:url'
import { builtinModules } from 'module';
import { defineConfig } from 'rollup';

import commonJs from '@rollup/plugin-commonjs';
import swc from '@rollup/plugin-swc';
import nodeExternals from 'rollup-plugin-node-externals'
import alias from '@rollup/plugin-alias';
import replace from '@rollup/plugin-replace';
import terser from '@rollup/plugin-terser';

import pkg from '../package.json' assert { type: 'json' };



export default defineConfig({
input: 'src/core/contentstack.js',
output: {
dir: './dist/node',
format: 'commonjs'
},
plugins: [
nodeExternals(),
commonJs(),
swc({
exclude: 'node_modules/**',
swc: {
jsc: {
target: 'es2015'
}
}
}),
replace({
values: {
'PLATFORM': 'nodejs',
'VERSION': pkg.version
},
delimiters: ['{{', '}}'],
preventAssignment: true
}),
alias({
entries: [
{
find: 'runtime',
replacement: fileURLToPath(new URL('../src/runtime/node', import.meta.url))
}
]
}),
terser()
],
external: [
...builtinModules,
...Object.keys(pkg.devDependencies)
]
});
58 changes: 58 additions & 0 deletions rollup/react-native.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { fileURLToPath } from 'node:url'
import { builtinModules } from 'module';
import { defineConfig } from 'rollup';

import swc from '@rollup/plugin-swc';
import commonJs from '@rollup/plugin-commonjs';
import nodeExternals from 'rollup-plugin-node-externals'
import alias from '@rollup/plugin-alias';
import replace from '@rollup/plugin-replace';
import terser from '@rollup/plugin-terser';

import pkg from '../package.json' assert { type: 'json' };


export default defineConfig({
input: 'src/core/contentstack.js',
output: {
dir: './dist/react-native',
format: 'commonjs'
},
plugins: [
nodeExternals(),
commonJs(),
swc({
exclude: 'node_modules/**',
swc: {
jsc: {
target: 'es2015'
}
}
}),
replace({
values: {
'PLATFORM': 'react-native',
'VERSION': pkg.version
},
delimiters: ['{{', '}}'],
preventAssignment: true
}),
alias({
entries: [
{
find: 'runtime',
replacement: fileURLToPath(new URL('../src/runtime/react-native', import.meta.url))
}
]
}),
terser({
output: {
ascii_only: true
}
})
],
external: [
...builtinModules,
...Object.keys(pkg.devDependencies)
]
});
55 changes: 55 additions & 0 deletions rollup/web.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { fileURLToPath } from 'node:url'
import { builtinModules } from 'module';
import { defineConfig } from 'rollup';

import swc from '@rollup/plugin-swc';
import commonJs from '@rollup/plugin-commonjs';
import nodeExternals from 'rollup-plugin-node-externals'
import alias from '@rollup/plugin-alias';
import replace from '@rollup/plugin-replace';
import terser from '@rollup/plugin-terser';

import pkg from '../package.json' assert { type: 'json' };


export default defineConfig({
input: 'src/core/contentstack.js',
output: {
dir: './dist/web',
format: 'umd'
},
plugins: [
nodeExternals(),
commonJs(),
swc({
exclude: 'node_modules/**',
swc: {
jsc: {
target: 'es2015'
}
}
}),
replace({
values: {
'PLATFORM': 'web',
'VERSION': pkg.version
},
delimiters: ['{{', '}}'],
preventAssignment: true
}),
alias({
entries: [
{
find: 'runtime',
replacement: fileURLToPath(new URL('../src/runtime/web', import.meta.url))
}
]
}),
terser()
],
context: 'window',
external: [
...builtinModules,
...Object.keys(pkg.devDependencies)
]
});
5 changes: 2 additions & 3 deletions src/core/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ export function _type(val) {

// merge two objects
export function mergeDeep(destination, sourceVar) {
let self = this;
let _merge_recursive = function(target, source) {
for (let key in source) {
if (self._type(source[key]) == 'object' && self._type(target[key]) == self._type(source[key])) {
if (_type(source[key]) == 'object' && _type(target[key]) == _type(source[key])) {
_merge_recursive(target[key], source[key])
} else if (self._type(source[key]) == 'array' && self._type(target[key]) == self._type(source[key])) {
} else if (_type(source[key]) == 'array' && _type(target[key]) == _type(source[key])) {
target[key] = target[key].concat(source[key]);
} else {
target[key] = source[key];
Expand Down
2 changes: 1 addition & 1 deletion src/core/modules/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ class Result {
}
}

module.exports = function(object) {
export default function(object) {
return new Result(object);
};
22 changes: 13 additions & 9 deletions test/config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
'use strict';
require('dotenv').config()
"use strict";
require("dotenv").config();

module.exports = {
stack: { 'api_key': process.env.API_KEY, 'delivery_token': process.env.DELIVERY_TOKEN, 'environment': process.env.ENVIRONMENT, },
host: process.env.HOST,
contentTypes: {
source: "author",
numbers_content_type: "blog_post"
},
}
stack: {
api_key: process.env.API_KEY,
delivery_token: process.env.DELIVERY_TOKEN,
environment: process.env.ENVIRONMENT,
},
host: process.env.HOST,
contentTypes: {
source: "author",
numbers_content_type: "blog_post",
},
};
47 changes: 0 additions & 47 deletions webpack/webpack.common.js

This file was deleted.

Loading
Loading