@nebula.js/cli-build 4.0.0-alpha.9 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/build.js +15 -298
- package/lib/config.js +179 -0
- package/lib/init-config.js +5 -0
- package/lib/systemjs.js +12 -0
- package/lib/watch.js +114 -0
- package/package.json +14 -14
package/lib/build.js
CHANGED
|
@@ -1,189 +1,12 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
|
-
const chalk = require('chalk');
|
|
3
|
-
const readline = require('readline');
|
|
4
|
-
|
|
5
|
-
const fs = require('fs');
|
|
6
2
|
const extend = require('extend');
|
|
7
3
|
const yargs = require('yargs');
|
|
8
4
|
const rollup = require('rollup');
|
|
9
|
-
const babel = require('@rollup/plugin-babel');
|
|
10
|
-
const postcss = require('rollup-plugin-postcss');
|
|
11
|
-
const replace = require('@rollup/plugin-replace');
|
|
12
|
-
const sourcemaps = require('rollup-plugin-sourcemaps');
|
|
13
|
-
const jsxPlugin = require('@babel/plugin-transform-react-jsx');
|
|
14
|
-
const json = require('@rollup/plugin-json');
|
|
15
|
-
const { nodeResolve } = require('@rollup/plugin-node-resolve');
|
|
16
|
-
const commonjs = require('@rollup/plugin-commonjs');
|
|
17
|
-
|
|
18
|
-
const babelPreset = require('@babel/preset-env');
|
|
19
|
-
|
|
20
|
-
const terser = require('@rollup/plugin-terser');
|
|
21
|
-
const resolveNative = require('./resolveNative');
|
|
22
5
|
|
|
23
6
|
const initConfig = require('./init-config');
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
throw new Error('replacementStrings should be an object with key value pairs of strings!');
|
|
28
|
-
}
|
|
29
|
-
return replacementStrings;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const setupReactNative = (argv) => {
|
|
33
|
-
const { reactNative } = argv;
|
|
34
|
-
let reactNativePath;
|
|
35
|
-
if (reactNative) {
|
|
36
|
-
reactNativePath = argv.reactNativePath || './react-native';
|
|
37
|
-
if (!fs.existsSync(`${reactNativePath}/package.json`)) {
|
|
38
|
-
// eslint-disable-next-line no-console
|
|
39
|
-
console.warn(
|
|
40
|
-
`WARNING: No ${reactNativePath}/package.json was found. If you really intended to build a react-native version of this package, please provide one.\nOther wise, to suppress this warning, omit the --reactNative flag.`
|
|
41
|
-
);
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return { reactNative, reactNativePath };
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const getBanner = ({ pkg }) => {
|
|
49
|
-
const { name, author, version, license } = pkg;
|
|
50
|
-
const auth = typeof author === 'object' ? `${author.name} <${author.email}>` : author || '';
|
|
51
|
-
|
|
52
|
-
return `/*
|
|
53
|
-
* ${name} v${version}
|
|
54
|
-
* Copyright (c) ${new Date().getFullYear()} ${auth}
|
|
55
|
-
* Released under the ${license} license.
|
|
56
|
-
*/
|
|
57
|
-
`;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const getExternalDefault = ({ pkg }) => {
|
|
61
|
-
const peers = pkg.peerDependencies || {};
|
|
62
|
-
return Object.keys(peers);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const getOutputFileDefault = ({ pkg }) => pkg.main;
|
|
66
|
-
|
|
67
|
-
const getOutputNameDefault = ({ pkg }) => pkg.name.split('/').reverse()[0];
|
|
68
|
-
|
|
69
|
-
const config = ({
|
|
70
|
-
mode = 'production',
|
|
71
|
-
format = 'umd',
|
|
72
|
-
cwd = process.cwd(),
|
|
73
|
-
argv = { sourcemap: true },
|
|
74
|
-
core,
|
|
75
|
-
behaviours: {
|
|
76
|
-
getExternal = getExternalDefault,
|
|
77
|
-
getOutputFile = getOutputFileDefault,
|
|
78
|
-
getOutputName = getOutputNameDefault,
|
|
79
|
-
// Return false if no build should be done, otherwise true
|
|
80
|
-
enabled = () => true,
|
|
81
|
-
} = {},
|
|
82
|
-
} = {}) => {
|
|
83
|
-
const CWD = argv.cwd || cwd;
|
|
84
|
-
const { reactNative, reactNativePath } = setupReactNative(argv);
|
|
85
|
-
let dir = CWD;
|
|
86
|
-
let pkg = require(path.resolve(CWD, 'package.json')); // eslint-disable-line
|
|
87
|
-
const corePkg = core ? require(path.resolve(core, 'package.json')) : null; // eslint-disable-line
|
|
88
|
-
pkg = reactNative ? require(path.resolve(reactNativePath, 'package.json')) : pkg; // eslint-disable-line
|
|
89
|
-
const { sourcemap, replacementStrings = {}, typescript } = argv;
|
|
90
|
-
const banner = getBanner({ pkg });
|
|
91
|
-
const outputName = getOutputName({ pkg, config: argv });
|
|
92
|
-
|
|
93
|
-
if (reactNative) {
|
|
94
|
-
dir = `${dir}/${reactNativePath}`;
|
|
95
|
-
} else if (corePkg) {
|
|
96
|
-
pkg = corePkg;
|
|
97
|
-
dir = core;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (!enabled({ pkg })) {
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
const outputFile = getOutputFile({ pkg, config: argv });
|
|
104
|
-
|
|
105
|
-
const extensions = ['.mjs', '.js', '.jsx', '.json', '.node'];
|
|
106
|
-
|
|
107
|
-
let typescriptPlugin;
|
|
108
|
-
if (typescript) {
|
|
109
|
-
extensions.push('.tsx', '.ts');
|
|
110
|
-
try {
|
|
111
|
-
typescriptPlugin = require('@rollup/plugin-typescript'); // eslint-disable-line
|
|
112
|
-
} catch (e) {
|
|
113
|
-
throw new Error(`${e}\n '@rollup/plugin-typescript' is required to build using typescript.`);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const external = getExternal({ pkg, config: argv });
|
|
118
|
-
// stardust should always be external
|
|
119
|
-
if (external.indexOf('@nebula.js/stardust') === -1) {
|
|
120
|
-
// eslint-disable-next-line no-console
|
|
121
|
-
console.warn('@nebula.js/stardust should be specified as a peer dependency');
|
|
122
|
-
external.push('@nebula.js/stardust');
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return {
|
|
126
|
-
input: {
|
|
127
|
-
input: path.resolve(CWD, 'src/index'),
|
|
128
|
-
external,
|
|
129
|
-
plugins: [
|
|
130
|
-
resolveNative({ reactNative }),
|
|
131
|
-
replace({
|
|
132
|
-
'process.env.NODE_ENV': JSON.stringify(mode === 'development' ? 'development' : 'production'),
|
|
133
|
-
preventAssignment: true,
|
|
134
|
-
...resolveReplacementStrings(replacementStrings),
|
|
135
|
-
}),
|
|
136
|
-
nodeResolve({
|
|
137
|
-
extensions,
|
|
138
|
-
}),
|
|
139
|
-
commonjs({
|
|
140
|
-
ignoreTryCatch: false, // Avoids problems with require() inside try catch (https://github.com/rollup/plugins/issues/1004)
|
|
141
|
-
}),
|
|
142
|
-
json(),
|
|
143
|
-
babel({
|
|
144
|
-
babelHelpers: 'bundled',
|
|
145
|
-
babelrc: false,
|
|
146
|
-
inputSourceMap: false, // without this you get wrong source maps, but I don't know why
|
|
147
|
-
extensions,
|
|
148
|
-
presets: [
|
|
149
|
-
[
|
|
150
|
-
babelPreset,
|
|
151
|
-
{
|
|
152
|
-
modules: false,
|
|
153
|
-
targets: {
|
|
154
|
-
browsers: ['chrome 62'],
|
|
155
|
-
},
|
|
156
|
-
},
|
|
157
|
-
],
|
|
158
|
-
],
|
|
159
|
-
plugins: [[jsxPlugin]],
|
|
160
|
-
}),
|
|
161
|
-
sourcemaps(),
|
|
162
|
-
postcss({}),
|
|
163
|
-
...[typescript ? typescriptPlugin() : false],
|
|
164
|
-
...[
|
|
165
|
-
mode === 'production'
|
|
166
|
-
? terser({
|
|
167
|
-
output: {
|
|
168
|
-
preamble: banner,
|
|
169
|
-
},
|
|
170
|
-
})
|
|
171
|
-
: false,
|
|
172
|
-
],
|
|
173
|
-
].filter(Boolean),
|
|
174
|
-
},
|
|
175
|
-
output: {
|
|
176
|
-
banner,
|
|
177
|
-
format,
|
|
178
|
-
file: path.resolve(dir, outputFile),
|
|
179
|
-
name: outputName,
|
|
180
|
-
sourcemap,
|
|
181
|
-
globals: {
|
|
182
|
-
'@nebula.js/stardust': 'stardust',
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
};
|
|
186
|
-
};
|
|
7
|
+
const config = require('./config');
|
|
8
|
+
const watch = require('./watch');
|
|
9
|
+
const systemjsBehaviours = require('./systemjs');
|
|
187
10
|
|
|
188
11
|
const umd = async (argv) => {
|
|
189
12
|
const c = config({
|
|
@@ -213,17 +36,6 @@ const esm = async (argv, core) => {
|
|
|
213
36
|
return bundle.write(c.output);
|
|
214
37
|
};
|
|
215
38
|
|
|
216
|
-
const systemjsBehaviours = {
|
|
217
|
-
getExternal: ({ config: cfg }) => {
|
|
218
|
-
const defaultExternal = ['@nebula.js/stardust', 'picasso.js', 'picasso-plugin-q', 'react', 'react-dom'];
|
|
219
|
-
const { external } = cfg.systemjs || {};
|
|
220
|
-
return Array.isArray(external) ? external : defaultExternal;
|
|
221
|
-
},
|
|
222
|
-
getOutputFile: ({ pkg }) => pkg.systemjs,
|
|
223
|
-
getOutputName: () => undefined,
|
|
224
|
-
enabled: ({ pkg }) => !!pkg.systemjs,
|
|
225
|
-
};
|
|
226
|
-
|
|
227
39
|
const systemjs = async (argv) => {
|
|
228
40
|
const c = config({
|
|
229
41
|
mode: argv.mode || 'production',
|
|
@@ -238,112 +50,6 @@ const systemjs = async (argv) => {
|
|
|
238
50
|
return bundle.write(c.output);
|
|
239
51
|
};
|
|
240
52
|
|
|
241
|
-
function clearScreen(msg) {
|
|
242
|
-
// source: https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli-shared-utils/lib/logger.js
|
|
243
|
-
if (process.stdout.isTTY) {
|
|
244
|
-
const blank = '\n'.repeat(process.stdout.rows);
|
|
245
|
-
console.log(blank);
|
|
246
|
-
readline.cursorTo(process.stdout, 0, 0);
|
|
247
|
-
readline.clearScreenDown(process.stdout);
|
|
248
|
-
if (msg) {
|
|
249
|
-
console.log(msg);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
const getPackage = (argv, cwd = process.cwd()) => require(path.resolve(argv.cwd || cwd, 'package.json')); // eslint-disable-line
|
|
255
|
-
|
|
256
|
-
const validateWatchInput = (argv) => {
|
|
257
|
-
if (argv.watch === 'systemjs') {
|
|
258
|
-
const pkg = getPackage(argv);
|
|
259
|
-
if (!pkg.systemjs) {
|
|
260
|
-
console.log(
|
|
261
|
-
`${chalk.white.bgRed(' ERROR ')} ${chalk.red(
|
|
262
|
-
'No "systemjs" field specifying output file found in package.json'
|
|
263
|
-
)}`
|
|
264
|
-
);
|
|
265
|
-
return false;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
return true;
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
const getWatchConfig = (argv) => {
|
|
272
|
-
const base = {
|
|
273
|
-
mode: argv.mode || 'development',
|
|
274
|
-
argv,
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
let opts;
|
|
278
|
-
|
|
279
|
-
switch (argv.watch) {
|
|
280
|
-
case 'systemjs':
|
|
281
|
-
opts = { ...base, format: 'systemjs', behaviours: systemjsBehaviours };
|
|
282
|
-
break;
|
|
283
|
-
case 'umd':
|
|
284
|
-
default:
|
|
285
|
-
opts = { ...base, format: 'umd' };
|
|
286
|
-
break;
|
|
287
|
-
}
|
|
288
|
-
return config(opts);
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
const watch = async (argv) => {
|
|
292
|
-
if (!validateWatchInput(argv)) {
|
|
293
|
-
return undefined;
|
|
294
|
-
}
|
|
295
|
-
const c = getWatchConfig(argv);
|
|
296
|
-
|
|
297
|
-
let hasWarnings = false;
|
|
298
|
-
|
|
299
|
-
const watcher = rollup.watch({
|
|
300
|
-
...c.input,
|
|
301
|
-
onwarn({ loc, message }) {
|
|
302
|
-
if (!hasWarnings) {
|
|
303
|
-
clearScreen();
|
|
304
|
-
}
|
|
305
|
-
console.log(
|
|
306
|
-
`${chalk.black.bgYellow(' WARN ')} ${chalk.yellow(
|
|
307
|
-
loc ? `${loc.file} (${loc.line}:${loc.column}) ${message}` : message
|
|
308
|
-
)}`
|
|
309
|
-
);
|
|
310
|
-
hasWarnings = true;
|
|
311
|
-
},
|
|
312
|
-
output: c.output,
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
return new Promise((resolve, reject) => {
|
|
316
|
-
watcher.on('event', (event) => {
|
|
317
|
-
switch (event.code) {
|
|
318
|
-
case 'BUNDLE_START':
|
|
319
|
-
hasWarnings = false;
|
|
320
|
-
clearScreen();
|
|
321
|
-
console.log(`${chalk.black.bgBlue(' INFO ')} Compiling...\n`);
|
|
322
|
-
break;
|
|
323
|
-
case 'FATAL':
|
|
324
|
-
case 'ERROR':
|
|
325
|
-
clearScreen();
|
|
326
|
-
console.log(`${chalk.white.bgRed(' ERROR ')} ${chalk.red('Failed to compile\n\n')}`);
|
|
327
|
-
console.error(event.error.stack);
|
|
328
|
-
reject(watcher);
|
|
329
|
-
break;
|
|
330
|
-
case 'BUNDLE_END':
|
|
331
|
-
if (!hasWarnings) {
|
|
332
|
-
clearScreen();
|
|
333
|
-
} else {
|
|
334
|
-
console.log();
|
|
335
|
-
}
|
|
336
|
-
console.log(
|
|
337
|
-
`${chalk.black.bgGreen(' DONE ')} ${chalk.green(`Compiled successfully in ${event.duration}ms\n`)}`
|
|
338
|
-
);
|
|
339
|
-
resolve(watcher);
|
|
340
|
-
break;
|
|
341
|
-
default:
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
});
|
|
345
|
-
};
|
|
346
|
-
|
|
347
53
|
async function build(argv = {}) {
|
|
348
54
|
let defaultBuildConfig = {};
|
|
349
55
|
|
|
@@ -358,13 +64,24 @@ async function build(argv = {}) {
|
|
|
358
64
|
return watch(buildConfig);
|
|
359
65
|
}
|
|
360
66
|
|
|
67
|
+
console.time('Generate UMD bundle');
|
|
361
68
|
await umd(buildConfig);
|
|
69
|
+
console.timeEnd('Generate UMD bundle');
|
|
70
|
+
console.time('Create ESM bundle');
|
|
362
71
|
await esm(buildConfig);
|
|
363
|
-
|
|
72
|
+
console.timeEnd('Create ESM bundle');
|
|
73
|
+
|
|
74
|
+
if (argv.systemjs) {
|
|
75
|
+
console.time('Support native format of the SystemJS loader');
|
|
76
|
+
await systemjs(buildConfig);
|
|
77
|
+
console.timeEnd('Support native format of the SystemJS loader');
|
|
78
|
+
}
|
|
364
79
|
|
|
365
80
|
if (argv.core) {
|
|
81
|
+
console.time('Create ESM bundle into core');
|
|
366
82
|
const core = path.resolve(process.cwd(), argv.core);
|
|
367
83
|
await esm(buildConfig, core);
|
|
84
|
+
console.timeEnd('Create ESM bundle into core');
|
|
368
85
|
}
|
|
369
86
|
|
|
370
87
|
return undefined;
|
package/lib/config.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const babel = require('@rollup/plugin-babel');
|
|
4
|
+
const postcss = require('rollup-plugin-postcss');
|
|
5
|
+
const replace = require('@rollup/plugin-replace');
|
|
6
|
+
const sourcemaps = require('rollup-plugin-sourcemaps');
|
|
7
|
+
const json = require('@rollup/plugin-json');
|
|
8
|
+
const { nodeResolve } = require('@rollup/plugin-node-resolve');
|
|
9
|
+
const commonjs = require('@rollup/plugin-commonjs');
|
|
10
|
+
const terser = require('@rollup/plugin-terser');
|
|
11
|
+
const jsxPlugin = require('@babel/plugin-transform-react-jsx');
|
|
12
|
+
const babelPreset = require('@babel/preset-env');
|
|
13
|
+
|
|
14
|
+
const resolveNative = require('./resolveNative');
|
|
15
|
+
|
|
16
|
+
const resolveReplacementStrings = (replacementStrings) => {
|
|
17
|
+
if (typeof replacementStrings !== 'object') {
|
|
18
|
+
throw new Error('replacementStrings should be an object with key value pairs of strings!');
|
|
19
|
+
}
|
|
20
|
+
return replacementStrings;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const setupReactNative = (argv) => {
|
|
24
|
+
const { reactNative } = argv;
|
|
25
|
+
let reactNativePath;
|
|
26
|
+
if (reactNative) {
|
|
27
|
+
reactNativePath = argv.reactNativePath || './react-native';
|
|
28
|
+
if (!fs.existsSync(`${reactNativePath}/package.json`)) {
|
|
29
|
+
// eslint-disable-next-line no-console
|
|
30
|
+
console.warn(
|
|
31
|
+
`WARNING: No ${reactNativePath}/package.json was found. If you really intended to build a react-native version of this package, please provide one.\nOther wise, to suppress this warning, omit the --reactNative flag.`
|
|
32
|
+
);
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return { reactNative, reactNativePath };
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const getBanner = ({ pkg }) => {
|
|
40
|
+
const { name, author, version, license } = pkg;
|
|
41
|
+
const auth = typeof author === 'object' ? `${author.name} <${author.email}>` : author || '';
|
|
42
|
+
|
|
43
|
+
return `/*
|
|
44
|
+
* ${name} v${version}
|
|
45
|
+
* Copyright (c) ${new Date().getFullYear()} ${auth}
|
|
46
|
+
* Released under the ${license} license.
|
|
47
|
+
*/
|
|
48
|
+
`;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const getExternalDefault = ({ pkg }) => {
|
|
52
|
+
const peers = pkg.peerDependencies || {};
|
|
53
|
+
return Object.keys(peers);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const getOutputFileDefault = ({ pkg }) => pkg.main;
|
|
57
|
+
|
|
58
|
+
const getOutputNameDefault = ({ pkg }) => pkg.name.split('/').reverse()[0];
|
|
59
|
+
|
|
60
|
+
const config = ({
|
|
61
|
+
mode = 'production',
|
|
62
|
+
format = 'umd',
|
|
63
|
+
cwd = process.cwd(),
|
|
64
|
+
argv = { sourcemap: true },
|
|
65
|
+
core,
|
|
66
|
+
behaviours: {
|
|
67
|
+
getExternal = getExternalDefault,
|
|
68
|
+
getOutputFile = getOutputFileDefault,
|
|
69
|
+
getOutputName = getOutputNameDefault,
|
|
70
|
+
// Return false if no build should be done, otherwise true
|
|
71
|
+
enabled = () => true,
|
|
72
|
+
} = {},
|
|
73
|
+
} = {}) => {
|
|
74
|
+
const CWD = argv.cwd || cwd;
|
|
75
|
+
const { reactNative, reactNativePath } = setupReactNative(argv);
|
|
76
|
+
let dir = CWD;
|
|
77
|
+
let pkg = require(path.resolve(CWD, 'package.json')); // eslint-disable-line
|
|
78
|
+
const corePkg = core ? require(path.resolve(core, 'package.json')) : null; // eslint-disable-line
|
|
79
|
+
pkg = reactNative ? require(path.resolve(reactNativePath, 'package.json')) : pkg; // eslint-disable-line
|
|
80
|
+
const { sourcemap, replacementStrings = {}, typescript } = argv;
|
|
81
|
+
const banner = getBanner({ pkg });
|
|
82
|
+
const outputName = getOutputName({ pkg, config: argv });
|
|
83
|
+
|
|
84
|
+
if (reactNative) {
|
|
85
|
+
dir = `${dir}/${reactNativePath}`;
|
|
86
|
+
} else if (corePkg) {
|
|
87
|
+
pkg = corePkg;
|
|
88
|
+
dir = core;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (!enabled({ pkg })) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
const outputFile = getOutputFile({ pkg, config: argv });
|
|
95
|
+
|
|
96
|
+
const extensions = ['.mjs', '.js', '.jsx', '.json', '.node'];
|
|
97
|
+
|
|
98
|
+
let typescriptPlugin;
|
|
99
|
+
if (typescript) {
|
|
100
|
+
extensions.push('.tsx', '.ts');
|
|
101
|
+
try {
|
|
102
|
+
typescriptPlugin = require('@rollup/plugin-typescript'); // eslint-disable-line
|
|
103
|
+
} catch (e) {
|
|
104
|
+
throw new Error(`${e}\n '@rollup/plugin-typescript' is required to build using typescript.`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const external = getExternal({ pkg, config: argv });
|
|
109
|
+
// stardust should always be external
|
|
110
|
+
if (external.indexOf('@nebula.js/stardust') === -1) {
|
|
111
|
+
// eslint-disable-next-line no-console
|
|
112
|
+
console.warn('@nebula.js/stardust should be specified as a peer dependency');
|
|
113
|
+
external.push('@nebula.js/stardust');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
input: {
|
|
118
|
+
input: path.resolve(CWD, 'src/index'),
|
|
119
|
+
external,
|
|
120
|
+
plugins: [
|
|
121
|
+
resolveNative({ reactNative }),
|
|
122
|
+
replace({
|
|
123
|
+
'process.env.NODE_ENV': JSON.stringify(mode === 'development' ? 'development' : 'production'),
|
|
124
|
+
preventAssignment: true,
|
|
125
|
+
...resolveReplacementStrings(replacementStrings),
|
|
126
|
+
}),
|
|
127
|
+
nodeResolve({
|
|
128
|
+
extensions,
|
|
129
|
+
}),
|
|
130
|
+
commonjs({
|
|
131
|
+
ignoreTryCatch: false, // Avoids problems with require() inside try catch (https://github.com/rollup/plugins/issues/1004)
|
|
132
|
+
}),
|
|
133
|
+
json(),
|
|
134
|
+
babel({
|
|
135
|
+
babelHelpers: 'bundled',
|
|
136
|
+
babelrc: false,
|
|
137
|
+
inputSourceMap: false, // without this you get wrong source maps, but I don't know why
|
|
138
|
+
extensions,
|
|
139
|
+
presets: [
|
|
140
|
+
[
|
|
141
|
+
babelPreset,
|
|
142
|
+
{
|
|
143
|
+
modules: false,
|
|
144
|
+
targets: {
|
|
145
|
+
browsers: ['chrome 62'],
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
],
|
|
150
|
+
plugins: [[jsxPlugin]],
|
|
151
|
+
}),
|
|
152
|
+
sourcemaps(),
|
|
153
|
+
postcss({}),
|
|
154
|
+
...[typescript ? typescriptPlugin() : false],
|
|
155
|
+
...[
|
|
156
|
+
mode === 'production'
|
|
157
|
+
? terser({
|
|
158
|
+
output: {
|
|
159
|
+
preamble: banner,
|
|
160
|
+
},
|
|
161
|
+
})
|
|
162
|
+
: false,
|
|
163
|
+
],
|
|
164
|
+
].filter(Boolean),
|
|
165
|
+
},
|
|
166
|
+
output: {
|
|
167
|
+
banner,
|
|
168
|
+
format,
|
|
169
|
+
file: path.resolve(dir, outputFile),
|
|
170
|
+
name: outputName,
|
|
171
|
+
sourcemap,
|
|
172
|
+
globals: {
|
|
173
|
+
'@nebula.js/stardust': 'stardust',
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
module.exports = config;
|
package/lib/init-config.js
CHANGED
|
@@ -27,6 +27,11 @@ const options = {
|
|
|
27
27
|
type: 'string',
|
|
28
28
|
default: undefined,
|
|
29
29
|
},
|
|
30
|
+
systemjs: {
|
|
31
|
+
description: 'Enable to transpile a systemjs format for release',
|
|
32
|
+
type: 'boolean',
|
|
33
|
+
default: true,
|
|
34
|
+
},
|
|
30
35
|
core: {
|
|
31
36
|
description: 'Set a core build target to compile an ES Module for release',
|
|
32
37
|
type: 'string',
|
package/lib/systemjs.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const systemjsBehaviours = {
|
|
2
|
+
getExternal: ({ config: cfg }) => {
|
|
3
|
+
const defaultExternal = ['@nebula.js/stardust', 'picasso.js', 'picasso-plugin-q', 'react', 'react-dom'];
|
|
4
|
+
const { external } = cfg.systemjs || {};
|
|
5
|
+
return Array.isArray(external) ? external : defaultExternal;
|
|
6
|
+
},
|
|
7
|
+
getOutputFile: ({ pkg }) => pkg.systemjs,
|
|
8
|
+
getOutputName: () => undefined,
|
|
9
|
+
enabled: ({ pkg }) => !!pkg.systemjs,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
module.exports = systemjsBehaviours;
|
package/lib/watch.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
const chalk = require('chalk');
|
|
2
|
+
const rollup = require('rollup');
|
|
3
|
+
const readline = require('readline');
|
|
4
|
+
|
|
5
|
+
const config = require('./config');
|
|
6
|
+
const systemjsBehaviours = require('./systemjs');
|
|
7
|
+
|
|
8
|
+
const getPackage = (argv, cwd = process.cwd()) => require(path.resolve(argv.cwd || cwd, 'package.json')); // eslint-disable-line
|
|
9
|
+
|
|
10
|
+
const validateWatchInput = (argv) => {
|
|
11
|
+
if (argv.watch === 'systemjs') {
|
|
12
|
+
const pkg = getPackage(argv);
|
|
13
|
+
if (!pkg.systemjs) {
|
|
14
|
+
console.log(
|
|
15
|
+
`${chalk.white.bgRed(' ERROR ')} ${chalk.red(
|
|
16
|
+
'No "systemjs" field specifying output file found in package.json'
|
|
17
|
+
)}`
|
|
18
|
+
);
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const getWatchConfig = (argv) => {
|
|
26
|
+
const base = {
|
|
27
|
+
mode: argv.mode || 'development',
|
|
28
|
+
argv,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
let opts;
|
|
32
|
+
|
|
33
|
+
switch (argv.watch) {
|
|
34
|
+
case 'systemjs':
|
|
35
|
+
opts = { ...base, format: 'systemjs', behaviours: systemjsBehaviours };
|
|
36
|
+
break;
|
|
37
|
+
case 'umd':
|
|
38
|
+
default:
|
|
39
|
+
opts = { ...base, format: 'umd' };
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
return config(opts);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
function clearScreen(msg) {
|
|
46
|
+
// source: https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli-shared-utils/lib/logger.js
|
|
47
|
+
if (process.stdout.isTTY) {
|
|
48
|
+
const blank = '\n'.repeat(process.stdout.rows);
|
|
49
|
+
console.log(blank);
|
|
50
|
+
readline.cursorTo(process.stdout, 0, 0);
|
|
51
|
+
readline.clearScreenDown(process.stdout);
|
|
52
|
+
if (msg) {
|
|
53
|
+
console.log(msg);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const watch = async (argv) => {
|
|
59
|
+
if (!validateWatchInput(argv)) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
const c = getWatchConfig(argv);
|
|
63
|
+
|
|
64
|
+
let hasWarnings = false;
|
|
65
|
+
|
|
66
|
+
const watcher = rollup.watch({
|
|
67
|
+
...c.input,
|
|
68
|
+
onwarn({ loc, message }) {
|
|
69
|
+
if (!hasWarnings) {
|
|
70
|
+
clearScreen();
|
|
71
|
+
}
|
|
72
|
+
console.log(
|
|
73
|
+
`${chalk.black.bgYellow(' WARN ')} ${chalk.yellow(
|
|
74
|
+
loc ? `${loc.file} (${loc.line}:${loc.column}) ${message}` : message
|
|
75
|
+
)}`
|
|
76
|
+
);
|
|
77
|
+
hasWarnings = true;
|
|
78
|
+
},
|
|
79
|
+
output: c.output,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return new Promise((resolve, reject) => {
|
|
83
|
+
watcher.on('event', (event) => {
|
|
84
|
+
switch (event.code) {
|
|
85
|
+
case 'BUNDLE_START':
|
|
86
|
+
hasWarnings = false;
|
|
87
|
+
clearScreen();
|
|
88
|
+
console.log(`${chalk.black.bgBlue(' INFO ')} Compiling...\n`);
|
|
89
|
+
break;
|
|
90
|
+
case 'FATAL':
|
|
91
|
+
case 'ERROR':
|
|
92
|
+
clearScreen();
|
|
93
|
+
console.log(`${chalk.white.bgRed(' ERROR ')} ${chalk.red('Failed to compile\n\n')}`);
|
|
94
|
+
console.error(event.error.stack);
|
|
95
|
+
reject(watcher);
|
|
96
|
+
break;
|
|
97
|
+
case 'BUNDLE_END':
|
|
98
|
+
if (!hasWarnings) {
|
|
99
|
+
clearScreen();
|
|
100
|
+
} else {
|
|
101
|
+
console.log();
|
|
102
|
+
}
|
|
103
|
+
console.log(
|
|
104
|
+
`${chalk.black.bgGreen(' DONE ')} ${chalk.green(`Compiled successfully in ${event.duration}ms\n`)}`
|
|
105
|
+
);
|
|
106
|
+
resolve(watcher);
|
|
107
|
+
break;
|
|
108
|
+
default:
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
module.exports = watch;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nebula.js/cli-build",
|
|
3
|
-
"version": "4.0.0
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "QlikTech International AB",
|
|
@@ -21,28 +21,28 @@
|
|
|
21
21
|
"lint": "eslint src"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@babel/cli": "7.21.
|
|
25
|
-
"@babel/core": "7.21.
|
|
26
|
-
"@babel/plugin-transform-react-jsx": "7.21.
|
|
27
|
-
"@babel/preset-env": "7.21.
|
|
24
|
+
"@babel/cli": "7.21.5",
|
|
25
|
+
"@babel/core": "7.21.8",
|
|
26
|
+
"@babel/plugin-transform-react-jsx": "7.21.5",
|
|
27
|
+
"@babel/preset-env": "7.21.5",
|
|
28
28
|
"@rollup/plugin-babel": "6.0.3",
|
|
29
|
-
"@rollup/plugin-commonjs": "24.0
|
|
29
|
+
"@rollup/plugin-commonjs": "24.1.0",
|
|
30
30
|
"@rollup/plugin-json": "6.0.0",
|
|
31
|
-
"@rollup/plugin-node-resolve": "15.0.
|
|
31
|
+
"@rollup/plugin-node-resolve": "15.0.2",
|
|
32
32
|
"@rollup/plugin-replace": "5.0.2",
|
|
33
|
-
"@rollup/plugin-terser": "0.4.
|
|
33
|
+
"@rollup/plugin-terser": "0.4.1",
|
|
34
34
|
"chalk": "4.1.2",
|
|
35
35
|
"extend": "3.0.2",
|
|
36
|
-
"postcss": "^8.4.
|
|
37
|
-
"rollup": "3.
|
|
36
|
+
"postcss": "^8.4.23",
|
|
37
|
+
"rollup": "3.21.5",
|
|
38
38
|
"rollup-plugin-postcss": "4.0.2",
|
|
39
39
|
"rollup-plugin-sourcemaps": "0.6.3",
|
|
40
|
-
"yargs": "17.7.
|
|
40
|
+
"yargs": "17.7.2"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@rollup/plugin-typescript": "11.
|
|
43
|
+
"@rollup/plugin-typescript": "11.1.0",
|
|
44
44
|
"tslib": "*",
|
|
45
|
-
"typescript": ">=
|
|
45
|
+
"typescript": ">=5.0.4"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "25856057bb28d545839e8118b0fd96db1af6f4aa"
|
|
48
48
|
}
|