piral-cli 0.15.0-alpha.4332 → 0.15.0-alpha.4396
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/cli.js +3 -2
- package/lib/cli.js.map +1 -1
- package/lib/commands.js +8 -0
- package/lib/commands.js.map +1 -1
- package/lib/common/emoji.d.ts +8 -0
- package/lib/common/emoji.js +10 -1
- package/lib/common/emoji.js.map +1 -1
- package/lib/common/npm.d.ts +1 -0
- package/lib/common/npm.js +15 -1
- package/lib/common/npm.js.map +1 -1
- package/lib/common/scaffold.js +1 -1
- package/lib/common/scaffold.js.map +1 -1
- package/lib/external/index.js +81 -49
- package/lib/questionnaire.js +7 -4
- package/lib/questionnaire.js.map +1 -1
- package/package.json +2 -2
- package/src/cli.ts +3 -2
- package/src/commands.ts +8 -0
- package/src/common/emoji.ts +9 -0
- package/src/common/npm.test.ts +14 -58
- package/src/common/npm.ts +17 -1
- package/src/common/scaffold.ts +2 -2
- package/src/questionnaire.ts +15 -3
package/src/cli.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as yargs from 'yargs';
|
|
2
2
|
import { detailed } from 'yargs-parser';
|
|
3
|
+
import { caterpillerIcon, zapIcon } from './common';
|
|
3
4
|
import { runQuestionnaireFor } from './questionnaire';
|
|
4
5
|
import { ToolCommand } from './types';
|
|
5
6
|
|
|
@@ -46,7 +47,7 @@ export function setupCli(commands: Array<ToolCommand<any>>) {
|
|
|
46
47
|
() => process.exit(0),
|
|
47
48
|
(err) => {
|
|
48
49
|
err && !err.logged && console.error(err.message);
|
|
49
|
-
console.log(
|
|
50
|
+
console.log(`${caterpillerIcon} Codes Reference: https://docs.piral.io/code/search`);
|
|
50
51
|
process.exit(1);
|
|
51
52
|
},
|
|
52
53
|
);
|
|
@@ -54,5 +55,5 @@ export function setupCli(commands: Array<ToolCommand<any>>) {
|
|
|
54
55
|
);
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
argv.epilog(
|
|
58
|
+
argv.epilog(`${zapIcon} For more information, check out the documentation at https://docs.piral.io.`).help().strict().argv;
|
|
58
59
|
}
|
package/src/commands.ts
CHANGED
|
@@ -281,9 +281,11 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
281
281
|
.boolean('install')
|
|
282
282
|
.describe('install', 'Already performs the installation of its npm dependencies.')
|
|
283
283
|
.default('install', apps.newPiralDefaults.install)
|
|
284
|
+
.alias('install', 'package-install')
|
|
284
285
|
.string('registry')
|
|
285
286
|
.describe('registry', 'Sets the package registry to use for resolving the dependencies.')
|
|
286
287
|
.default('registry', apps.newPiralDefaults.registry)
|
|
288
|
+
.alias('registry', 'package-registry')
|
|
287
289
|
.number('log-level')
|
|
288
290
|
.describe('log-level', 'Sets the log level to use (1-5).')
|
|
289
291
|
.default('log-level', apps.newPiralDefaults.logLevel)
|
|
@@ -293,6 +295,7 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
293
295
|
'Sets the tag or version of the package to install. By default, this uses the version of the CLI.',
|
|
294
296
|
)
|
|
295
297
|
.default('tag', apps.newPiralDefaults.version)
|
|
298
|
+
.alias('tag', 'piral-version')
|
|
296
299
|
.choices('force-overwrite', forceOverwriteKeys)
|
|
297
300
|
.describe('force-overwrite', 'Determines if files should be overwritten by the installation.')
|
|
298
301
|
.default('force-overwrite', keyOfForceOverwrite(apps.newPiralDefaults.forceOverwrite))
|
|
@@ -354,6 +357,7 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
354
357
|
.boolean('install')
|
|
355
358
|
.describe('install', 'Already performs the update of its npm dependencies.')
|
|
356
359
|
.default('install', apps.upgradePiralDefaults.install)
|
|
360
|
+
.alias('install', 'package-install')
|
|
357
361
|
.choices('npm-client', clientTypeKeys)
|
|
358
362
|
.describe('npm-client', 'Sets the npm client to be used when upgrading.')
|
|
359
363
|
.default('npm-client', apps.upgradePiralDefaults.npmClient)
|
|
@@ -614,6 +618,7 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
614
618
|
.choices('mode', publishModeKeys)
|
|
615
619
|
.describe('mode', 'Sets the authorization mode to use.')
|
|
616
620
|
.default('mode', apps.publishPiletDefaults.mode)
|
|
621
|
+
.alias('mode', 'auth-mode')
|
|
617
622
|
.choices('bundler', availableBundlers)
|
|
618
623
|
.describe('bundler', 'Sets the bundler to use.')
|
|
619
624
|
.default('bundler', availableBundlers[0])
|
|
@@ -672,9 +677,11 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
672
677
|
.string('registry')
|
|
673
678
|
.describe('registry', 'Sets the package registry to use for resolving the specified Piral app.')
|
|
674
679
|
.default('registry', apps.newPiletDefaults.registry)
|
|
680
|
+
.alias('registry', 'package-registry')
|
|
675
681
|
.boolean('install')
|
|
676
682
|
.describe('install', 'Already performs the installation of its npm dependencies.')
|
|
677
683
|
.default('install', apps.newPiletDefaults.install)
|
|
684
|
+
.alias('install', 'package-install')
|
|
678
685
|
.choices('force-overwrite', forceOverwriteKeys)
|
|
679
686
|
.describe('force-overwrite', 'Determines if files should be overwritten by the scaffolding.')
|
|
680
687
|
.default('force-overwrite', keyOfForceOverwrite(apps.newPiletDefaults.forceOverwrite))
|
|
@@ -737,6 +744,7 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
737
744
|
.boolean('install')
|
|
738
745
|
.describe('install', 'Already performs the update of its npm dependencies.')
|
|
739
746
|
.default('install', apps.upgradePiletDefaults.install)
|
|
747
|
+
.alias('install', 'package-install')
|
|
740
748
|
.choices('force-overwrite', forceOverwriteKeys)
|
|
741
749
|
.describe('force-overwrite', 'Determines if files should be overwritten by the upgrading process.')
|
|
742
750
|
.default('force-overwrite', keyOfForceOverwrite(apps.upgradePiletDefaults.forceOverwrite))
|
package/src/common/emoji.ts
CHANGED
|
@@ -2,5 +2,14 @@ import { isWindows } from './info';
|
|
|
2
2
|
|
|
3
3
|
const supportsEmoji = !isWindows || process.env.TERM === 'xterm-256color';
|
|
4
4
|
|
|
5
|
+
// see https://unicode.org/emoji/charts/full-emoji-list.html
|
|
5
6
|
export const liveIcon = supportsEmoji ? '🚀 ' : '>';
|
|
6
7
|
export const settingsIcon = supportsEmoji ? '🔧 ' : '>';
|
|
8
|
+
export const cactusIcon = supportsEmoji ? '👻' : '>';
|
|
9
|
+
export const clapIcon = supportsEmoji ? '👏' : '^';
|
|
10
|
+
export const sparklesIcon = supportsEmoji ? '✨' : '>';
|
|
11
|
+
export const unicornIcon = supportsEmoji ? '🦄' : '>';
|
|
12
|
+
export const caterpillerIcon = supportsEmoji ? '🐛' : '+';
|
|
13
|
+
export const butterflyIcon = supportsEmoji ? '🦋' : '+';
|
|
14
|
+
export const zapIcon = supportsEmoji ? '⚡' : '>';
|
|
15
|
+
export const rainbowIcon = supportsEmoji ? '🌈' : '~';
|
package/src/common/npm.test.ts
CHANGED
|
@@ -66,7 +66,7 @@ jest.mock('fs', () => ({
|
|
|
66
66
|
existsSync: (file: string) => {
|
|
67
67
|
return true;
|
|
68
68
|
},
|
|
69
|
-
readFile: (file: string, type: string, callback: (err: NodeJS.ErrnoException, data: string) => void) => {
|
|
69
|
+
readFile: (file: string, type: string, callback: (err: NodeJS.ErrnoException | undefined, data: string) => void) => {
|
|
70
70
|
return callback(undefined, '');
|
|
71
71
|
},
|
|
72
72
|
realpathSync: () => ({}),
|
|
@@ -320,7 +320,7 @@ describe('npm Module', () => {
|
|
|
320
320
|
});
|
|
321
321
|
|
|
322
322
|
it('check if package from nothing is not local', () => {
|
|
323
|
-
const result = isLocalPackage('./',
|
|
323
|
+
const result = isLocalPackage('./', '');
|
|
324
324
|
expect(result).toBeFalsy();
|
|
325
325
|
});
|
|
326
326
|
|
|
@@ -364,7 +364,7 @@ describe('npm Module', () => {
|
|
|
364
364
|
expect(result).toBeTruthy();
|
|
365
365
|
result = isGitPackage('git+');
|
|
366
366
|
expect(result).toBeTruthy();
|
|
367
|
-
result = isGitPackage(
|
|
367
|
+
result = isGitPackage('');
|
|
368
368
|
expect(result).toBeFalsy();
|
|
369
369
|
});
|
|
370
370
|
|
|
@@ -395,11 +395,11 @@ describe('npm Module', () => {
|
|
|
395
395
|
it('combine package refernce', () => {
|
|
396
396
|
let result = combinePackageRef('foo', '1.0.0', 'registry');
|
|
397
397
|
expect(result).toBe('foo@1.0.0');
|
|
398
|
-
result = combinePackageRef('foo',
|
|
398
|
+
result = combinePackageRef('foo', '', 'registry');
|
|
399
399
|
expect(result).toBe('foo@latest');
|
|
400
|
-
result = combinePackageRef('foo',
|
|
400
|
+
result = combinePackageRef('foo', '', 'file');
|
|
401
401
|
expect(result).toBe('foo');
|
|
402
|
-
result = combinePackageRef('foo',
|
|
402
|
+
result = combinePackageRef('foo', '', 'git');
|
|
403
403
|
expect(result).toBe('foo');
|
|
404
404
|
});
|
|
405
405
|
|
|
@@ -430,18 +430,18 @@ describe('npm Module', () => {
|
|
|
430
430
|
expect(result).toEqual('1.0.0');
|
|
431
431
|
result = getPackageVersion(false, 'foo', '1.0.0', 'registry', './');
|
|
432
432
|
expect(result).toBeFalsy();
|
|
433
|
-
result = getPackageVersion(true, './foo.tgz',
|
|
433
|
+
result = getPackageVersion(true, './foo.tgz', '', 'file', './');
|
|
434
434
|
expect(result).toEqual('file:foo.tgz');
|
|
435
|
-
result = getPackageVersion(true, 'git+https://.foo.git',
|
|
435
|
+
result = getPackageVersion(true, 'git+https://.foo.git', '', 'git', '');
|
|
436
436
|
expect(result).toEqual('git+https://.foo.git');
|
|
437
437
|
});
|
|
438
438
|
|
|
439
439
|
it('gets path to git package', () => {
|
|
440
|
-
const result = getCurrentPackageDetails('./', './foo.tgz',
|
|
440
|
+
const result = getCurrentPackageDetails('./', './foo.tgz', '', 'file://foo.tgz', './');
|
|
441
441
|
result.then(([path, version]) => {
|
|
442
442
|
expect(path).not.toBeUndefined();
|
|
443
443
|
});
|
|
444
|
-
const result2 = getCurrentPackageDetails('./', './foo.tgz',
|
|
444
|
+
const result2 = getCurrentPackageDetails('./', './foo.tgz', '', 'git+https://.foo.git', './');
|
|
445
445
|
result2.then(([path, version]) => {
|
|
446
446
|
expect(path).not.toBeUndefined();
|
|
447
447
|
});
|
|
@@ -454,32 +454,12 @@ describe('npm Module', () => {
|
|
|
454
454
|
|
|
455
455
|
it('makeExternals without externals returns coreExternals', () => {
|
|
456
456
|
const externals = makeExternals(process.cwd(), { piral: '*' });
|
|
457
|
-
expect(externals).toEqual([
|
|
458
|
-
'react',
|
|
459
|
-
'react-dom',
|
|
460
|
-
'react-router',
|
|
461
|
-
'react-router-dom',
|
|
462
|
-
'history',
|
|
463
|
-
'tslib',
|
|
464
|
-
'path-to-regexp',
|
|
465
|
-
'@libre/atom',
|
|
466
|
-
'@dbeining/react-atom',
|
|
467
|
-
]);
|
|
457
|
+
expect(externals).toEqual(['react', 'react-dom', 'react-router', 'react-router-dom', 'history', 'tslib']);
|
|
468
458
|
});
|
|
469
459
|
|
|
470
460
|
it('makeExternals with no externals returns coreExternals', () => {
|
|
471
461
|
const externals = makeExternals(process.cwd(), { piral: '*' }, []);
|
|
472
|
-
expect(externals).toEqual([
|
|
473
|
-
'react',
|
|
474
|
-
'react-dom',
|
|
475
|
-
'react-router',
|
|
476
|
-
'react-router-dom',
|
|
477
|
-
'history',
|
|
478
|
-
'tslib',
|
|
479
|
-
'path-to-regexp',
|
|
480
|
-
'@libre/atom',
|
|
481
|
-
'@dbeining/react-atom',
|
|
482
|
-
]);
|
|
462
|
+
expect(externals).toEqual(['react', 'react-dom', 'react-router', 'react-router-dom', 'history', 'tslib']);
|
|
483
463
|
});
|
|
484
464
|
|
|
485
465
|
it('makeExternals with exclude coreExternals returns empty set', () => {
|
|
@@ -498,41 +478,17 @@ describe('npm Module', () => {
|
|
|
498
478
|
'react-router-dom',
|
|
499
479
|
'history',
|
|
500
480
|
'tslib',
|
|
501
|
-
'path-to-regexp',
|
|
502
|
-
'@libre/atom',
|
|
503
|
-
'@dbeining/react-atom',
|
|
504
481
|
]);
|
|
505
482
|
});
|
|
506
483
|
|
|
507
484
|
it('makeExternals with external duplicate only reflects coreExternals', () => {
|
|
508
485
|
const externals = makeExternals(process.cwd(), { piral: '*' }, ['react', 'foo']);
|
|
509
|
-
expect(externals).toEqual([
|
|
510
|
-
'react',
|
|
511
|
-
'foo',
|
|
512
|
-
'react-dom',
|
|
513
|
-
'react-router',
|
|
514
|
-
'react-router-dom',
|
|
515
|
-
'history',
|
|
516
|
-
'tslib',
|
|
517
|
-
'path-to-regexp',
|
|
518
|
-
'@libre/atom',
|
|
519
|
-
'@dbeining/react-atom',
|
|
520
|
-
]);
|
|
486
|
+
expect(externals).toEqual(['react', 'foo', 'react-dom', 'react-router', 'react-router-dom', 'history', 'tslib']);
|
|
521
487
|
});
|
|
522
488
|
|
|
523
489
|
it('makeExternals with explicit include and exclude', () => {
|
|
524
490
|
const externals = makeExternals(process.cwd(), { piral: '*' }, ['react', 'react-calendar', '!history']);
|
|
525
|
-
expect(externals).toEqual([
|
|
526
|
-
'react',
|
|
527
|
-
'react-calendar',
|
|
528
|
-
'react-dom',
|
|
529
|
-
'react-router',
|
|
530
|
-
'react-router-dom',
|
|
531
|
-
'tslib',
|
|
532
|
-
'path-to-regexp',
|
|
533
|
-
'@libre/atom',
|
|
534
|
-
'@dbeining/react-atom',
|
|
535
|
-
]);
|
|
491
|
+
expect(externals).toEqual(['react', 'react-calendar', 'react-dom', 'react-router', 'react-router-dom', 'tslib']);
|
|
536
492
|
});
|
|
537
493
|
|
|
538
494
|
it('makeExternals with all exclude and explicit include', () => {
|
package/src/common/npm.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { createReadStream, existsSync } from 'fs';
|
|
|
3
3
|
import { log, fail } from './log';
|
|
4
4
|
import { clients, detectClients, isWrapperClient } from './clients';
|
|
5
5
|
import { config } from './config';
|
|
6
|
-
import { legacyCoreExternals, frameworkLibs } from './constants';
|
|
6
|
+
import { legacyCoreExternals, frameworkLibs, defaultRegistry } from './constants';
|
|
7
7
|
import { inspectPackage } from './inspect';
|
|
8
8
|
import { readJson, checkExists } from './io';
|
|
9
9
|
import { clientTypeKeys } from '../helpers';
|
|
@@ -129,6 +129,22 @@ export function installNpmDependencies(client: NpmClientType, target = '.'): Pro
|
|
|
129
129
|
return installDependencies(target);
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
export async function installNpmPackageFromOptionalRegistry(
|
|
133
|
+
packageRef: string,
|
|
134
|
+
target = '.',
|
|
135
|
+
registry: string,
|
|
136
|
+
): Promise<void> {
|
|
137
|
+
try {
|
|
138
|
+
await installNpmPackage('npm', packageRef, target, '--registry', registry);
|
|
139
|
+
} catch (e) {
|
|
140
|
+
if (registry === defaultRegistry) {
|
|
141
|
+
throw e;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
await installNpmPackage('npm', packageRef, target, '--registry', defaultRegistry);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
132
148
|
export async function installNpmPackage(
|
|
133
149
|
client: NpmClientType,
|
|
134
150
|
packageRef: string,
|
package/src/common/scaffold.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { join, dirname, resolve, basename, isAbsolute } from 'path';
|
|
2
|
-
import {
|
|
2
|
+
import { installNpmPackageFromOptionalRegistry } from './npm';
|
|
3
3
|
import { ForceOverwrite } from './enums';
|
|
4
4
|
import { createDirectory, createFileIfNotExists, updateExistingJson } from './io';
|
|
5
5
|
import { cliVersion, isWindows } from './info';
|
|
@@ -41,7 +41,7 @@ async function getTemplateFiles(
|
|
|
41
41
|
templatePackageName = `${templatePackageName}@latest`;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
await
|
|
44
|
+
await installNpmPackageFromOptionalRegistry(templatePackageName, __dirname, registry);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
const templateRunner = getTemplatePackage(templatePackageName);
|
package/src/questionnaire.ts
CHANGED
|
@@ -7,6 +7,7 @@ type FlagType = 'string' | 'number' | 'boolean' | 'object';
|
|
|
7
7
|
interface Flag {
|
|
8
8
|
name: string;
|
|
9
9
|
type?: FlagType;
|
|
10
|
+
alias: Array<string>;
|
|
10
11
|
values?: Array<any>;
|
|
11
12
|
describe?: string;
|
|
12
13
|
default?: any;
|
|
@@ -16,16 +17,23 @@ interface Flag {
|
|
|
16
17
|
function getCommandData(retrieve: any) {
|
|
17
18
|
const instructions: Array<Flag> = [];
|
|
18
19
|
const fn = {
|
|
20
|
+
alias(name: string, altName: string) {
|
|
21
|
+
return this.swap(name, (flag) => ({
|
|
22
|
+
...flag,
|
|
23
|
+
alias: [...flag.alias, altName],
|
|
24
|
+
}));
|
|
25
|
+
},
|
|
19
26
|
positional(name: string, info: Flag) {
|
|
20
27
|
instructions.push({
|
|
21
28
|
...info,
|
|
29
|
+
alias: [],
|
|
22
30
|
name,
|
|
23
31
|
});
|
|
24
32
|
return this;
|
|
25
33
|
},
|
|
26
34
|
swap(name: string, swapper: (flag: Flag) => Flag) {
|
|
27
35
|
const [flag] = instructions.filter((m) => m.name === name);
|
|
28
|
-
const newFlag = swapper(flag || { name });
|
|
36
|
+
const newFlag = swapper(flag || { name, alias: [] });
|
|
29
37
|
|
|
30
38
|
if (!flag) {
|
|
31
39
|
instructions.push(newFlag);
|
|
@@ -135,7 +143,7 @@ export function runQuestionnaireFor(
|
|
|
135
143
|
const questions = instructions
|
|
136
144
|
.filter((instruction) => !ignored.includes(instruction.name))
|
|
137
145
|
.filter((instruction) => !acceptAll || (instruction.default === undefined && instruction.required))
|
|
138
|
-
.filter((instruction) =>
|
|
146
|
+
.filter((instruction) => [...instruction.alias, instruction.name].every((m) => args[m] === undefined))
|
|
139
147
|
.filter((instruction) => instruction.type !== 'object')
|
|
140
148
|
.map((instruction) => ({
|
|
141
149
|
name: instruction.name,
|
|
@@ -146,12 +154,16 @@ export function runQuestionnaireFor(
|
|
|
146
154
|
validate: instruction.type === 'number' ? (input: string) => !isNaN(+input) : () => true,
|
|
147
155
|
}));
|
|
148
156
|
|
|
157
|
+
|
|
149
158
|
return inquirer.prompt(questions).then((answers) => {
|
|
150
159
|
const parameters: any = {};
|
|
151
160
|
|
|
152
161
|
for (const instruction of instructions) {
|
|
153
162
|
const name = instruction.name;
|
|
154
|
-
const value =
|
|
163
|
+
const value =
|
|
164
|
+
answers[name] ??
|
|
165
|
+
ignoredInstructions[name] ??
|
|
166
|
+
[...instruction.alias, instruction.name].map((m) => args[m]).find((v) => v !== undefined);
|
|
155
167
|
parameters[name] = value !== undefined ? getValue(instruction.type, value as any) : instruction.default;
|
|
156
168
|
}
|
|
157
169
|
|