create-pkgbld 1.6.0 → 1.7.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/dist/index.cjs +83 -50
- package/dist/index.mjs +83 -50
- package/dist/types.d.ts +2 -19
- package/package.json +9 -7
package/dist/index.cjs
CHANGED
|
@@ -11,6 +11,7 @@ var kleur = require('kleur');
|
|
|
11
11
|
var stringArgv = require('string-argv');
|
|
12
12
|
var childProcess = require('node:child_process');
|
|
13
13
|
var util = require('node:util');
|
|
14
|
+
var lodash = require('lodash');
|
|
14
15
|
|
|
15
16
|
async function getGitRoot() {
|
|
16
17
|
const exec = util.promisify(childProcess.exec);
|
|
@@ -20,7 +21,7 @@ async function getGitRoot() {
|
|
|
20
21
|
|
|
21
22
|
function isPackageJson(value) {
|
|
22
23
|
return (input => {
|
|
23
|
-
const $io0 = input => (undefined === input.private || "boolean" === typeof input.private) && (undefined === input.version || "string" === typeof input.version) && (undefined === input.name || "string" === typeof input.name) && (undefined === input.license || "string" === typeof input.license) && (undefined === input.readme || "string" === typeof input.readme) && (null !== input.author && (undefined === input.author || "string" === typeof input.author || "object" === typeof input.author && null !== input.author && false === Array.isArray(input.author) && $io1(input.author))) && (undefined === input.description || "string" === typeof input.description) && (undefined === input.scripts || "object" === typeof input.scripts && null !== input.scripts && false === Array.isArray(input.scripts) && $io2(input.scripts)) && (undefined === input.dependencies || "object" === typeof input.dependencies && null !== input.dependencies && false === Array.isArray(input.dependencies) && $
|
|
24
|
+
const $io0 = input => (undefined === input.private || "boolean" === typeof input.private) && (undefined === input.version || "string" === typeof input.version) && (undefined === input.name || "string" === typeof input.name) && (undefined === input.license || "string" === typeof input.license) && (undefined === input.readme || "string" === typeof input.readme) && (null !== input.author && (undefined === input.author || "string" === typeof input.author || "object" === typeof input.author && null !== input.author && false === Array.isArray(input.author) && $io1(input.author))) && (undefined === input.description || "string" === typeof input.description) && (undefined === input.scripts || "object" === typeof input.scripts && null !== input.scripts && false === Array.isArray(input.scripts) && $io2(input.scripts)) && (undefined === input.repository || "object" === typeof input.repository && null !== input.repository && false === Array.isArray(input.repository) && $io3(input.repository)) && (undefined === input.bugs || "string" === typeof input.bugs) && (undefined === input.homepage || "string" === typeof input.homepage) && (undefined === input.dependencies || "object" === typeof input.dependencies && null !== input.dependencies && false === Array.isArray(input.dependencies) && $io4(input.dependencies)) && (undefined === input.devDependencies || "object" === typeof input.devDependencies && null !== input.devDependencies && false === Array.isArray(input.devDependencies) && $io4(input.devDependencies)) && (undefined === input.peerDependencies || "object" === typeof input.peerDependencies && null !== input.peerDependencies && false === Array.isArray(input.peerDependencies) && $io4(input.peerDependencies));
|
|
24
25
|
const $io1 = input => (undefined === input.name || "string" === typeof input.name) && (undefined === input.email || "string" === typeof input.email) && (undefined === input.url || "string" === typeof input.url);
|
|
25
26
|
const $io2 = input => Object.keys(input).every(key => {
|
|
26
27
|
const value = input[key];
|
|
@@ -30,7 +31,8 @@ function isPackageJson(value) {
|
|
|
30
31
|
return "string" === typeof value;
|
|
31
32
|
return true;
|
|
32
33
|
});
|
|
33
|
-
const $io3 = input =>
|
|
34
|
+
const $io3 = input => (undefined === input.type || "string" === typeof input.type) && (undefined === input.url || "string" === typeof input.url);
|
|
35
|
+
const $io4 = input => Object.keys(input).every(key => {
|
|
34
36
|
const value = input[key];
|
|
35
37
|
if (undefined === value)
|
|
36
38
|
return true;
|
|
@@ -55,35 +57,37 @@ function CommaSeparatedStringOrBoolean(value) {
|
|
|
55
57
|
}
|
|
56
58
|
const cliFlagsDefaults = {
|
|
57
59
|
formats: ['es', 'cjs'],
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
umd: [],
|
|
61
|
+
compress: ['umd'],
|
|
62
|
+
sourcemaps: ['umd'],
|
|
61
63
|
preprocess: [],
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
dest: 'dist',
|
|
65
|
+
src: 'src',
|
|
66
|
+
bin: undefined,
|
|
64
67
|
includeExternals: false,
|
|
65
68
|
eject: false,
|
|
66
69
|
noTsConfig: false,
|
|
67
70
|
noUpdatePackageJson: false,
|
|
68
71
|
commonjsPattern: '[name].cjs',
|
|
69
|
-
|
|
70
|
-
umdPattern: '[name].umd.js'
|
|
72
|
+
esmPattern: '[name].mjs',
|
|
73
|
+
umdPattern: '[name].umd.js',
|
|
74
|
+
formatPackageJson: false
|
|
71
75
|
};
|
|
72
76
|
const cliFlags = {
|
|
73
77
|
umd: {
|
|
74
78
|
type: CommaSeparatedString,
|
|
75
79
|
description: 'Package subpath exports in UMD format',
|
|
76
|
-
default: cliFlagsDefaults.
|
|
80
|
+
default: cliFlagsDefaults.umd
|
|
77
81
|
},
|
|
78
82
|
compress: {
|
|
79
83
|
type: CommaSeparatedString,
|
|
80
84
|
description: 'Compress formats using terser',
|
|
81
|
-
default: cliFlagsDefaults.
|
|
85
|
+
default: cliFlagsDefaults.compress
|
|
82
86
|
},
|
|
83
87
|
sourcemaps: {
|
|
84
88
|
type: CommaSeparatedString,
|
|
85
89
|
description: 'Emit sourcemaps for the specified formats',
|
|
86
|
-
default: cliFlagsDefaults.
|
|
90
|
+
default: cliFlagsDefaults.sourcemaps
|
|
87
91
|
},
|
|
88
92
|
formats: {
|
|
89
93
|
type: CommaSeparatedString,
|
|
@@ -95,19 +99,20 @@ const cliFlags = {
|
|
|
95
99
|
description: 'Preprocess entry points / subpath exports',
|
|
96
100
|
default: cliFlagsDefaults.preprocess
|
|
97
101
|
},
|
|
98
|
-
|
|
102
|
+
dest: {
|
|
99
103
|
type: String,
|
|
100
104
|
description: 'Output directory',
|
|
101
|
-
default: cliFlagsDefaults.
|
|
105
|
+
default: cliFlagsDefaults.dest
|
|
102
106
|
},
|
|
103
|
-
|
|
107
|
+
src: {
|
|
104
108
|
type: String,
|
|
105
109
|
description: 'Source directory',
|
|
106
|
-
default: cliFlagsDefaults.
|
|
110
|
+
default: cliFlagsDefaults.src
|
|
107
111
|
},
|
|
108
112
|
bin: {
|
|
109
113
|
type: CommaSeparatedString,
|
|
110
|
-
description: 'Executable files'
|
|
114
|
+
description: 'Executable files',
|
|
115
|
+
default: cliFlagsDefaults.bin
|
|
111
116
|
},
|
|
112
117
|
includeExternals: {
|
|
113
118
|
type: CommaSeparatedStringOrBoolean,
|
|
@@ -137,12 +142,17 @@ const cliFlags = {
|
|
|
137
142
|
esmPattern: {
|
|
138
143
|
type: String,
|
|
139
144
|
description: 'ES output file name pattern',
|
|
140
|
-
default: cliFlagsDefaults.
|
|
145
|
+
default: cliFlagsDefaults.esmPattern
|
|
141
146
|
},
|
|
142
147
|
umdPattern: {
|
|
143
148
|
type: String,
|
|
144
149
|
description: 'UMD output file name pattern',
|
|
145
150
|
default: cliFlagsDefaults.umdPattern
|
|
151
|
+
},
|
|
152
|
+
formatPackageJson: {
|
|
153
|
+
type: Boolean,
|
|
154
|
+
description: 'Format package.json',
|
|
155
|
+
default: cliFlagsDefaults.formatPackageJson
|
|
146
156
|
}
|
|
147
157
|
};
|
|
148
158
|
const packageJsonFieldsOrder = new Set([
|
|
@@ -150,6 +160,7 @@ const packageJsonFieldsOrder = new Set([
|
|
|
150
160
|
'type',
|
|
151
161
|
'version',
|
|
152
162
|
'name',
|
|
163
|
+
'scope',
|
|
153
164
|
'description',
|
|
154
165
|
'license',
|
|
155
166
|
'author',
|
|
@@ -235,7 +246,7 @@ async function execute() {
|
|
|
235
246
|
const packageName = path.basename(targetDir);
|
|
236
247
|
let cancelled = false;
|
|
237
248
|
const options = getBasicOptions(packageName, pkg);
|
|
238
|
-
options.push(...await getGitOptions(targetDir));
|
|
249
|
+
options.push(...await getGitOptions(targetDir, pkg.pkg));
|
|
239
250
|
options.push(...getPkgbldOptions(pkg.pkg));
|
|
240
251
|
const state = getOptionsValue(options);
|
|
241
252
|
if (!args.flags.quiet) {
|
|
@@ -307,7 +318,7 @@ function getScriptValue(pkgbld) {
|
|
|
307
318
|
const pkgBldCopy = { ...pkgbld };
|
|
308
319
|
delete pkgBldCopy['pkgbldBinary'];
|
|
309
320
|
delete pkgBldCopy['extraParameters'];
|
|
310
|
-
return `${binary} ${asCommandLineArgs(pkgBldCopy)} ${extraArgs}
|
|
321
|
+
return `${binary} ${asCommandLineArgs(pkgBldCopy, cliFlagsDefaults)} ${extraArgs}`.trimEnd();
|
|
311
322
|
}
|
|
312
323
|
function getPromptOption(option, mutateObject) {
|
|
313
324
|
const value = mutateObject[option.field];
|
|
@@ -338,16 +349,19 @@ function mapOption(state) {
|
|
|
338
349
|
return (option) => {
|
|
339
350
|
const fieldValue = state[option.field];
|
|
340
351
|
return {
|
|
341
|
-
title: pad16plus(option.title) + kleur.grey('items' in option ? getPrintString(option
|
|
352
|
+
title: pad16plus(option.title) + kleur.grey('items' in option ? getPrintString(option, (option.mutateInnerObject ? fieldValue : state)) : fieldValue ?? ''),
|
|
342
353
|
value: option.field
|
|
343
354
|
};
|
|
344
355
|
};
|
|
345
356
|
}
|
|
346
|
-
function getPrintString(
|
|
347
|
-
|
|
357
|
+
function getPrintString(option, json) {
|
|
358
|
+
if (option.render) {
|
|
359
|
+
return option.render(option, json);
|
|
360
|
+
}
|
|
361
|
+
return option.items
|
|
348
362
|
.filter(item => item.field in json && json[item.field] && (Array.isArray(json[item.field]) ? json[item.field].length > 0 : true))
|
|
349
363
|
.map(item => kleur.grey(item.title) + ' ' + (kleur.white('items' in item ?
|
|
350
|
-
`[${getPrintString(item
|
|
364
|
+
`[${getPrintString(item, (item.mutateInnerObject ? json[item.field] :
|
|
351
365
|
json))}]` : json[item.field])))
|
|
352
366
|
.join(', ');
|
|
353
367
|
}
|
|
@@ -374,7 +388,7 @@ async function reportVersion() {
|
|
|
374
388
|
const version = createPkgBldPackage.pkg.version ?? '<unknown>';
|
|
375
389
|
return version;
|
|
376
390
|
}
|
|
377
|
-
async function getGitOptions(targetDir) {
|
|
391
|
+
async function getGitOptions(targetDir, packageJson) {
|
|
378
392
|
try {
|
|
379
393
|
const gitCfg = await gitConfig();
|
|
380
394
|
if (gitCfg) {
|
|
@@ -385,6 +399,15 @@ async function getGitOptions(targetDir) {
|
|
|
385
399
|
title: 'Git',
|
|
386
400
|
field: 'git',
|
|
387
401
|
mutateInnerObject: false,
|
|
402
|
+
render: (_option, value) => lodash.isEqual(removeEmpty({
|
|
403
|
+
repository: value.repository,
|
|
404
|
+
bugs: value.bugs,
|
|
405
|
+
homepage: value.homepage
|
|
406
|
+
}), removeEmpty({
|
|
407
|
+
repository: packageJson.repository,
|
|
408
|
+
bugs: packageJson.bugs,
|
|
409
|
+
homepage: packageJson.homepage
|
|
410
|
+
})) ? `[${kleur.green('Ok')}]` : `[${kleur.blue('Updated')}]`,
|
|
388
411
|
items: [{
|
|
389
412
|
title: 'Homepage',
|
|
390
413
|
field: 'homepage',
|
|
@@ -420,20 +443,7 @@ async function getGitOptions(targetDir) {
|
|
|
420
443
|
return [];
|
|
421
444
|
}
|
|
422
445
|
function getPkgbldOptions(pkg) {
|
|
423
|
-
let args =
|
|
424
|
-
formats: ['es', 'cjs'],
|
|
425
|
-
umd: [],
|
|
426
|
-
compress: ['umd'],
|
|
427
|
-
sourcemaps: ['umd'],
|
|
428
|
-
preprocess: [],
|
|
429
|
-
dir: 'dist',
|
|
430
|
-
sourceDir: 'src',
|
|
431
|
-
bin: undefined,
|
|
432
|
-
includeExternals: false,
|
|
433
|
-
eject: false,
|
|
434
|
-
noTsConfig: false,
|
|
435
|
-
noUpdatePackageJson: false
|
|
436
|
-
};
|
|
446
|
+
let args = cliFlagsDefaults;
|
|
437
447
|
const cmd = pkg.scripts?.build ?? '';
|
|
438
448
|
let binary = 'pkgbld';
|
|
439
449
|
if (cmd) {
|
|
@@ -463,14 +473,15 @@ function getPkgbldOptions(pkg) {
|
|
|
463
473
|
title: 'pkgbld',
|
|
464
474
|
field: 'pkgbld',
|
|
465
475
|
mutateInnerObject: true,
|
|
476
|
+
render: (_option, value) => cmd === getScriptValue(value) ? `[${kleur.green('Ok')}]` : `[${kleur.blue('Updated')}]`,
|
|
466
477
|
items: [{
|
|
467
478
|
title: 'Destination folder',
|
|
468
479
|
field: 'dest',
|
|
469
|
-
initialValue: args.
|
|
480
|
+
initialValue: args.dest
|
|
470
481
|
}, {
|
|
471
482
|
title: 'Source folder',
|
|
472
483
|
field: 'src',
|
|
473
|
-
initialValue: args.
|
|
484
|
+
initialValue: args.src
|
|
474
485
|
}, {
|
|
475
486
|
title: 'UMD exports',
|
|
476
487
|
field: 'umd',
|
|
@@ -516,15 +527,15 @@ function getPkgbldOptions(pkg) {
|
|
|
516
527
|
type: 'toggle',
|
|
517
528
|
initialValue: args.eject
|
|
518
529
|
}, {
|
|
519
|
-
title: '
|
|
520
|
-
field: '
|
|
530
|
+
title: 'Do not create tsconfig',
|
|
531
|
+
field: 'noTsConfig',
|
|
521
532
|
type: 'toggle',
|
|
522
|
-
initialValue:
|
|
533
|
+
initialValue: args.noTsConfig
|
|
523
534
|
}, {
|
|
524
|
-
title: '
|
|
525
|
-
field: '
|
|
535
|
+
title: 'Do not update package.json',
|
|
536
|
+
field: 'noUpdatePackageJson',
|
|
526
537
|
type: 'toggle',
|
|
527
|
-
initialValue:
|
|
538
|
+
initialValue: args.noUpdatePackageJson
|
|
528
539
|
}, {
|
|
529
540
|
title: 'Extra parameters',
|
|
530
541
|
field: 'extraParameters',
|
|
@@ -539,11 +550,12 @@ function getPkgbldOptions(pkg) {
|
|
|
539
550
|
}]
|
|
540
551
|
}];
|
|
541
552
|
}
|
|
542
|
-
function asCommandLineArgs(parsedArgs) {
|
|
553
|
+
function asCommandLineArgs(parsedArgs, defaultArgs = {}) {
|
|
543
554
|
return Object.entries(parsedArgs)
|
|
544
|
-
.
|
|
555
|
+
.filter(([key, value]) => !lodash.isEqual(value, defaultArgs[key]))
|
|
556
|
+
.map(([key, value]) => `--${kebabize(key)}${typeof value === 'string' || Array.isArray(value) ? `=${asArray(value).join(',')}` : ''}`)
|
|
545
557
|
.filter(Boolean)
|
|
546
|
-
.
|
|
558
|
+
.join(' ');
|
|
547
559
|
}
|
|
548
560
|
function asArray(value) {
|
|
549
561
|
return Array.isArray(value) ? value : [value];
|
|
@@ -552,6 +564,21 @@ function getBasicOptions(packageName, pkg) {
|
|
|
552
564
|
return [{
|
|
553
565
|
title: 'General',
|
|
554
566
|
field: 'general',
|
|
567
|
+
render: (_option, value) => lodash.isEqual(removeEmpty({
|
|
568
|
+
name: value.name,
|
|
569
|
+
version: value.version,
|
|
570
|
+
description: value.description,
|
|
571
|
+
license: value.license,
|
|
572
|
+
author: value.author,
|
|
573
|
+
readme: value.readme
|
|
574
|
+
}), removeEmpty({
|
|
575
|
+
name: pkg.pkg.name,
|
|
576
|
+
version: pkg.pkg.version,
|
|
577
|
+
description: pkg.pkg.description,
|
|
578
|
+
license: pkg.pkg.license,
|
|
579
|
+
author: pkg.pkg.author,
|
|
580
|
+
readme: pkg.pkg.readme
|
|
581
|
+
})) ? `[${kleur.green('Ok')}]` : `[${kleur.blue('Updated')}]`,
|
|
555
582
|
items: [{
|
|
556
583
|
title: 'Package Name',
|
|
557
584
|
field: 'name',
|
|
@@ -634,3 +661,9 @@ async function writePackage(dir, pkg) {
|
|
|
634
661
|
process.exit(-1);
|
|
635
662
|
}
|
|
636
663
|
}
|
|
664
|
+
function removeEmpty(data) {
|
|
665
|
+
return JSON.parse(JSON.stringify(data));
|
|
666
|
+
}
|
|
667
|
+
function kebabize(value) {
|
|
668
|
+
return value.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? '-' : '') + $.toLowerCase());
|
|
669
|
+
}
|
package/dist/index.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import kleur from 'kleur';
|
|
|
8
8
|
import { parseArgsStringToArgv } from 'string-argv';
|
|
9
9
|
import childProcess from 'node:child_process';
|
|
10
10
|
import util from 'node:util';
|
|
11
|
+
import { isEqual } from 'lodash';
|
|
11
12
|
|
|
12
13
|
async function getGitRoot() {
|
|
13
14
|
const exec = util.promisify(childProcess.exec);
|
|
@@ -17,7 +18,7 @@ async function getGitRoot() {
|
|
|
17
18
|
|
|
18
19
|
function isPackageJson(value) {
|
|
19
20
|
return (input => {
|
|
20
|
-
const $io0 = input => (undefined === input.private || "boolean" === typeof input.private) && (undefined === input.version || "string" === typeof input.version) && (undefined === input.name || "string" === typeof input.name) && (undefined === input.license || "string" === typeof input.license) && (undefined === input.readme || "string" === typeof input.readme) && (null !== input.author && (undefined === input.author || "string" === typeof input.author || "object" === typeof input.author && null !== input.author && false === Array.isArray(input.author) && $io1(input.author))) && (undefined === input.description || "string" === typeof input.description) && (undefined === input.scripts || "object" === typeof input.scripts && null !== input.scripts && false === Array.isArray(input.scripts) && $io2(input.scripts)) && (undefined === input.dependencies || "object" === typeof input.dependencies && null !== input.dependencies && false === Array.isArray(input.dependencies) && $
|
|
21
|
+
const $io0 = input => (undefined === input.private || "boolean" === typeof input.private) && (undefined === input.version || "string" === typeof input.version) && (undefined === input.name || "string" === typeof input.name) && (undefined === input.license || "string" === typeof input.license) && (undefined === input.readme || "string" === typeof input.readme) && (null !== input.author && (undefined === input.author || "string" === typeof input.author || "object" === typeof input.author && null !== input.author && false === Array.isArray(input.author) && $io1(input.author))) && (undefined === input.description || "string" === typeof input.description) && (undefined === input.scripts || "object" === typeof input.scripts && null !== input.scripts && false === Array.isArray(input.scripts) && $io2(input.scripts)) && (undefined === input.repository || "object" === typeof input.repository && null !== input.repository && false === Array.isArray(input.repository) && $io3(input.repository)) && (undefined === input.bugs || "string" === typeof input.bugs) && (undefined === input.homepage || "string" === typeof input.homepage) && (undefined === input.dependencies || "object" === typeof input.dependencies && null !== input.dependencies && false === Array.isArray(input.dependencies) && $io4(input.dependencies)) && (undefined === input.devDependencies || "object" === typeof input.devDependencies && null !== input.devDependencies && false === Array.isArray(input.devDependencies) && $io4(input.devDependencies)) && (undefined === input.peerDependencies || "object" === typeof input.peerDependencies && null !== input.peerDependencies && false === Array.isArray(input.peerDependencies) && $io4(input.peerDependencies));
|
|
21
22
|
const $io1 = input => (undefined === input.name || "string" === typeof input.name) && (undefined === input.email || "string" === typeof input.email) && (undefined === input.url || "string" === typeof input.url);
|
|
22
23
|
const $io2 = input => Object.keys(input).every(key => {
|
|
23
24
|
const value = input[key];
|
|
@@ -27,7 +28,8 @@ function isPackageJson(value) {
|
|
|
27
28
|
return "string" === typeof value;
|
|
28
29
|
return true;
|
|
29
30
|
});
|
|
30
|
-
const $io3 = input =>
|
|
31
|
+
const $io3 = input => (undefined === input.type || "string" === typeof input.type) && (undefined === input.url || "string" === typeof input.url);
|
|
32
|
+
const $io4 = input => Object.keys(input).every(key => {
|
|
31
33
|
const value = input[key];
|
|
32
34
|
if (undefined === value)
|
|
33
35
|
return true;
|
|
@@ -52,35 +54,37 @@ function CommaSeparatedStringOrBoolean(value) {
|
|
|
52
54
|
}
|
|
53
55
|
const cliFlagsDefaults = {
|
|
54
56
|
formats: ['es', 'cjs'],
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
57
|
+
umd: [],
|
|
58
|
+
compress: ['umd'],
|
|
59
|
+
sourcemaps: ['umd'],
|
|
58
60
|
preprocess: [],
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
dest: 'dist',
|
|
62
|
+
src: 'src',
|
|
63
|
+
bin: undefined,
|
|
61
64
|
includeExternals: false,
|
|
62
65
|
eject: false,
|
|
63
66
|
noTsConfig: false,
|
|
64
67
|
noUpdatePackageJson: false,
|
|
65
68
|
commonjsPattern: '[name].cjs',
|
|
66
|
-
|
|
67
|
-
umdPattern: '[name].umd.js'
|
|
69
|
+
esmPattern: '[name].mjs',
|
|
70
|
+
umdPattern: '[name].umd.js',
|
|
71
|
+
formatPackageJson: false
|
|
68
72
|
};
|
|
69
73
|
const cliFlags = {
|
|
70
74
|
umd: {
|
|
71
75
|
type: CommaSeparatedString,
|
|
72
76
|
description: 'Package subpath exports in UMD format',
|
|
73
|
-
default: cliFlagsDefaults.
|
|
77
|
+
default: cliFlagsDefaults.umd
|
|
74
78
|
},
|
|
75
79
|
compress: {
|
|
76
80
|
type: CommaSeparatedString,
|
|
77
81
|
description: 'Compress formats using terser',
|
|
78
|
-
default: cliFlagsDefaults.
|
|
82
|
+
default: cliFlagsDefaults.compress
|
|
79
83
|
},
|
|
80
84
|
sourcemaps: {
|
|
81
85
|
type: CommaSeparatedString,
|
|
82
86
|
description: 'Emit sourcemaps for the specified formats',
|
|
83
|
-
default: cliFlagsDefaults.
|
|
87
|
+
default: cliFlagsDefaults.sourcemaps
|
|
84
88
|
},
|
|
85
89
|
formats: {
|
|
86
90
|
type: CommaSeparatedString,
|
|
@@ -92,19 +96,20 @@ const cliFlags = {
|
|
|
92
96
|
description: 'Preprocess entry points / subpath exports',
|
|
93
97
|
default: cliFlagsDefaults.preprocess
|
|
94
98
|
},
|
|
95
|
-
|
|
99
|
+
dest: {
|
|
96
100
|
type: String,
|
|
97
101
|
description: 'Output directory',
|
|
98
|
-
default: cliFlagsDefaults.
|
|
102
|
+
default: cliFlagsDefaults.dest
|
|
99
103
|
},
|
|
100
|
-
|
|
104
|
+
src: {
|
|
101
105
|
type: String,
|
|
102
106
|
description: 'Source directory',
|
|
103
|
-
default: cliFlagsDefaults.
|
|
107
|
+
default: cliFlagsDefaults.src
|
|
104
108
|
},
|
|
105
109
|
bin: {
|
|
106
110
|
type: CommaSeparatedString,
|
|
107
|
-
description: 'Executable files'
|
|
111
|
+
description: 'Executable files',
|
|
112
|
+
default: cliFlagsDefaults.bin
|
|
108
113
|
},
|
|
109
114
|
includeExternals: {
|
|
110
115
|
type: CommaSeparatedStringOrBoolean,
|
|
@@ -134,12 +139,17 @@ const cliFlags = {
|
|
|
134
139
|
esmPattern: {
|
|
135
140
|
type: String,
|
|
136
141
|
description: 'ES output file name pattern',
|
|
137
|
-
default: cliFlagsDefaults.
|
|
142
|
+
default: cliFlagsDefaults.esmPattern
|
|
138
143
|
},
|
|
139
144
|
umdPattern: {
|
|
140
145
|
type: String,
|
|
141
146
|
description: 'UMD output file name pattern',
|
|
142
147
|
default: cliFlagsDefaults.umdPattern
|
|
148
|
+
},
|
|
149
|
+
formatPackageJson: {
|
|
150
|
+
type: Boolean,
|
|
151
|
+
description: 'Format package.json',
|
|
152
|
+
default: cliFlagsDefaults.formatPackageJson
|
|
143
153
|
}
|
|
144
154
|
};
|
|
145
155
|
const packageJsonFieldsOrder = new Set([
|
|
@@ -147,6 +157,7 @@ const packageJsonFieldsOrder = new Set([
|
|
|
147
157
|
'type',
|
|
148
158
|
'version',
|
|
149
159
|
'name',
|
|
160
|
+
'scope',
|
|
150
161
|
'description',
|
|
151
162
|
'license',
|
|
152
163
|
'author',
|
|
@@ -232,7 +243,7 @@ async function execute() {
|
|
|
232
243
|
const packageName = path.basename(targetDir);
|
|
233
244
|
let cancelled = false;
|
|
234
245
|
const options = getBasicOptions(packageName, pkg);
|
|
235
|
-
options.push(...await getGitOptions(targetDir));
|
|
246
|
+
options.push(...await getGitOptions(targetDir, pkg.pkg));
|
|
236
247
|
options.push(...getPkgbldOptions(pkg.pkg));
|
|
237
248
|
const state = getOptionsValue(options);
|
|
238
249
|
if (!args.flags.quiet) {
|
|
@@ -304,7 +315,7 @@ function getScriptValue(pkgbld) {
|
|
|
304
315
|
const pkgBldCopy = { ...pkgbld };
|
|
305
316
|
delete pkgBldCopy['pkgbldBinary'];
|
|
306
317
|
delete pkgBldCopy['extraParameters'];
|
|
307
|
-
return `${binary} ${asCommandLineArgs(pkgBldCopy)} ${extraArgs}
|
|
318
|
+
return `${binary} ${asCommandLineArgs(pkgBldCopy, cliFlagsDefaults)} ${extraArgs}`.trimEnd();
|
|
308
319
|
}
|
|
309
320
|
function getPromptOption(option, mutateObject) {
|
|
310
321
|
const value = mutateObject[option.field];
|
|
@@ -335,16 +346,19 @@ function mapOption(state) {
|
|
|
335
346
|
return (option) => {
|
|
336
347
|
const fieldValue = state[option.field];
|
|
337
348
|
return {
|
|
338
|
-
title: pad16plus(option.title) + kleur.grey('items' in option ? getPrintString(option
|
|
349
|
+
title: pad16plus(option.title) + kleur.grey('items' in option ? getPrintString(option, (option.mutateInnerObject ? fieldValue : state)) : fieldValue ?? ''),
|
|
339
350
|
value: option.field
|
|
340
351
|
};
|
|
341
352
|
};
|
|
342
353
|
}
|
|
343
|
-
function getPrintString(
|
|
344
|
-
|
|
354
|
+
function getPrintString(option, json) {
|
|
355
|
+
if (option.render) {
|
|
356
|
+
return option.render(option, json);
|
|
357
|
+
}
|
|
358
|
+
return option.items
|
|
345
359
|
.filter(item => item.field in json && json[item.field] && (Array.isArray(json[item.field]) ? json[item.field].length > 0 : true))
|
|
346
360
|
.map(item => kleur.grey(item.title) + ' ' + (kleur.white('items' in item ?
|
|
347
|
-
`[${getPrintString(item
|
|
361
|
+
`[${getPrintString(item, (item.mutateInnerObject ? json[item.field] :
|
|
348
362
|
json))}]` : json[item.field])))
|
|
349
363
|
.join(', ');
|
|
350
364
|
}
|
|
@@ -371,7 +385,7 @@ async function reportVersion() {
|
|
|
371
385
|
const version = createPkgBldPackage.pkg.version ?? '<unknown>';
|
|
372
386
|
return version;
|
|
373
387
|
}
|
|
374
|
-
async function getGitOptions(targetDir) {
|
|
388
|
+
async function getGitOptions(targetDir, packageJson) {
|
|
375
389
|
try {
|
|
376
390
|
const gitCfg = await gitConfig();
|
|
377
391
|
if (gitCfg) {
|
|
@@ -382,6 +396,15 @@ async function getGitOptions(targetDir) {
|
|
|
382
396
|
title: 'Git',
|
|
383
397
|
field: 'git',
|
|
384
398
|
mutateInnerObject: false,
|
|
399
|
+
render: (_option, value) => isEqual(removeEmpty({
|
|
400
|
+
repository: value.repository,
|
|
401
|
+
bugs: value.bugs,
|
|
402
|
+
homepage: value.homepage
|
|
403
|
+
}), removeEmpty({
|
|
404
|
+
repository: packageJson.repository,
|
|
405
|
+
bugs: packageJson.bugs,
|
|
406
|
+
homepage: packageJson.homepage
|
|
407
|
+
})) ? `[${kleur.green('Ok')}]` : `[${kleur.blue('Updated')}]`,
|
|
385
408
|
items: [{
|
|
386
409
|
title: 'Homepage',
|
|
387
410
|
field: 'homepage',
|
|
@@ -417,20 +440,7 @@ async function getGitOptions(targetDir) {
|
|
|
417
440
|
return [];
|
|
418
441
|
}
|
|
419
442
|
function getPkgbldOptions(pkg) {
|
|
420
|
-
let args =
|
|
421
|
-
formats: ['es', 'cjs'],
|
|
422
|
-
umd: [],
|
|
423
|
-
compress: ['umd'],
|
|
424
|
-
sourcemaps: ['umd'],
|
|
425
|
-
preprocess: [],
|
|
426
|
-
dir: 'dist',
|
|
427
|
-
sourceDir: 'src',
|
|
428
|
-
bin: undefined,
|
|
429
|
-
includeExternals: false,
|
|
430
|
-
eject: false,
|
|
431
|
-
noTsConfig: false,
|
|
432
|
-
noUpdatePackageJson: false
|
|
433
|
-
};
|
|
443
|
+
let args = cliFlagsDefaults;
|
|
434
444
|
const cmd = pkg.scripts?.build ?? '';
|
|
435
445
|
let binary = 'pkgbld';
|
|
436
446
|
if (cmd) {
|
|
@@ -460,14 +470,15 @@ function getPkgbldOptions(pkg) {
|
|
|
460
470
|
title: 'pkgbld',
|
|
461
471
|
field: 'pkgbld',
|
|
462
472
|
mutateInnerObject: true,
|
|
473
|
+
render: (_option, value) => cmd === getScriptValue(value) ? `[${kleur.green('Ok')}]` : `[${kleur.blue('Updated')}]`,
|
|
463
474
|
items: [{
|
|
464
475
|
title: 'Destination folder',
|
|
465
476
|
field: 'dest',
|
|
466
|
-
initialValue: args.
|
|
477
|
+
initialValue: args.dest
|
|
467
478
|
}, {
|
|
468
479
|
title: 'Source folder',
|
|
469
480
|
field: 'src',
|
|
470
|
-
initialValue: args.
|
|
481
|
+
initialValue: args.src
|
|
471
482
|
}, {
|
|
472
483
|
title: 'UMD exports',
|
|
473
484
|
field: 'umd',
|
|
@@ -513,15 +524,15 @@ function getPkgbldOptions(pkg) {
|
|
|
513
524
|
type: 'toggle',
|
|
514
525
|
initialValue: args.eject
|
|
515
526
|
}, {
|
|
516
|
-
title: '
|
|
517
|
-
field: '
|
|
527
|
+
title: 'Do not create tsconfig',
|
|
528
|
+
field: 'noTsConfig',
|
|
518
529
|
type: 'toggle',
|
|
519
|
-
initialValue:
|
|
530
|
+
initialValue: args.noTsConfig
|
|
520
531
|
}, {
|
|
521
|
-
title: '
|
|
522
|
-
field: '
|
|
532
|
+
title: 'Do not update package.json',
|
|
533
|
+
field: 'noUpdatePackageJson',
|
|
523
534
|
type: 'toggle',
|
|
524
|
-
initialValue:
|
|
535
|
+
initialValue: args.noUpdatePackageJson
|
|
525
536
|
}, {
|
|
526
537
|
title: 'Extra parameters',
|
|
527
538
|
field: 'extraParameters',
|
|
@@ -536,11 +547,12 @@ function getPkgbldOptions(pkg) {
|
|
|
536
547
|
}]
|
|
537
548
|
}];
|
|
538
549
|
}
|
|
539
|
-
function asCommandLineArgs(parsedArgs) {
|
|
550
|
+
function asCommandLineArgs(parsedArgs, defaultArgs = {}) {
|
|
540
551
|
return Object.entries(parsedArgs)
|
|
541
|
-
.
|
|
552
|
+
.filter(([key, value]) => !isEqual(value, defaultArgs[key]))
|
|
553
|
+
.map(([key, value]) => `--${kebabize(key)}${typeof value === 'string' || Array.isArray(value) ? `=${asArray(value).join(',')}` : ''}`)
|
|
542
554
|
.filter(Boolean)
|
|
543
|
-
.
|
|
555
|
+
.join(' ');
|
|
544
556
|
}
|
|
545
557
|
function asArray(value) {
|
|
546
558
|
return Array.isArray(value) ? value : [value];
|
|
@@ -549,6 +561,21 @@ function getBasicOptions(packageName, pkg) {
|
|
|
549
561
|
return [{
|
|
550
562
|
title: 'General',
|
|
551
563
|
field: 'general',
|
|
564
|
+
render: (_option, value) => isEqual(removeEmpty({
|
|
565
|
+
name: value.name,
|
|
566
|
+
version: value.version,
|
|
567
|
+
description: value.description,
|
|
568
|
+
license: value.license,
|
|
569
|
+
author: value.author,
|
|
570
|
+
readme: value.readme
|
|
571
|
+
}), removeEmpty({
|
|
572
|
+
name: pkg.pkg.name,
|
|
573
|
+
version: pkg.pkg.version,
|
|
574
|
+
description: pkg.pkg.description,
|
|
575
|
+
license: pkg.pkg.license,
|
|
576
|
+
author: pkg.pkg.author,
|
|
577
|
+
readme: pkg.pkg.readme
|
|
578
|
+
})) ? `[${kleur.green('Ok')}]` : `[${kleur.blue('Updated')}]`,
|
|
552
579
|
items: [{
|
|
553
580
|
title: 'Package Name',
|
|
554
581
|
field: 'name',
|
|
@@ -631,3 +658,9 @@ async function writePackage(dir, pkg) {
|
|
|
631
658
|
process.exit(-1);
|
|
632
659
|
}
|
|
633
660
|
}
|
|
661
|
+
function removeEmpty(data) {
|
|
662
|
+
return JSON.parse(JSON.stringify(data));
|
|
663
|
+
}
|
|
664
|
+
function kebabize(value) {
|
|
665
|
+
return value.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? '-' : '') + $.toLowerCase());
|
|
666
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { PackageJson } from 'options';
|
|
1
2
|
export type Option = ({
|
|
2
3
|
title: string;
|
|
3
4
|
field: string;
|
|
@@ -17,26 +18,8 @@ export type Option = ({
|
|
|
17
18
|
} | {
|
|
18
19
|
items: Option[];
|
|
19
20
|
mutateInnerObject: boolean;
|
|
21
|
+
render?: (option: Option, value: OptionsValue) => string;
|
|
20
22
|
});
|
|
21
|
-
export type PackageJson = {
|
|
22
|
-
private?: boolean;
|
|
23
|
-
version?: string;
|
|
24
|
-
name?: string;
|
|
25
|
-
license?: string;
|
|
26
|
-
readme?: string;
|
|
27
|
-
author?: string | {
|
|
28
|
-
name?: string;
|
|
29
|
-
email?: string;
|
|
30
|
-
url?: string;
|
|
31
|
-
};
|
|
32
|
-
description?: string;
|
|
33
|
-
scripts?: {
|
|
34
|
-
[key: string]: string;
|
|
35
|
-
};
|
|
36
|
-
dependencies?: Record<string, string>;
|
|
37
|
-
devDependencies?: Record<string, string>;
|
|
38
|
-
peerDependencies?: Record<string, string>;
|
|
39
|
-
};
|
|
40
23
|
export type PkgInfo = {
|
|
41
24
|
readme: string;
|
|
42
25
|
pkg: PackageJson;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.7.0",
|
|
3
3
|
"name": "create-pkgbld",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Konstantin Shutkin",
|
|
@@ -34,20 +34,22 @@
|
|
|
34
34
|
"init"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"string-argv": "
|
|
37
|
+
"string-argv": "0.3.2",
|
|
38
38
|
"git-user-name": "2.0.0",
|
|
39
|
-
"cleye": "
|
|
39
|
+
"cleye": "1.3.2",
|
|
40
40
|
"parse-git-config": "3.0.0",
|
|
41
41
|
"prompts": "2.4.2",
|
|
42
|
-
"kleur": "4.1.5"
|
|
42
|
+
"kleur": "4.1.5",
|
|
43
|
+
"lodash": "4.17.21"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
46
|
"@types/git-user-name": "2.0.1",
|
|
46
47
|
"@types/parse-git-config": "3.0.2",
|
|
47
48
|
"@types/prompts": "2.4.5",
|
|
48
|
-
"@
|
|
49
|
-
"
|
|
50
|
-
"
|
|
49
|
+
"@types/lodash": "4.14.199",
|
|
50
|
+
"@total-typescript/ts-reset": "0.5.1",
|
|
51
|
+
"pkgbld": "1.22.0",
|
|
52
|
+
"options": "0.0.1"
|
|
51
53
|
},
|
|
52
54
|
"scripts": {
|
|
53
55
|
"build": "node ../pkgbld/dist/index.js --include-externals=options",
|