piral-cli 0.15.0-alpha.4355 → 0.15.0-alpha.4409
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/commands.js +8 -0
- package/lib/commands.js.map +1 -1
- package/lib/common/archive.d.ts +4 -0
- package/lib/common/archive.js +23 -2
- package/lib/common/archive.js.map +1 -1
- package/lib/common/inspect.d.ts +3 -1
- package/lib/common/inspect.js +9 -10
- package/lib/common/inspect.js.map +1 -1
- package/lib/common/io.d.ts +1 -0
- package/lib/common/io.js +24 -12
- package/lib/common/io.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/pack.js +27 -17
- package/lib/common/pack.js.map +1 -1
- package/lib/common/package.js +4 -11
- package/lib/common/package.js.map +1 -1
- package/lib/common/scaffold.js +1 -1
- package/lib/common/scaffold.js.map +1 -1
- package/lib/external/index.js +160 -128
- package/lib/questionnaire.js +7 -4
- package/lib/questionnaire.js.map +1 -1
- package/package.json +2 -2
- package/src/commands.ts +8 -0
- package/src/common/archive.ts +28 -1
- package/src/common/inspect.ts +8 -10
- package/src/common/io.ts +15 -2
- package/src/common/npm.ts +17 -1
- package/src/common/pack.test.ts +10 -13
- package/src/common/pack.ts +43 -21
- package/src/common/package.ts +4 -16
- package/src/common/scaffold.ts +2 -2
- package/src/questionnaire.ts +15 -3
package/lib/questionnaire.js
CHANGED
|
@@ -6,13 +6,16 @@ const commands_1 = require("./commands");
|
|
|
6
6
|
function getCommandData(retrieve) {
|
|
7
7
|
const instructions = [];
|
|
8
8
|
const fn = {
|
|
9
|
+
alias(name, altName) {
|
|
10
|
+
return this.swap(name, (flag) => (Object.assign(Object.assign({}, flag), { alias: [...flag.alias, altName] })));
|
|
11
|
+
},
|
|
9
12
|
positional(name, info) {
|
|
10
|
-
instructions.push(Object.assign(Object.assign({}, info), { name }));
|
|
13
|
+
instructions.push(Object.assign(Object.assign({}, info), { alias: [], name }));
|
|
11
14
|
return this;
|
|
12
15
|
},
|
|
13
16
|
swap(name, swapper) {
|
|
14
17
|
const [flag] = instructions.filter((m) => m.name === name);
|
|
15
|
-
const newFlag = swapper(flag || { name });
|
|
18
|
+
const newFlag = swapper(flag || { name, alias: [] });
|
|
16
19
|
if (!flag) {
|
|
17
20
|
instructions.push(newFlag);
|
|
18
21
|
}
|
|
@@ -83,7 +86,7 @@ function runQuestionnaireFor(command, args, ignoredInstructions = ['base', 'log-
|
|
|
83
86
|
const questions = instructions
|
|
84
87
|
.filter((instruction) => !ignored.includes(instruction.name))
|
|
85
88
|
.filter((instruction) => !acceptAll || (instruction.default === undefined && instruction.required))
|
|
86
|
-
.filter((instruction) =>
|
|
89
|
+
.filter((instruction) => [...instruction.alias, instruction.name].every((m) => args[m] === undefined))
|
|
87
90
|
.filter((instruction) => instruction.type !== 'object')
|
|
88
91
|
.map((instruction) => ({
|
|
89
92
|
name: instruction.name,
|
|
@@ -98,7 +101,7 @@ function runQuestionnaireFor(command, args, ignoredInstructions = ['base', 'log-
|
|
|
98
101
|
const parameters = {};
|
|
99
102
|
for (const instruction of instructions) {
|
|
100
103
|
const name = instruction.name;
|
|
101
|
-
const value = (_b = (_a = answers[name]) !== null && _a !== void 0 ? _a : ignoredInstructions[name]) !== null && _b !== void 0 ? _b :
|
|
104
|
+
const value = (_b = (_a = answers[name]) !== null && _a !== void 0 ? _a : ignoredInstructions[name]) !== null && _b !== void 0 ? _b : [...instruction.alias, instruction.name].map((m) => args[m]).find((v) => v !== undefined);
|
|
102
105
|
parameters[name] = value !== undefined ? getValue(instruction.type, value) : instruction.default;
|
|
103
106
|
}
|
|
104
107
|
return command.run(parameters);
|
package/lib/questionnaire.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"questionnaire.js","sourceRoot":"","sources":["../src/questionnaire.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AACtC,yCAAsC;
|
|
1
|
+
{"version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O,CAAC,IAAI,CAAC,mCACb,mBAAmB,CAAC,IAAI,CAAC,mCACzB,CAAC,GAAG,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;YAC5F,UAAU,CAAC,IAAI,CAAC,GAAG,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE,KAAY,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC;SACzG;QAED,OAAO,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC;AArCD,kDAqCC;AAED,SAAgB,gBAAgB,CAC9B,WAAmB,EACnB,sBAA2C,CAAC,MAAM,EAAE,WAAW,CAAC;IAEhE,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAClC,MAAM,CAAC,OAAO,CAAC,GAAG,mBAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC;IACrE,OAAO,mBAAmB,CAAC,OAAO,EAAE,IAAI,EAAE,mBAAmB,CAAC,CAAC;AACjE,CAAC;AAPD,4CAOC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-cli",
|
|
3
|
-
"version": "0.15.0-alpha.
|
|
3
|
+
"version": "0.15.0-alpha.4409",
|
|
4
4
|
"description": "The standard CLI for creating and building a Piral instance or a Pilet.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"portal",
|
|
@@ -78,5 +78,5 @@
|
|
|
78
78
|
"typescript": "^4.7.3",
|
|
79
79
|
"yargs": "^15.4.1"
|
|
80
80
|
},
|
|
81
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "f5a0a4bb26fa2074af90776fa4a8b85a3eb8369a"
|
|
82
82
|
}
|
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/archive.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { resolve, relative } from 'path';
|
|
2
1
|
import { createGunzip } from 'zlib';
|
|
3
2
|
import { EventEmitter } from 'events';
|
|
3
|
+
import { createWriteStream } from 'fs';
|
|
4
|
+
import { resolve, relative } from 'path';
|
|
4
5
|
import { log } from './log';
|
|
5
6
|
import { tar } from '../external';
|
|
6
7
|
import { PackageFiles } from '../types';
|
|
@@ -11,6 +12,32 @@ interface ReadEntry extends EventEmitter {
|
|
|
11
12
|
ignore: boolean;
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Creates an npm-style tgz.
|
|
17
|
+
*/
|
|
18
|
+
export function createTgz(file: string, cwd: string, files: Array<string>) {
|
|
19
|
+
const stream = createWriteStream(file);
|
|
20
|
+
|
|
21
|
+
const tgz = tar.create(
|
|
22
|
+
{
|
|
23
|
+
cwd,
|
|
24
|
+
prefix: 'package/',
|
|
25
|
+
portable: true,
|
|
26
|
+
follow: true,
|
|
27
|
+
gzip: {
|
|
28
|
+
level: 9,
|
|
29
|
+
},
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
mtime: new Date('1985-10-26T08:15:00.000Z'),
|
|
32
|
+
},
|
|
33
|
+
files,
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
tgz.pipe(stream, { end: true });
|
|
37
|
+
|
|
38
|
+
return new Promise((finish) => stream.on('close', finish));
|
|
39
|
+
}
|
|
40
|
+
|
|
14
41
|
export function createTarball(sourceDir: string, targetDir: string, targetFile: string) {
|
|
15
42
|
const folder = relative(targetDir, sourceDir);
|
|
16
43
|
log('generalDebug_0003', `Create archive "${targetFile}" in "${targetDir}" containing "${folder}".`);
|
package/src/common/inspect.ts
CHANGED
|
@@ -12,16 +12,14 @@ function getPackageJson(files: PackageFiles): PackageData {
|
|
|
12
12
|
return jju.parse(content);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
function
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
];
|
|
24
|
-
return paths.map((filePath) => `${packageRoot}${filePath}`).filter((filePath) => !!files[filePath])[0];
|
|
15
|
+
export function getPossiblePiletMainPaths(data: PackageData) {
|
|
16
|
+
const { main = 'index.js' } = data;
|
|
17
|
+
return [main, `dist/${main}`, `${main}/index.js`, `dist/${main}/index.js`, 'index.js', 'dist/index.js'];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function getPiletMainPath(data: PackageData, files: PackageFiles) {
|
|
21
|
+
const paths = getPossiblePiletMainPaths(data);
|
|
22
|
+
return paths.map((filePath) => `${packageRoot}${filePath}`).find((filePath) => !!files[filePath]);
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
export interface PiletPackageData extends PackageData {
|
package/src/common/io.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as rimraf from 'rimraf';
|
|
2
2
|
import { transpileModule, ModuleKind, ModuleResolutionKind, ScriptTarget, JsxEmit } from 'typescript';
|
|
3
3
|
import { join, resolve, basename, dirname, extname, isAbsolute, sep } from 'path';
|
|
4
|
-
import { exists,
|
|
5
|
-
import {
|
|
4
|
+
import { exists, lstat, unlink, statSync } from 'fs';
|
|
5
|
+
import { mkdtemp, mkdir, mkdirSync, constants } from 'fs';
|
|
6
|
+
import { writeFile, readFile, readdir, copyFile } from 'fs';
|
|
6
7
|
import { log } from './log';
|
|
7
8
|
import { deepMerge } from './merge';
|
|
8
9
|
import { nodeVersion } from './info';
|
|
@@ -135,6 +136,18 @@ export async function getEntryFiles(content: string, basePath: string) {
|
|
|
135
136
|
return results;
|
|
136
137
|
}
|
|
137
138
|
|
|
139
|
+
export function makeTempDir(prefix: string) {
|
|
140
|
+
return new Promise<string>((resolve, reject) =>
|
|
141
|
+
mkdtemp(prefix, (err, folder) => {
|
|
142
|
+
if (err) {
|
|
143
|
+
reject(err);
|
|
144
|
+
} else {
|
|
145
|
+
resolve(folder);
|
|
146
|
+
}
|
|
147
|
+
}),
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
138
151
|
export function checkExists(target: string) {
|
|
139
152
|
return new Promise<boolean>((resolve) => {
|
|
140
153
|
if (target !== undefined) {
|
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/pack.test.ts
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
import { createPiletPackage } from './pack';
|
|
2
2
|
import { resolve } from 'path';
|
|
3
3
|
|
|
4
|
-
let json = {};
|
|
4
|
+
let json: any = {};
|
|
5
5
|
|
|
6
6
|
jest.mock('./io', () => ({
|
|
7
|
-
readJson: (
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
},
|
|
7
|
+
readJson: jest.fn(() => json),
|
|
8
|
+
removeDirectory: jest.fn(() => Promise.resolve()),
|
|
9
|
+
makeTempDir: jest.fn(() => Promise.resolve('')),
|
|
10
|
+
copy: jest.fn(() => Promise.resolve()),
|
|
11
|
+
checkExists: jest.fn(() => Promise.resolve(true)),
|
|
13
12
|
}));
|
|
14
13
|
|
|
15
|
-
jest.mock('./
|
|
16
|
-
|
|
17
|
-
return Promise.resolve(target);
|
|
18
|
-
},
|
|
14
|
+
jest.mock('./archive', () => ({
|
|
15
|
+
createTgz: jest.fn(() => Promise.resolve()),
|
|
19
16
|
}));
|
|
20
17
|
|
|
21
18
|
describe('Pack Module', () => {
|
|
@@ -51,7 +48,7 @@ describe('Pack Module', () => {
|
|
|
51
48
|
|
|
52
49
|
it('createPilePackage source <> target', async () => {
|
|
53
50
|
json = { name: 'foo', version: '1.0.0' };
|
|
54
|
-
const path = resolve('./', 'foo-1.0.0.tgz');
|
|
55
|
-
await expect(createPiletPackage('./', '', 'test')).resolves.toEqual(
|
|
51
|
+
const path = resolve('./', 'test', 'foo-1.0.0.tgz');
|
|
52
|
+
await expect(createPiletPackage('./', '', 'test')).resolves.toEqual(path);
|
|
56
53
|
});
|
|
57
54
|
});
|
package/src/common/pack.ts
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { tmpdir } from 'os';
|
|
2
|
+
import { resolve, relative, join, dirname, basename } from 'path';
|
|
3
|
+
import { createTgz } from './archive';
|
|
2
4
|
import { log, progress, fail } from './log';
|
|
3
|
-
import { readJson,
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
5
|
+
import { readJson, copy, removeDirectory, checkExists, makeTempDir } from './io';
|
|
6
|
+
import { getPossiblePiletMainPaths } from './inspect';
|
|
7
|
+
|
|
8
|
+
async function getPiletContentDir(root: string, packageData: any) {
|
|
9
|
+
const paths = getPossiblePiletMainPaths(packageData);
|
|
10
|
+
|
|
11
|
+
for (const path of paths) {
|
|
12
|
+
const file = resolve(root, path);
|
|
13
|
+
|
|
14
|
+
if (await checkExists(file)) {
|
|
15
|
+
return dirname(file);
|
|
16
|
+
}
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
return
|
|
19
|
+
return root;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
export async function createPiletPackage(baseDir: string, source: string, target: string) {
|
|
@@ -36,13 +38,33 @@ export async function createPiletPackage(baseDir: string, source: string, target
|
|
|
36
38
|
fail('packageJsonMissingVersion_0022');
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
const file =
|
|
41
|
+
const isFileTarget = target.endsWith('.tgz');
|
|
42
|
+
progress(`Packing pilet in "${root}" ...`);
|
|
43
|
+
|
|
44
|
+
const pckgName = pckg.name.replace(/@/g, '').replace(/\//g, '-');
|
|
45
|
+
const id = `${pckgName}-${pckg.version}`;
|
|
46
|
+
const name = isFileTarget ? basename(target) : `${id}.tgz`;
|
|
47
|
+
const file = isFileTarget ? dest : resolve(dest, name);
|
|
48
|
+
log('generalDebug_0003', `Assume package name "${name}".`);
|
|
49
|
+
|
|
50
|
+
const content = await getPiletContentDir(root, pckg);
|
|
51
|
+
const files = [resolve(root, 'package.json'), content];
|
|
52
|
+
const prefix = join(tmpdir(), `${id}-`);
|
|
53
|
+
const cwd = await makeTempDir(prefix);
|
|
54
|
+
log('generalDebug_0003', `Creating package with content from "${content}" ...`);
|
|
55
|
+
|
|
56
|
+
await Promise.all(files.map((file) => copy(file, resolve(cwd, relative(root, file)))));
|
|
57
|
+
|
|
58
|
+
await createTgz(
|
|
59
|
+
file,
|
|
60
|
+
cwd,
|
|
61
|
+
files.map((f) => relative(root, f)),
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
log('generalDebug_0003', `Successfully created package from "${cwd}".`);
|
|
65
|
+
|
|
66
|
+
await removeDirectory(cwd);
|
|
67
|
+
|
|
46
68
|
log('generalDebug_0003', `Packed file "${file}".`);
|
|
47
69
|
return file;
|
|
48
70
|
}
|
package/src/common/package.ts
CHANGED
|
@@ -518,21 +518,7 @@ export async function patchPiletPackage(
|
|
|
518
518
|
...info.scripts,
|
|
519
519
|
}
|
|
520
520
|
: info.scripts;
|
|
521
|
-
const peerModules = [];
|
|
522
521
|
const allExternals = makePiletExternals(root, piralDependencies, externals, fromEmulator, piralInfo);
|
|
523
|
-
const peerDependencies = {
|
|
524
|
-
...allExternals.reduce((deps, name) => {
|
|
525
|
-
const valid = isValidDependency(name);
|
|
526
|
-
deps[name] = valid ? '*' : undefined;
|
|
527
|
-
|
|
528
|
-
if (!valid) {
|
|
529
|
-
peerModules.push(name);
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
return deps;
|
|
533
|
-
}, {}),
|
|
534
|
-
[name]: `*`,
|
|
535
|
-
};
|
|
536
522
|
const devDependencies: Record<string, string> = {
|
|
537
523
|
...Object.keys(typeDependencies).reduce((deps, name) => {
|
|
538
524
|
deps[name] = piralDependencies[name] || typeDependencies[name];
|
|
@@ -564,9 +550,11 @@ export async function patchPiletPackage(
|
|
|
564
550
|
|
|
565
551
|
const packageContent = deepMerge(packageOverrides, {
|
|
566
552
|
piral,
|
|
553
|
+
importmap: {
|
|
554
|
+
imports: {},
|
|
555
|
+
inherit: [name],
|
|
556
|
+
},
|
|
567
557
|
devDependencies,
|
|
568
|
-
peerDependencies,
|
|
569
|
-
peerModules,
|
|
570
558
|
dependencies: {
|
|
571
559
|
[name]: undefined,
|
|
572
560
|
},
|
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
|
|