piral-cli 0.15.0-alpha.4098 → 0.15.0-alpha.4257
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/apps/debug-pilet.js +26 -41
- package/lib/apps/debug-pilet.js.map +1 -1
- package/lib/apps/debug-piral.js +18 -33
- package/lib/apps/debug-piral.js.map +1 -1
- package/lib/apps/new-pilet.js +5 -9
- package/lib/apps/new-pilet.js.map +1 -1
- package/lib/apps/new-piral.js +9 -3
- package/lib/apps/new-piral.js.map +1 -1
- package/lib/apps/publish-pilet.d.ts +4 -0
- package/lib/apps/publish-pilet.js +4 -3
- package/lib/apps/publish-pilet.js.map +1 -1
- package/lib/apps/publish-piral.d.ts +4 -0
- package/lib/apps/publish-piral.js +9 -7
- package/lib/apps/publish-piral.js.map +1 -1
- package/lib/apps/upgrade-pilet.js +2 -8
- package/lib/apps/upgrade-pilet.js.map +1 -1
- package/lib/apps/upgrade-piral.js +1 -1
- package/lib/apps/upgrade-piral.js.map +1 -1
- package/lib/bundler.js +1 -1
- package/lib/bundler.js.map +1 -1
- package/lib/commands.js +14 -6
- package/lib/commands.js.map +1 -1
- package/lib/common/browser.d.ts +1 -0
- package/lib/common/browser.js +16 -10
- package/lib/common/browser.js.map +1 -1
- package/lib/common/clients/index.d.ts +19 -0
- package/lib/common/clients/index.js +40 -0
- package/lib/common/clients/index.js.map +1 -0
- package/lib/common/clients/lerna.d.ts +6 -1
- package/lib/common/clients/lerna.js +67 -3
- package/lib/common/clients/lerna.js.map +1 -1
- package/lib/common/clients/npm.d.ts +4 -1
- package/lib/common/clients/npm.js +37 -16
- package/lib/common/clients/npm.js.map +1 -1
- package/lib/common/clients/pnpm.d.ts +4 -0
- package/lib/common/clients/pnpm.js +43 -9
- package/lib/common/clients/pnpm.js.map +1 -1
- package/lib/common/clients/rush.d.ts +6 -0
- package/lib/common/clients/rush.js +118 -0
- package/lib/common/clients/rush.js.map +1 -0
- package/lib/common/clients/yarn.d.ts +4 -0
- package/lib/common/clients/yarn.js +45 -11
- package/lib/common/clients/yarn.js.map +1 -1
- package/lib/common/constants.d.ts +1 -1
- package/lib/common/constants.js +1 -1
- package/lib/common/constants.js.map +1 -1
- package/lib/common/declaration.js +14 -10
- package/lib/common/declaration.js.map +1 -1
- package/lib/common/emulator.js +2 -2
- package/lib/common/emulator.js.map +1 -1
- package/lib/common/http.d.ts +1 -1
- package/lib/common/http.js +12 -7
- package/lib/common/http.js.map +1 -1
- package/lib/common/importmap.js +4 -14
- package/lib/common/importmap.js.map +1 -1
- package/lib/common/info.d.ts +4 -0
- package/lib/common/info.js +6 -1
- package/lib/common/info.js.map +1 -1
- package/lib/common/injectors.d.ts +36 -7
- package/lib/common/injectors.js +39 -11
- package/lib/common/injectors.js.map +1 -1
- package/lib/common/inspect.js +2 -1
- package/lib/common/inspect.js.map +1 -1
- package/lib/common/interactive.d.ts +9 -0
- package/lib/common/interactive.js +31 -1
- package/lib/common/interactive.js.map +1 -1
- package/lib/common/io.js +1 -1
- package/lib/common/io.js.map +1 -1
- package/lib/common/npm.d.ts +11 -16
- package/lib/common/npm.js +165 -158
- package/lib/common/npm.js.map +1 -1
- package/lib/common/pack.js +1 -1
- package/lib/common/pack.js.map +1 -1
- package/lib/common/package.d.ts +6 -7
- package/lib/common/package.js +26 -28
- package/lib/common/package.js.map +1 -1
- package/lib/common/scaffold.js +5 -2
- package/lib/common/scaffold.js.map +1 -1
- package/lib/common/version.js +4 -4
- package/lib/common/version.js.map +1 -1
- package/lib/external/index.js +1982 -92
- package/lib/helpers.d.ts +4 -4
- package/lib/helpers.js +10 -10
- package/lib/helpers.js.map +1 -1
- package/lib/injectors/{pilet.d.ts → pilet-injector.d.ts} +1 -0
- package/lib/injectors/{pilet.js → pilet-injector.js} +29 -31
- package/lib/injectors/pilet-injector.js.map +1 -0
- package/lib/injectors/{piral.d.ts → piral-injector.d.ts} +1 -0
- package/lib/injectors/{piral.js → piral-injector.js} +20 -22
- package/lib/injectors/piral-injector.js.map +1 -0
- package/lib/messages.d.ts +1 -1
- package/lib/messages.js +5 -1
- package/lib/messages.js.map +1 -1
- package/lib/plugin.js +27 -2
- package/lib/plugin.js.map +1 -1
- package/lib/release.d.ts +1 -1
- package/lib/release.js +7 -2
- package/lib/release.js.map +1 -1
- package/lib/types/common.d.ts +1 -1
- package/lib/types/internal.d.ts +9 -1
- package/lib/types/public.d.ts +2 -2
- package/package.json +6 -4
- package/src/apps/debug-pilet.ts +25 -47
- package/src/apps/debug-piral.ts +19 -36
- package/src/apps/new-pilet.ts +9 -14
- package/src/apps/new-piral.ts +16 -5
- package/src/apps/publish-pilet.ts +10 -3
- package/src/apps/publish-piral.ts +21 -6
- package/src/apps/upgrade-pilet.ts +4 -12
- package/src/apps/upgrade-piral.ts +2 -2
- package/src/bundler.test.ts +1 -1
- package/src/bundler.ts +2 -2
- package/src/commands.ts +17 -9
- package/src/common/browser.ts +12 -8
- package/src/common/clients/index.ts +33 -0
- package/src/common/clients/lerna.ts +61 -1
- package/src/common/clients/npm.ts +32 -15
- package/src/common/clients/pnpm.ts +39 -10
- package/src/common/clients/rush.ts +111 -0
- package/src/common/clients/yarn.ts +41 -12
- package/src/common/constants.ts +1 -1
- package/src/common/declaration.ts +17 -10
- package/src/common/emulator.ts +3 -3
- package/src/common/http.ts +20 -6
- package/src/common/importmap.ts +4 -14
- package/src/common/info.ts +6 -1
- package/src/common/injectors.ts +46 -17
- package/src/common/inspect.ts +2 -1
- package/src/common/interactive.test.ts +3 -0
- package/src/common/interactive.ts +48 -1
- package/src/common/io.ts +1 -1
- package/src/common/npm.test.ts +122 -76
- package/src/common/npm.ts +177 -152
- package/src/common/pack.test.ts +1 -1
- package/src/common/pack.ts +2 -2
- package/src/common/package.test.ts +1 -14
- package/src/common/package.ts +31 -29
- package/src/common/scaffold.ts +6 -2
- package/src/common/version.ts +4 -4
- package/src/external/index.ts +2 -1
- package/src/helpers.test.ts +5 -5
- package/src/helpers.ts +8 -8
- package/src/injectors/{pilet.test.ts → pilet-injector.test.ts} +10 -1
- package/src/injectors/{pilet.ts → pilet-injector.ts} +36 -28
- package/src/injectors/{piral.test.ts → piral-injector.test.ts} +5 -1
- package/src/injectors/{piral.ts → piral-injector.ts} +24 -17
- package/src/messages.ts +6 -2
- package/src/plugin.ts +34 -5
- package/src/release.ts +10 -2
- package/src/types/common.ts +1 -1
- package/src/types/internal.ts +6 -1
- package/src/types/public.ts +2 -2
- package/lib/injectors/pilet.js.map +0 -1
- package/lib/injectors/piral.js.map +0 -1
package/src/commands.ts
CHANGED
|
@@ -6,9 +6,9 @@ import {
|
|
|
6
6
|
forceOverwriteKeys,
|
|
7
7
|
keyOfForceOverwrite,
|
|
8
8
|
valueOfForceOverwrite,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
keyOfSourceLanguage,
|
|
10
|
+
sourceLanguageKeys,
|
|
11
|
+
valueOfSourceLanguage,
|
|
12
12
|
frameworkKeys,
|
|
13
13
|
clientTypeKeys,
|
|
14
14
|
schemaKeys,
|
|
@@ -208,6 +208,9 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
208
208
|
.option('fields', undefined)
|
|
209
209
|
.describe('fields', 'Sets additional fields to be included in the feed service request.')
|
|
210
210
|
.default('fields', apps.publishPiralDefaults.fields)
|
|
211
|
+
.boolean('interactive')
|
|
212
|
+
.describe('interactive', 'Defines if authorization tokens can be retrieved interactively.')
|
|
213
|
+
.default('interactive', apps.publishPiralDefaults.interactive)
|
|
211
214
|
.string('base')
|
|
212
215
|
.default('base', process.cwd())
|
|
213
216
|
.describe('base', 'Sets the base directory. By default the current directory is used.');
|
|
@@ -219,6 +222,7 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
219
222
|
type: args.type as PiralBuildType,
|
|
220
223
|
provider: args.provider as string,
|
|
221
224
|
fields: args.fields as Record<string, string>,
|
|
225
|
+
interactive: args.interactive as boolean,
|
|
222
226
|
});
|
|
223
227
|
},
|
|
224
228
|
},
|
|
@@ -293,9 +297,9 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
293
297
|
.choices('force-overwrite', forceOverwriteKeys)
|
|
294
298
|
.describe('force-overwrite', 'Determines if files should be overwritten by the installation.')
|
|
295
299
|
.default('force-overwrite', keyOfForceOverwrite(apps.newPiralDefaults.forceOverwrite))
|
|
296
|
-
.choices('language',
|
|
300
|
+
.choices('language', sourceLanguageKeys)
|
|
297
301
|
.describe('language', 'Determines the programming language for the new Piral instance.')
|
|
298
|
-
.default('language',
|
|
302
|
+
.default('language', keyOfSourceLanguage(apps.newPiralDefaults.language))
|
|
299
303
|
.string('template')
|
|
300
304
|
.describe('template', 'Sets the boilerplate template package to be used when scaffolding.')
|
|
301
305
|
.default('template', apps.newPiralDefaults.template)
|
|
@@ -320,7 +324,7 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
320
324
|
version: args.tag as string,
|
|
321
325
|
registry: args.registry as string,
|
|
322
326
|
forceOverwrite: valueOfForceOverwrite(args['force-overwrite'] as string),
|
|
323
|
-
language:
|
|
327
|
+
language: valueOfSourceLanguage(args.language as string),
|
|
324
328
|
install: args.install as boolean,
|
|
325
329
|
template: args.template as string,
|
|
326
330
|
logLevel: args['log-level'] as LogLevels,
|
|
@@ -623,6 +627,9 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
623
627
|
.option('headers', undefined)
|
|
624
628
|
.describe('headers', 'Sets additional headers to be included in the feed service request.')
|
|
625
629
|
.default('headers', apps.publishPiletDefaults.headers)
|
|
630
|
+
.boolean('interactive')
|
|
631
|
+
.describe('interactive', 'Defines if authorization tokens can be retrieved interactively.')
|
|
632
|
+
.default('interactive', apps.publishPiletDefaults.interactive)
|
|
626
633
|
.string('base')
|
|
627
634
|
.default('base', process.cwd())
|
|
628
635
|
.describe('base', 'Sets the base directory. By default the current directory is used.');
|
|
@@ -641,6 +648,7 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
641
648
|
fields: args.fields as Record<string, string>,
|
|
642
649
|
headers: args.headers as Record<string, string>,
|
|
643
650
|
mode: args.mode as PiletPublishScheme,
|
|
651
|
+
interactive: args.interactive as boolean,
|
|
644
652
|
_: args,
|
|
645
653
|
});
|
|
646
654
|
},
|
|
@@ -674,9 +682,9 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
674
682
|
.number('log-level')
|
|
675
683
|
.describe('log-level', 'Sets the log level to use (1-5).')
|
|
676
684
|
.default('log-level', apps.newPiletDefaults.logLevel)
|
|
677
|
-
.choices('language',
|
|
685
|
+
.choices('language', sourceLanguageKeys)
|
|
678
686
|
.describe('language', 'Determines the programming language for the new pilet.')
|
|
679
|
-
.default('language',
|
|
687
|
+
.default('language', keyOfSourceLanguage(apps.newPiletDefaults.language))
|
|
680
688
|
.string('template')
|
|
681
689
|
.describe('template', 'Sets the boilerplate template package to be used when scaffolding.')
|
|
682
690
|
.default('template', apps.newPiletDefaults.template)
|
|
@@ -699,7 +707,7 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
699
707
|
source: args.source as string,
|
|
700
708
|
registry: args.registry as string,
|
|
701
709
|
forceOverwrite: valueOfForceOverwrite(args['force-overwrite'] as string),
|
|
702
|
-
language:
|
|
710
|
+
language: valueOfSourceLanguage(args.language as string),
|
|
703
711
|
logLevel: args['log-level'] as LogLevels,
|
|
704
712
|
install: args.install as boolean,
|
|
705
713
|
template: args.template as string,
|
package/src/common/browser.ts
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { log } from './log';
|
|
2
|
-
import { open } from '../external';
|
|
3
2
|
import { config } from './config';
|
|
3
|
+
import { open } from '../external';
|
|
4
|
+
|
|
5
|
+
export async function openBrowserAt(address: string) {
|
|
6
|
+
try {
|
|
7
|
+
await open(address, undefined);
|
|
8
|
+
} catch (err) {
|
|
9
|
+
log('failedToOpenBrowser_0170', err);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
4
12
|
|
|
5
13
|
export async function openBrowser(shouldOpen: boolean, port: number, path: string, https?: boolean) {
|
|
6
14
|
if (shouldOpen) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
await open(address, undefined);
|
|
11
|
-
} catch (err) {
|
|
12
|
-
log('failedToOpenBrowser_0170', err);
|
|
13
|
-
}
|
|
15
|
+
const scheme = https ? 'https' : 'http';
|
|
16
|
+
const address = `${scheme}://${config.host}:${port}${path}`;
|
|
17
|
+
await openBrowserAt(address);
|
|
14
18
|
}
|
|
15
19
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as lerna from './lerna';
|
|
2
|
+
import * as npm from './npm';
|
|
3
|
+
import * as pnpm from './pnpm';
|
|
4
|
+
import * as rush from './rush';
|
|
5
|
+
import * as yarn from './yarn';
|
|
6
|
+
|
|
7
|
+
export const clients = {
|
|
8
|
+
lerna,
|
|
9
|
+
npm,
|
|
10
|
+
pnpm,
|
|
11
|
+
rush,
|
|
12
|
+
yarn,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
type ClientName = keyof typeof clients;
|
|
16
|
+
|
|
17
|
+
const directClients = ['npm', 'yarn', 'pnpm'];
|
|
18
|
+
|
|
19
|
+
export function isWrapperClient(client: ClientName) {
|
|
20
|
+
return !directClients.includes(client);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function detectClients(root: string) {
|
|
24
|
+
return Promise.all(
|
|
25
|
+
Object.keys(clients).map(async (client: ClientName) => {
|
|
26
|
+
const result = await clients[client].detectClient(root);
|
|
27
|
+
return {
|
|
28
|
+
client,
|
|
29
|
+
result,
|
|
30
|
+
};
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -1,17 +1,77 @@
|
|
|
1
1
|
import { resolve } from 'path';
|
|
2
2
|
import { log } from '../log';
|
|
3
|
+
import { findFile } from '../io';
|
|
3
4
|
import { runCommand } from '../scripts';
|
|
4
5
|
import { MemoryStream } from '../MemoryStream';
|
|
5
6
|
|
|
7
|
+
// Helpers:
|
|
8
|
+
|
|
6
9
|
function runLernaProcess(args: Array<string>, target: string, output?: NodeJS.WritableStream) {
|
|
7
10
|
log('generalDebug_0003', 'Starting the Lerna process ...');
|
|
8
11
|
const cwd = resolve(process.cwd(), target);
|
|
9
12
|
return runCommand('lerna', args, cwd, output);
|
|
10
13
|
}
|
|
11
14
|
|
|
12
|
-
|
|
15
|
+
function convert(flags: Array<string>) {
|
|
16
|
+
return flags.map((flag) => {
|
|
17
|
+
switch (flag) {
|
|
18
|
+
case '--save-exact':
|
|
19
|
+
return '--exact';
|
|
20
|
+
case '--save-dev':
|
|
21
|
+
return '--dev';
|
|
22
|
+
case '--no-save':
|
|
23
|
+
// unfortunately no
|
|
24
|
+
return '';
|
|
25
|
+
default:
|
|
26
|
+
return flag;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Client interface functions:
|
|
32
|
+
|
|
33
|
+
export async function installDependencies(target = '.', ...flags: Array<string>) {
|
|
13
34
|
const ms = new MemoryStream();
|
|
14
35
|
await runLernaProcess(['bootstrap', ...flags], target, ms);
|
|
15
36
|
log('generalDebug_0003', `Lerna bootstrap result: ${ms.value}`);
|
|
16
37
|
return ms.value;
|
|
17
38
|
}
|
|
39
|
+
|
|
40
|
+
export async function installPackage(packageRef: string, target = '.', ...flags: Array<string>) {
|
|
41
|
+
const ms = new MemoryStream();
|
|
42
|
+
await runLernaProcess(['add', packageRef, ...convert(flags)], target, ms);
|
|
43
|
+
log('generalDebug_0003', `Lerna install package result: ${ms.value}`);
|
|
44
|
+
return ms.value;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function detectClient(root: string) {
|
|
48
|
+
return !!(await findFile(root, 'lerna.json'));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function initProject(projectName: string, target: string) {}
|
|
52
|
+
|
|
53
|
+
export async function isProject(root: string, packageRef: string) {
|
|
54
|
+
const projects = await listProjects(root);
|
|
55
|
+
|
|
56
|
+
if (Array.isArray(projects)) {
|
|
57
|
+
return projects?.some((p) => p.name === packageRef) ?? false;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Functions to exclusively use from lerna client:
|
|
64
|
+
|
|
65
|
+
export async function listProjects(target: string) {
|
|
66
|
+
const ms = new MemoryStream();
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
await runLernaProcess(['list', '--json', '-p'], target, ms);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
log('generalDebug_0003', `lerna list error: ${e}`);
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
log('generalDebug_0003', `lerna list project result: ${ms.value}`);
|
|
76
|
+
return JSON.parse(ms.value);
|
|
77
|
+
}
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { resolve } from 'path';
|
|
2
2
|
import { log } from '../log';
|
|
3
|
+
import { findFile } from '../io';
|
|
3
4
|
import { runCommand } from '../scripts';
|
|
4
5
|
import { MemoryStream } from '../MemoryStream';
|
|
5
6
|
|
|
7
|
+
// Helpers:
|
|
8
|
+
|
|
6
9
|
function runNpmProcess(args: Array<string>, target: string, output?: NodeJS.WritableStream) {
|
|
7
10
|
log('generalDebug_0003', 'Starting the npm process ...');
|
|
8
11
|
const cwd = resolve(process.cwd(), target);
|
|
9
12
|
return runCommand('npm', args, cwd, output);
|
|
10
13
|
}
|
|
11
14
|
|
|
15
|
+
// Client interface functions:
|
|
16
|
+
|
|
12
17
|
export async function installDependencies(target = '.', ...flags: Array<string>) {
|
|
13
18
|
const ms = new MemoryStream();
|
|
14
19
|
await runNpmProcess(['install', '--legacy-peer-deps', ...flags], target, ms);
|
|
@@ -16,26 +21,37 @@ export async function installDependencies(target = '.', ...flags: Array<string>)
|
|
|
16
21
|
return ms.value;
|
|
17
22
|
}
|
|
18
23
|
|
|
19
|
-
export async function
|
|
24
|
+
export async function installPackage(packageRef: string, target = '.', ...flags: Array<string>) {
|
|
20
25
|
const ms = new MemoryStream();
|
|
21
|
-
await runNpmProcess(['
|
|
22
|
-
log('generalDebug_0003', `npm
|
|
26
|
+
await runNpmProcess(['install', packageRef, '--legacy-peer-deps', ...flags], target, ms);
|
|
27
|
+
log('generalDebug_0003', `npm install package result: ${ms.value}`);
|
|
23
28
|
return ms.value;
|
|
24
29
|
}
|
|
25
30
|
|
|
26
|
-
export async function
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
);
|
|
37
|
-
throw ex;
|
|
31
|
+
export async function detectClient(root: string) {
|
|
32
|
+
return !!(await findFile(root, 'package-lock.json'));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function isProject(root: string, packageRef: string) {
|
|
36
|
+
const details = await listPackage(packageRef, root);
|
|
37
|
+
const packageDetails = details?.dependencies?.[packageRef];
|
|
38
|
+
|
|
39
|
+
if (packageDetails && typeof packageDetails.resolved === 'string') {
|
|
40
|
+
return packageDetails.resolved.startsWith('file:');
|
|
38
41
|
}
|
|
42
|
+
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function initProject(projectName: string, target: string) {}
|
|
47
|
+
|
|
48
|
+
// Functions to exclusively use from npm client:
|
|
49
|
+
|
|
50
|
+
export async function unpackPackage(packageRef: string, target = '.', ...flags: Array<string>) {
|
|
51
|
+
const ms = new MemoryStream();
|
|
52
|
+
await runNpmProcess(['pack', packageRef, ...flags], target, ms);
|
|
53
|
+
log('generalDebug_0003', `npm (un)pack result: ${ms.value}`);
|
|
54
|
+
return ms.value;
|
|
39
55
|
}
|
|
40
56
|
|
|
41
57
|
export async function createPackage(target = '.', ...flags: Array<string>) {
|
|
@@ -73,6 +89,7 @@ export async function listPackage(packageRef: string, target = '.', ...flags: Ar
|
|
|
73
89
|
await runNpmProcess(['ls', packageRef, '--json', '--depth', '0', ...flags], target, ms);
|
|
74
90
|
} catch (e) {
|
|
75
91
|
log('generalDebug_0003', `npm ls packageRef error: ${e}`);
|
|
92
|
+
return {};
|
|
76
93
|
}
|
|
77
94
|
|
|
78
95
|
log('generalDebug_0003', `npm ls packageRef result: ${ms.value}`);
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { resolve } from 'path';
|
|
2
2
|
import { log } from '../log';
|
|
3
|
+
import { findFile } from '../io';
|
|
3
4
|
import { runCommand } from '../scripts';
|
|
4
5
|
import { MemoryStream } from '../MemoryStream';
|
|
5
6
|
|
|
7
|
+
// Helpers:
|
|
8
|
+
|
|
6
9
|
function runPnpmProcess(args: Array<string>, target: string, output?: NodeJS.WritableStream) {
|
|
7
10
|
log('generalDebug_0003', 'Starting the Pnpm process ...');
|
|
8
11
|
const cwd = resolve(process.cwd(), target);
|
|
@@ -21,6 +24,8 @@ function convert(flags: Array<string>) {
|
|
|
21
24
|
});
|
|
22
25
|
}
|
|
23
26
|
|
|
27
|
+
// Client interface functions:
|
|
28
|
+
|
|
24
29
|
export async function installDependencies(target = '.', ...flags: Array<string>) {
|
|
25
30
|
const ms = new MemoryStream();
|
|
26
31
|
await runPnpmProcess(['install', ...convert(flags)], target, ms);
|
|
@@ -29,16 +34,40 @@ export async function installDependencies(target = '.', ...flags: Array<string>)
|
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
export async function installPackage(packageRef: string, target = '.', ...flags: Array<string>) {
|
|
37
|
+
const ms = new MemoryStream();
|
|
38
|
+
await runPnpmProcess(['add', packageRef, ...convert(flags)], target, ms);
|
|
39
|
+
log('generalDebug_0003', `Pnpm install package result: ${ms.value}`);
|
|
40
|
+
return ms.value;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function detectClient(root: string) {
|
|
44
|
+
return !!(await findFile(root, 'pnpm-lock.yaml'));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function initProject(projectName: string, target: string) {}
|
|
48
|
+
|
|
49
|
+
export async function isProject(root: string, packageRef: string) {
|
|
50
|
+
const projects = await listProjects(root);
|
|
51
|
+
|
|
52
|
+
if (Array.isArray(projects)) {
|
|
53
|
+
return projects?.some((p) => p.name === packageRef) ?? false;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Functions to exclusively use from pnpm client:
|
|
60
|
+
|
|
61
|
+
export async function listProjects(target: string) {
|
|
62
|
+
const ms = new MemoryStream();
|
|
63
|
+
|
|
32
64
|
try {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
log('generalDebug_0003', `
|
|
36
|
-
return
|
|
37
|
-
} catch (ex) {
|
|
38
|
-
log(
|
|
39
|
-
'generalError_0002',
|
|
40
|
-
`Could not install the package "${packageRef}" using Pnpm. Make sure Pnpm is correctly installed and accessible: ${ex}`,
|
|
41
|
-
);
|
|
42
|
-
throw ex;
|
|
65
|
+
await runPnpmProcess(['list', '--json', '--recursive', '--depth', '0'], target, ms);
|
|
66
|
+
} catch (e) {
|
|
67
|
+
log('generalDebug_0003', `pnpm list error: ${e}`);
|
|
68
|
+
return [];
|
|
43
69
|
}
|
|
70
|
+
|
|
71
|
+
log('generalDebug_0003', `pnpm list project result: ${ms.value}`);
|
|
72
|
+
return JSON.parse(ms.value);
|
|
44
73
|
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { dirname, relative, resolve } from 'path';
|
|
2
|
+
import { log } from '../log';
|
|
3
|
+
import { findFile, readText, writeText } from '../io';
|
|
4
|
+
import { jju } from '../../external';
|
|
5
|
+
import { runCommand } from '../scripts';
|
|
6
|
+
import { MemoryStream } from '../MemoryStream';
|
|
7
|
+
|
|
8
|
+
// Helpers:
|
|
9
|
+
const rushJson = 'rush.json';
|
|
10
|
+
|
|
11
|
+
function runRushProcess(args: Array<string>, target: string, output?: NodeJS.WritableStream) {
|
|
12
|
+
log('generalDebug_0003', 'Starting the Rush process ...');
|
|
13
|
+
const cwd = resolve(process.cwd(), target);
|
|
14
|
+
return runCommand('rush', args, cwd, output);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function convert(flags: Array<string>) {
|
|
18
|
+
return flags.map((flag) => {
|
|
19
|
+
switch (flag) {
|
|
20
|
+
case '--save-exact':
|
|
21
|
+
// discard as this may lead to problems
|
|
22
|
+
return '';
|
|
23
|
+
case '--save-dev':
|
|
24
|
+
return '--dev';
|
|
25
|
+
case '--no-save':
|
|
26
|
+
// unfortunately no
|
|
27
|
+
return '';
|
|
28
|
+
default:
|
|
29
|
+
return flag;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Client interface functions:
|
|
35
|
+
|
|
36
|
+
export async function installDependencies(target = '.', ...flags: Array<string>) {
|
|
37
|
+
const ms = new MemoryStream();
|
|
38
|
+
await runRushProcess(['update', ...convert(flags)], target, ms);
|
|
39
|
+
log('generalDebug_0003', `Rush install dependencies result: ${ms.value}`);
|
|
40
|
+
return ms.value;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function installPackage(packageRef: string, target = '.', ...flags: Array<string>) {
|
|
44
|
+
const ms = new MemoryStream();
|
|
45
|
+
await runRushProcess(['add', '--package', packageRef, ...convert(flags)], target, ms);
|
|
46
|
+
log('generalDebug_0003', `Rush install package result: ${ms.value}`);
|
|
47
|
+
return ms.value;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function detectClient(root: string) {
|
|
51
|
+
return !!(await findFile(root, rushJson));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function initProject(packageName: string, target: string) {
|
|
55
|
+
const rushPath = await findFile(target, rushJson);
|
|
56
|
+
|
|
57
|
+
if (!rushPath) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
`Could not find the "${rushJson}" from "${target}". Sure you want to create the project in the right directory?`,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const rushDir = dirname(rushPath);
|
|
64
|
+
const rushContent = await readText(rushDir, rushJson);
|
|
65
|
+
const rushData = jju.parse(rushContent);
|
|
66
|
+
const projectFolder = relative(rushDir, target);
|
|
67
|
+
|
|
68
|
+
if (!Array.isArray(rushData.projects)) {
|
|
69
|
+
rushData.projects = [];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
rushData.projects.push({
|
|
73
|
+
packageName,
|
|
74
|
+
projectFolder,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
await writeText(
|
|
78
|
+
rushDir,
|
|
79
|
+
rushJson,
|
|
80
|
+
jju.update(rushContent, rushData, {
|
|
81
|
+
mode: 'cjson',
|
|
82
|
+
indent: 2,
|
|
83
|
+
}),
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export async function isProject(root: string, packageRef: string) {
|
|
88
|
+
const details = await listProjects(root);
|
|
89
|
+
|
|
90
|
+
if (typeof details === 'object' && Array.isArray(details?.projects)) {
|
|
91
|
+
return details?.projects?.some((p) => p.name === packageRef) ?? false;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Functions to exclusively use from rush client:
|
|
98
|
+
|
|
99
|
+
export async function listProjects(target: string) {
|
|
100
|
+
const ms = new MemoryStream();
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
await runRushProcess(['list', '--json'], target, ms);
|
|
104
|
+
} catch (e) {
|
|
105
|
+
log('generalDebug_0003', `rush list error: ${e}`);
|
|
106
|
+
return {};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
log('generalDebug_0003', `rush list project result: ${ms.value}`);
|
|
110
|
+
return JSON.parse(ms.value);
|
|
111
|
+
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { resolve } from 'path';
|
|
2
2
|
import { log } from '../log';
|
|
3
|
+
import { findFile } from '../io';
|
|
3
4
|
import { runCommand } from '../scripts';
|
|
4
5
|
import { MemoryStream } from '../MemoryStream';
|
|
5
6
|
|
|
7
|
+
// Helpers:
|
|
8
|
+
|
|
6
9
|
function runYarnProcess(args: Array<string>, target: string, output?: NodeJS.WritableStream) {
|
|
7
|
-
log('generalDebug_0003', 'Starting the Yarn process ...');
|
|
10
|
+
log('generalDebug_0003', 'Starting the Yarn@1 process ...');
|
|
8
11
|
const cwd = resolve(process.cwd(), target);
|
|
9
12
|
return runCommand('yarn', args, cwd, output);
|
|
10
13
|
}
|
|
@@ -25,24 +28,50 @@ function convert(flags: Array<string>) {
|
|
|
25
28
|
});
|
|
26
29
|
}
|
|
27
30
|
|
|
31
|
+
// Client interface functions:
|
|
32
|
+
|
|
28
33
|
export async function installDependencies(target = '.', ...flags: Array<string>) {
|
|
29
34
|
const ms = new MemoryStream();
|
|
30
35
|
await runYarnProcess(['install', ...convert(flags)], target, ms);
|
|
31
|
-
log('generalDebug_0003', `Yarn install dependencies result: ${ms.value}`);
|
|
36
|
+
log('generalDebug_0003', `Yarn@1 install dependencies result: ${ms.value}`);
|
|
32
37
|
return ms.value;
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
export async function installPackage(packageRef: string, target = '.', ...flags: Array<string>) {
|
|
41
|
+
const ms = new MemoryStream();
|
|
42
|
+
await runYarnProcess(['add', packageRef, ...convert(flags)], target, ms);
|
|
43
|
+
log('generalDebug_0003', `Yarn@1 install package result: ${ms.value}`);
|
|
44
|
+
return ms.value;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function detectClient(root: string) {
|
|
48
|
+
return !!(await findFile(root, 'yarn.lock'));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function initProject(projectName: string, target: string) {}
|
|
52
|
+
|
|
53
|
+
export async function isProject(root: string, packageRef: string) {
|
|
54
|
+
const details = await listProjects(root);
|
|
55
|
+
|
|
56
|
+
if (typeof details === 'object') {
|
|
57
|
+
return typeof details?.[packageRef]?.location === 'string';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Functions to exclusively use from yarn client:
|
|
64
|
+
|
|
65
|
+
export async function listProjects(target: string) {
|
|
66
|
+
const ms = new MemoryStream();
|
|
67
|
+
|
|
36
68
|
try {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
log('generalDebug_0003', `
|
|
40
|
-
return
|
|
41
|
-
} catch (ex) {
|
|
42
|
-
log(
|
|
43
|
-
'generalError_0002',
|
|
44
|
-
`Could not install the package "${packageRef}" using Yarn. Make sure Yarn@1 is correctly installed and accessible: ${ex}`,
|
|
45
|
-
);
|
|
46
|
-
throw ex;
|
|
69
|
+
await runYarnProcess(['workspaces', 'info'], target, ms);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
log('generalDebug_0003', `yarn workspaces error: ${e}`);
|
|
72
|
+
return {};
|
|
47
73
|
}
|
|
74
|
+
|
|
75
|
+
log('generalDebug_0003', `yarn workspaces result: ${ms.value}`);
|
|
76
|
+
return JSON.parse(ms.value);
|
|
48
77
|
}
|
package/src/common/constants.ts
CHANGED
|
@@ -2,7 +2,7 @@ export const defaultRegistry = 'https://registry.npmjs.org/';
|
|
|
2
2
|
export const filesTar = 'files';
|
|
3
3
|
export const filesOnceTar = 'files_once';
|
|
4
4
|
export const piralBaseRoot = 'piral-base/package.json';
|
|
5
|
-
export const frameworkLibs = ['piral' as const, 'piral-core' as const, 'piral-base' as const];
|
|
5
|
+
export const frameworkLibs = ['piral-native' as const, 'piral' as const, 'piral-core' as const, 'piral-base' as const];
|
|
6
6
|
export const entryModuleExtensions = ['.ts', '.tsx', '.js', '.jsx'];
|
|
7
7
|
export const bundlerNames = [
|
|
8
8
|
'esbuild' as const,
|
|
@@ -16,9 +16,16 @@ function findPiralBaseApi(root: string) {
|
|
|
16
16
|
const projectDir = dirname(packageJsonPath);
|
|
17
17
|
// By default support for piral-base < 0.15
|
|
18
18
|
const { piletApiTypings = 'lib/types.d.ts' } = project;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
|
|
20
|
+
return [
|
|
21
|
+
{
|
|
22
|
+
file: resolve(projectDir, piletApiTypings),
|
|
23
|
+
name: 'PiletApi',
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
} catch (err) {
|
|
27
|
+
log('generalError_0002', `Could not find the root API of "piral-base" from "${root}": ${err}`);
|
|
28
|
+
return [];
|
|
22
29
|
}
|
|
23
30
|
}
|
|
24
31
|
|
|
@@ -141,15 +148,15 @@ export async function createPiralDeclaration(
|
|
|
141
148
|
root,
|
|
142
149
|
files,
|
|
143
150
|
types: findDeclaredTypings(root),
|
|
144
|
-
apis:
|
|
145
|
-
{
|
|
146
|
-
file: findPiralBaseApi(root),
|
|
147
|
-
name: 'PiletApi',
|
|
148
|
-
},
|
|
149
|
-
],
|
|
151
|
+
apis: findPiralBaseApi(root),
|
|
150
152
|
imports: externals,
|
|
151
153
|
logLevel,
|
|
152
154
|
logger: createLogger(),
|
|
153
155
|
};
|
|
154
|
-
|
|
156
|
+
|
|
157
|
+
if (options.apis.length) {
|
|
158
|
+
return await createDeclarationFile(options, baseDir, target, forceOverwrite);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
log('declarationCouldNotBeGenerated_0076', baseDir, 'The main Pilet API interface could not be found.');
|
|
155
162
|
}
|
package/src/common/emulator.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { findDependencyVersion, copyScaffoldingFiles, isValidDependency } from '
|
|
|
3
3
|
import { createFileFromTemplateIfNotExists } from './template';
|
|
4
4
|
import { filesTar, filesOnceTar } from './constants';
|
|
5
5
|
import { cliVersion } from './info';
|
|
6
|
-
import {
|
|
6
|
+
import { createNpmPackage, makeExternals } from './npm';
|
|
7
7
|
import { createPiralDeclaration } from './declaration';
|
|
8
8
|
import { ForceOverwrite } from './enums';
|
|
9
9
|
import { createTarball } from './archive';
|
|
@@ -31,7 +31,7 @@ export async function createEmulatorSources(
|
|
|
31
31
|
...piralPkg.devDependencies,
|
|
32
32
|
...piralPkg.dependencies,
|
|
33
33
|
};
|
|
34
|
-
const allExternals = makeExternals(allDeps, piralPkg.pilets?.externals);
|
|
34
|
+
const allExternals = makeExternals(sourceDir, allDeps, piralPkg.pilets?.externals);
|
|
35
35
|
|
|
36
36
|
const externalPackages = await Promise.all(
|
|
37
37
|
allExternals.filter(isValidDependency).map(async (name) => ({
|
|
@@ -138,7 +138,7 @@ export async function createEmulatorSources(
|
|
|
138
138
|
|
|
139
139
|
export async function packageEmulator(rootDir: string) {
|
|
140
140
|
// finally package everything up
|
|
141
|
-
await
|
|
141
|
+
await createNpmPackage(rootDir);
|
|
142
142
|
|
|
143
143
|
// get all files
|
|
144
144
|
const names = await getFileNames(rootDir);
|