piral-cli 0.15.0-alpha.4284 → 0.15.0-alpha.4332
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/new-pilet.d.ts +2 -2
- package/lib/apps/new-pilet.js +3 -3
- package/lib/apps/new-pilet.js.map +1 -1
- package/lib/apps/new-piral.d.ts +2 -2
- package/lib/apps/new-piral.js +6 -5
- package/lib/apps/new-piral.js.map +1 -1
- package/lib/apps/publish-piral.d.ts +2 -2
- package/lib/apps/publish-piral.js +8 -7
- package/lib/apps/publish-piral.js.map +1 -1
- package/lib/apps/upgrade-pilet.js +3 -3
- package/lib/apps/upgrade-pilet.js.map +1 -1
- package/lib/apps/upgrade-piral.js +2 -2
- package/lib/apps/upgrade-piral.js.map +1 -1
- package/lib/commands.js +8 -8
- package/lib/commands.js.map +1 -1
- package/lib/common/clients/index.d.ts +3 -1
- package/lib/common/clients/index.js +3 -1
- package/lib/common/clients/index.js.map +1 -1
- package/lib/common/clients/npm.d.ts +1 -0
- package/lib/common/clients/npm.js +7 -1
- package/lib/common/clients/npm.js.map +1 -1
- package/lib/common/clients/pnp.d.ts +6 -0
- package/lib/common/clients/pnp.js +95 -0
- package/lib/common/clients/pnp.js.map +1 -0
- package/lib/common/clients/yarn.js +3 -3
- package/lib/common/clients/yarn.js.map +1 -1
- package/lib/common/config.d.ts +1 -2
- package/lib/common/config.js +1 -2
- package/lib/common/config.js.map +1 -1
- package/lib/common/emulator.js +1 -1
- package/lib/common/emulator.js.map +1 -1
- package/lib/common/enums.d.ts +0 -4
- package/lib/common/enums.js +1 -6
- package/lib/common/enums.js.map +1 -1
- package/lib/common/interactive.js +4 -1
- package/lib/common/interactive.js.map +1 -1
- package/lib/common/language.d.ts +3 -13
- package/lib/common/language.js +46 -12
- package/lib/common/language.js.map +1 -1
- package/lib/common/npm.d.ts +1 -1
- package/lib/common/npm.js +13 -5
- package/lib/common/npm.js.map +1 -1
- package/lib/common/package.d.ts +9 -3
- package/lib/common/package.js +11 -25
- package/lib/common/package.js.map +1 -1
- package/lib/common/scaffold.d.ts +12 -10
- package/lib/common/scaffold.js +6 -12
- package/lib/common/scaffold.js.map +1 -1
- package/lib/common/template.d.ts +1 -3
- package/lib/common/template.js +21 -47
- package/lib/common/template.js.map +1 -1
- package/lib/external/index.js +79 -79
- package/lib/helpers.d.ts +3 -5
- package/lib/helpers.js +3 -21
- package/lib/helpers.js.map +1 -1
- package/lib/injectors/pilet-injector.d.ts +1 -0
- package/lib/injectors/piral-injector.d.ts +1 -0
- package/lib/messages.d.ts +11 -11
- package/lib/messages.js +14 -14
- package/lib/messages.js.map +1 -1
- package/lib/release.js +1 -1
- package/lib/release.js.map +1 -1
- package/lib/types/common.d.ts +0 -1
- package/lib/types/public.d.ts +2 -1
- package/package.json +3 -5
- package/src/apps/new-pilet.test.ts +9 -6
- package/src/apps/new-pilet.ts +4 -4
- package/src/apps/new-piral.test.ts +3 -6
- package/src/apps/new-piral.ts +8 -12
- package/src/apps/publish-piral.ts +20 -9
- package/src/apps/upgrade-pilet.ts +3 -3
- package/src/apps/upgrade-piral.ts +2 -1
- package/src/commands.ts +9 -10
- package/src/common/clients/index.ts +3 -1
- package/src/common/clients/npm.ts +4 -0
- package/src/common/clients/pnp.ts +77 -0
- package/src/common/clients/yarn.ts +3 -3
- package/src/common/config.ts +2 -3
- package/src/common/emulator.ts +2 -2
- package/src/common/enums.ts +0 -5
- package/src/common/interactive.ts +5 -1
- package/src/common/language.ts +59 -11
- package/src/common/npm.ts +21 -6
- package/src/common/package.test.ts +11 -3
- package/src/common/package.ts +20 -34
- package/src/common/scaffold.ts +8 -16
- package/src/common/template.ts +19 -40
- package/src/helpers.test.ts +2 -22
- package/src/helpers.ts +4 -24
- package/src/messages.ts +14 -14
- package/src/release.ts +1 -1
- package/src/types/common.ts +0 -1
- package/src/types/public.ts +3 -1
- package/templates/piral-index.js.ejs +0 -16
|
@@ -24,7 +24,6 @@ import {
|
|
|
24
24
|
getPiralPath,
|
|
25
25
|
isMonorepoPackageRef,
|
|
26
26
|
getPiletScaffoldData,
|
|
27
|
-
SourceLanguage,
|
|
28
27
|
} from '../common';
|
|
29
28
|
|
|
30
29
|
export interface UpgradePiletOptions {
|
|
@@ -88,6 +87,7 @@ export async function upgradePilet(baseDir = process.cwd(), options: UpgradePile
|
|
|
88
87
|
logLevel = upgradePiletDefaults.logLevel,
|
|
89
88
|
install = upgradePiletDefaults.install,
|
|
90
89
|
variables = upgradePiletDefaults.variables,
|
|
90
|
+
npmClient: defaultNpmClient = upgradePiletDefaults.npmClient,
|
|
91
91
|
} = options;
|
|
92
92
|
const fullBase = resolve(process.cwd(), baseDir);
|
|
93
93
|
const root = resolve(fullBase, target);
|
|
@@ -98,13 +98,13 @@ export async function upgradePilet(baseDir = process.cwd(), options: UpgradePile
|
|
|
98
98
|
fail('invalidPiletTarget_0040');
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
const npmClient = await determineNpmClient(root,
|
|
101
|
+
const npmClient = await determineNpmClient(root, defaultNpmClient);
|
|
102
102
|
const pckg = await readJson(root, 'package.json');
|
|
103
103
|
const { devDependencies = {}, dependencies = {}, piral, source } = pckg;
|
|
104
104
|
|
|
105
105
|
if (piral && typeof piral === 'object') {
|
|
106
106
|
const sourceName = piral.name;
|
|
107
|
-
const language = /\.jsx?$/.test(source) ?
|
|
107
|
+
const language = /\.jsx?$/.test(source) ? 'js' : 'ts';
|
|
108
108
|
|
|
109
109
|
if (!sourceName || typeof sourceName !== 'string') {
|
|
110
110
|
fail('invalidPiletPackage_0042');
|
|
@@ -80,6 +80,7 @@ export async function upgradePiral(baseDir = process.cwd(), options: UpgradePira
|
|
|
80
80
|
target = upgradePiralDefaults.target,
|
|
81
81
|
logLevel = upgradePiralDefaults.logLevel,
|
|
82
82
|
install = upgradePiralDefaults.install,
|
|
83
|
+
npmClient: defaultNpmClient = upgradePiralDefaults.npmClient,
|
|
83
84
|
} = options;
|
|
84
85
|
const fullBase = resolve(process.cwd(), baseDir);
|
|
85
86
|
const root = resolve(fullBase, target);
|
|
@@ -91,7 +92,7 @@ export async function upgradePiral(baseDir = process.cwd(), options: UpgradePira
|
|
|
91
92
|
fail('packageJsonNotFound_0020');
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
const npmClient = await determineNpmClient(root,
|
|
95
|
+
const npmClient = await determineNpmClient(root, defaultNpmClient);
|
|
95
96
|
|
|
96
97
|
progress(`Checking provided version ...`);
|
|
97
98
|
const realVersion = await findSpecificVersion('piral-cli', version);
|
package/src/commands.ts
CHANGED
|
@@ -6,9 +6,7 @@ import {
|
|
|
6
6
|
forceOverwriteKeys,
|
|
7
7
|
keyOfForceOverwrite,
|
|
8
8
|
valueOfForceOverwrite,
|
|
9
|
-
keyOfSourceLanguage,
|
|
10
9
|
sourceLanguageKeys,
|
|
11
|
-
valueOfSourceLanguage,
|
|
12
10
|
frameworkKeys,
|
|
13
11
|
clientTypeKeys,
|
|
14
12
|
schemaKeys,
|
|
@@ -27,6 +25,7 @@ import {
|
|
|
27
25
|
PiletSchemaVersion,
|
|
28
26
|
PiletBuildType,
|
|
29
27
|
PiletPublishScheme,
|
|
28
|
+
SourceLanguage,
|
|
30
29
|
} from './types';
|
|
31
30
|
|
|
32
31
|
function specializeCommand(commands: Array<ToolCommand<any>>, command: ToolCommand<any>, suffix: string) {
|
|
@@ -205,9 +204,9 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
205
204
|
.choices('provider', availableReleaseProviders)
|
|
206
205
|
.describe('provider', 'Sets the provider for publishing the release assets.')
|
|
207
206
|
.default('provider', apps.publishPiralDefaults.provider)
|
|
208
|
-
.option('
|
|
209
|
-
.describe('
|
|
210
|
-
.default('
|
|
207
|
+
.option('opts', undefined)
|
|
208
|
+
.describe('opts', 'Sets the options to forward to the chosen provider.')
|
|
209
|
+
.default('opts', apps.publishPiralDefaults.opts)
|
|
211
210
|
.boolean('interactive')
|
|
212
211
|
.describe('interactive', 'Defines if authorization tokens can be retrieved interactively.')
|
|
213
212
|
.default('interactive', apps.publishPiralDefaults.interactive)
|
|
@@ -221,7 +220,7 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
221
220
|
logLevel: args['log-level'] as LogLevels,
|
|
222
221
|
type: args.type as PiralBuildType,
|
|
223
222
|
provider: args.provider as string,
|
|
224
|
-
|
|
223
|
+
opts: args.opts as Record<string, string>,
|
|
225
224
|
interactive: args.interactive as boolean,
|
|
226
225
|
});
|
|
227
226
|
},
|
|
@@ -299,7 +298,7 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
299
298
|
.default('force-overwrite', keyOfForceOverwrite(apps.newPiralDefaults.forceOverwrite))
|
|
300
299
|
.choices('language', sourceLanguageKeys)
|
|
301
300
|
.describe('language', 'Determines the programming language for the new Piral instance.')
|
|
302
|
-
.default('language',
|
|
301
|
+
.default('language', apps.newPiralDefaults.language)
|
|
303
302
|
.string('template')
|
|
304
303
|
.describe('template', 'Sets the boilerplate template package to be used when scaffolding.')
|
|
305
304
|
.default('template', apps.newPiralDefaults.template)
|
|
@@ -324,7 +323,7 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
324
323
|
version: args.tag as string,
|
|
325
324
|
registry: args.registry as string,
|
|
326
325
|
forceOverwrite: valueOfForceOverwrite(args['force-overwrite'] as string),
|
|
327
|
-
language:
|
|
326
|
+
language: args.language as SourceLanguage,
|
|
328
327
|
install: args.install as boolean,
|
|
329
328
|
template: args.template as string,
|
|
330
329
|
logLevel: args['log-level'] as LogLevels,
|
|
@@ -684,7 +683,7 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
684
683
|
.default('log-level', apps.newPiletDefaults.logLevel)
|
|
685
684
|
.choices('language', sourceLanguageKeys)
|
|
686
685
|
.describe('language', 'Determines the programming language for the new pilet.')
|
|
687
|
-
.default('language',
|
|
686
|
+
.default('language', apps.newPiletDefaults.language)
|
|
688
687
|
.string('template')
|
|
689
688
|
.describe('template', 'Sets the boilerplate template package to be used when scaffolding.')
|
|
690
689
|
.default('template', apps.newPiletDefaults.template)
|
|
@@ -707,7 +706,7 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
707
706
|
source: args.source as string,
|
|
708
707
|
registry: args.registry as string,
|
|
709
708
|
forceOverwrite: valueOfForceOverwrite(args['force-overwrite'] as string),
|
|
710
|
-
language:
|
|
709
|
+
language: args.language as SourceLanguage,
|
|
711
710
|
logLevel: args['log-level'] as LogLevels,
|
|
712
711
|
install: args.install as boolean,
|
|
713
712
|
template: args.template as string,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as lerna from './lerna';
|
|
2
2
|
import * as npm from './npm';
|
|
3
|
+
import * as pnp from './pnp';
|
|
3
4
|
import * as pnpm from './pnpm';
|
|
4
5
|
import * as rush from './rush';
|
|
5
6
|
import * as yarn from './yarn';
|
|
@@ -7,6 +8,7 @@ import * as yarn from './yarn';
|
|
|
7
8
|
export const clients = {
|
|
8
9
|
lerna,
|
|
9
10
|
npm,
|
|
11
|
+
pnp,
|
|
10
12
|
pnpm,
|
|
11
13
|
rush,
|
|
12
14
|
yarn,
|
|
@@ -14,7 +16,7 @@ export const clients = {
|
|
|
14
16
|
|
|
15
17
|
type ClientName = keyof typeof clients;
|
|
16
18
|
|
|
17
|
-
const directClients = ['npm', 'yarn', 'pnpm'];
|
|
19
|
+
const directClients = ['npm', 'pnp', 'yarn', 'pnpm'];
|
|
18
20
|
|
|
19
21
|
export function isWrapperClient(client: ClientName) {
|
|
20
22
|
return !directClients.includes(client);
|
|
@@ -47,6 +47,10 @@ export async function initProject(projectName: string, target: string) {}
|
|
|
47
47
|
|
|
48
48
|
// Functions to exclusively use from npm client:
|
|
49
49
|
|
|
50
|
+
export async function loginUser() {
|
|
51
|
+
await runNpmProcess(['login'], '.');
|
|
52
|
+
}
|
|
53
|
+
|
|
50
54
|
export async function unpackPackage(packageRef: string, target = '.', ...flags: Array<string>) {
|
|
51
55
|
const ms = new MemoryStream();
|
|
52
56
|
await runNpmProcess(['pack', packageRef, ...flags], target, ms);
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import { log } from '../log';
|
|
3
|
+
import { findFile } from '../io';
|
|
4
|
+
import { runCommand } from '../scripts';
|
|
5
|
+
import { MemoryStream } from '../MemoryStream';
|
|
6
|
+
|
|
7
|
+
// Helpers:
|
|
8
|
+
|
|
9
|
+
function runYarnProcess(args: Array<string>, target: string, output?: NodeJS.WritableStream) {
|
|
10
|
+
log('generalDebug_0003', 'Starting the Yarn PnP process ...');
|
|
11
|
+
const cwd = resolve(process.cwd(), target);
|
|
12
|
+
return runCommand('yarn', args, cwd, output);
|
|
13
|
+
}
|
|
14
|
+
|
|
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 (https://github.com/yarnpkg/yarn/issues/1743)
|
|
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>) {
|
|
34
|
+
const ms = new MemoryStream();
|
|
35
|
+
await runYarnProcess(['install', ...convert(flags)], target, ms);
|
|
36
|
+
log('generalDebug_0003', `Yarn PnP install dependencies result: ${ms.value}`);
|
|
37
|
+
return ms.value;
|
|
38
|
+
}
|
|
39
|
+
|
|
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 PnP install package result: ${ms.value}`);
|
|
44
|
+
return ms.value;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function detectClient(root: string) {
|
|
48
|
+
return !!(await findFile(root, '.pnp.cjs'));
|
|
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
|
+
|
|
68
|
+
try {
|
|
69
|
+
await runYarnProcess(['workspaces', 'info'], target, ms);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
log('generalDebug_0003', `yarn workspaces error: ${e}`);
|
|
72
|
+
return {};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
log('generalDebug_0003', `yarn workspaces result: ${ms.value}`);
|
|
76
|
+
return JSON.parse(ms.value);
|
|
77
|
+
}
|
|
@@ -7,7 +7,7 @@ import { MemoryStream } from '../MemoryStream';
|
|
|
7
7
|
// Helpers:
|
|
8
8
|
|
|
9
9
|
function runYarnProcess(args: Array<string>, target: string, output?: NodeJS.WritableStream) {
|
|
10
|
-
log('generalDebug_0003', 'Starting the Yarn
|
|
10
|
+
log('generalDebug_0003', 'Starting the Yarn Classic process ...');
|
|
11
11
|
const cwd = resolve(process.cwd(), target);
|
|
12
12
|
return runCommand('yarn', args, cwd, output);
|
|
13
13
|
}
|
|
@@ -33,14 +33,14 @@ function convert(flags: Array<string>) {
|
|
|
33
33
|
export async function installDependencies(target = '.', ...flags: Array<string>) {
|
|
34
34
|
const ms = new MemoryStream();
|
|
35
35
|
await runYarnProcess(['install', ...convert(flags)], target, ms);
|
|
36
|
-
log('generalDebug_0003', `Yarn
|
|
36
|
+
log('generalDebug_0003', `Yarn Classic install dependencies result: ${ms.value}`);
|
|
37
37
|
return ms.value;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
export async function installPackage(packageRef: string, target = '.', ...flags: Array<string>) {
|
|
41
41
|
const ms = new MemoryStream();
|
|
42
42
|
await runYarnProcess(['add', packageRef, ...convert(flags)], target, ms);
|
|
43
|
-
log('generalDebug_0003', `Yarn
|
|
43
|
+
log('generalDebug_0003', `Yarn Classic install package result: ${ms.value}`);
|
|
44
44
|
return ms.value;
|
|
45
45
|
}
|
|
46
46
|
|
package/src/common/config.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { SourceLanguage } from './enums';
|
|
2
1
|
import { defaultRegistry } from './constants';
|
|
3
2
|
import { rc } from '../external';
|
|
4
|
-
import { NpmClientType, PiletSchemaVersion } from '../types';
|
|
3
|
+
import { SourceLanguage, NpmClientType, PiletSchemaVersion } from '../types';
|
|
5
4
|
|
|
6
5
|
export interface PiralCliConfig {
|
|
7
6
|
/**
|
|
@@ -79,7 +78,7 @@ export const config: PiralCliConfig = rc(
|
|
|
79
78
|
schemaVersion: 'v2' as const,
|
|
80
79
|
openBrowser: false,
|
|
81
80
|
port: 1234,
|
|
82
|
-
language:
|
|
81
|
+
language: 'ts' as const,
|
|
83
82
|
host: 'localhost',
|
|
84
83
|
registry: defaultRegistry,
|
|
85
84
|
},
|
package/src/common/emulator.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { join, resolve, relative } from 'path';
|
|
2
2
|
import { findDependencyVersion, copyScaffoldingFiles, isValidDependency } from './package';
|
|
3
|
-
import {
|
|
3
|
+
import { createPiralStubIndexIfNotExists } from './template';
|
|
4
4
|
import { filesTar, filesOnceTar } from './constants';
|
|
5
5
|
import { cliVersion } from './info';
|
|
6
6
|
import { createNpmPackage, makeExternals } from './npm';
|
|
@@ -116,7 +116,7 @@ export async function createEmulatorSources(
|
|
|
116
116
|
await copyScaffoldingFiles(sourceDir, rootDir, piralPkg.files ?? []);
|
|
117
117
|
|
|
118
118
|
// actually including this one hints that the app shell should have been included - which is forbidden
|
|
119
|
-
await
|
|
119
|
+
await createPiralStubIndexIfNotExists(targetDir, 'index.js', ForceOverwrite.yes, {
|
|
120
120
|
name: piralPkg.name,
|
|
121
121
|
outFile: targetFile,
|
|
122
122
|
});
|
package/src/common/enums.ts
CHANGED
|
@@ -56,7 +56,11 @@ export function getTokenInteractively(url: string, httpsAgent: Agent): TokenResu
|
|
|
56
56
|
)
|
|
57
57
|
.then((res) => {
|
|
58
58
|
const { loginUrl, callbackUrl, expires } = res.data;
|
|
59
|
-
|
|
59
|
+
const now = new Date();
|
|
60
|
+
const then = new Date(expires);
|
|
61
|
+
const diff = ~~((then.valueOf() - now.valueOf()) / (60 * 1000));
|
|
62
|
+
|
|
63
|
+
console.log(`Use the URL below to complete the login. The link expires in ${diff} minutes (${then}).`);
|
|
60
64
|
console.log('===');
|
|
61
65
|
console.log(loginUrl);
|
|
62
66
|
console.log('===');
|
package/src/common/language.ts
CHANGED
|
@@ -1,45 +1,93 @@
|
|
|
1
1
|
import { log } from './log';
|
|
2
|
-
import { SourceLanguage } from '
|
|
2
|
+
import { Framework, SourceLanguage } from '../types';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
const react17Deps = {
|
|
5
5
|
react: '^17',
|
|
6
6
|
'react-dom': '^17',
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const react18Deps = {
|
|
10
|
+
react: '^18',
|
|
11
|
+
'react-dom': '^18',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const reactRouter5Deps = {
|
|
7
15
|
'react-router': '^5',
|
|
8
16
|
'react-router-dom': '^5',
|
|
9
17
|
};
|
|
10
18
|
|
|
11
|
-
|
|
19
|
+
const reactRouter6Deps = {
|
|
20
|
+
'react-router': '^6',
|
|
21
|
+
'react-router-dom': '^6',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const react17Typings = {
|
|
12
25
|
'@types/react': '^17',
|
|
13
26
|
'@types/react-dom': '^17',
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const react18Typings = {
|
|
30
|
+
'@types/react': '^18',
|
|
31
|
+
'@types/react-dom': '^18',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const reactRouter5Typings = {
|
|
14
35
|
'@types/react-router': '^5',
|
|
15
36
|
'@types/react-router-dom': '^5',
|
|
16
37
|
};
|
|
17
38
|
|
|
18
|
-
|
|
39
|
+
const defaultDeps = {};
|
|
40
|
+
|
|
41
|
+
const defaultTypings = {
|
|
42
|
+
'@types/react': '*',
|
|
43
|
+
'@types/react-dom': '*',
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export function getDependencyPackages(framework: Framework, reactVersion: number, reactRouterVersion: number) {
|
|
47
|
+
// take default packages only if piral-core
|
|
48
|
+
return framework !== 'piral-core'
|
|
49
|
+
? {}
|
|
50
|
+
: {
|
|
51
|
+
...(reactVersion < 18 ? react17Deps : react18Deps),
|
|
52
|
+
...(reactRouterVersion < 6 ? reactRouter5Deps : reactRouter6Deps),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function getDevDependencyPackages(framework: Framework, reactVersion: number, reactRouterVersion: number) {
|
|
57
|
+
// take default dev packages only if not piral-base
|
|
58
|
+
return framework === 'piral-base'
|
|
59
|
+
? {}
|
|
60
|
+
: {
|
|
61
|
+
...(reactVersion < 18 ? react17Typings : react18Typings),
|
|
62
|
+
...(reactRouterVersion < 6 ? reactRouter5Typings : {}),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function getDependencies(language: SourceLanguage, packages: Record<string, string> = defaultDeps) {
|
|
19
67
|
switch (language) {
|
|
20
|
-
case
|
|
21
|
-
case
|
|
68
|
+
case 'js':
|
|
69
|
+
case 'ts':
|
|
22
70
|
return {
|
|
23
71
|
...packages,
|
|
24
72
|
};
|
|
25
73
|
default:
|
|
26
|
-
log('generalDebug_0003', 'Did not find a valid language.
|
|
74
|
+
log('generalDebug_0003', 'Did not find a valid language. Skipping "dependencies".');
|
|
27
75
|
return {};
|
|
28
76
|
}
|
|
29
77
|
}
|
|
30
78
|
|
|
31
|
-
export function getDevDependencies(language: SourceLanguage, typings: Record<string, string> =
|
|
79
|
+
export function getDevDependencies(language: SourceLanguage, typings: Record<string, string> = defaultTypings) {
|
|
32
80
|
switch (language) {
|
|
33
|
-
case
|
|
81
|
+
case 'ts':
|
|
34
82
|
return {
|
|
35
83
|
...typings,
|
|
36
84
|
'@types/node': 'latest',
|
|
37
85
|
typescript: 'latest',
|
|
38
86
|
};
|
|
39
|
-
case
|
|
87
|
+
case 'js':
|
|
40
88
|
return {};
|
|
41
89
|
default:
|
|
42
|
-
log('generalDebug_0003', 'Did not find a valid language.
|
|
90
|
+
log('generalDebug_0003', 'Did not find a valid language. Skipping "devDependencies".');
|
|
43
91
|
return {};
|
|
44
92
|
}
|
|
45
93
|
}
|
package/src/common/npm.ts
CHANGED
|
@@ -43,6 +43,10 @@ async function detectMonorepoRoot(root: string): Promise<[] | [string, NpmClient
|
|
|
43
43
|
const packageJson = await readJson(root, 'package.json');
|
|
44
44
|
|
|
45
45
|
if (Array.isArray(packageJson?.workspaces)) {
|
|
46
|
+
if (await checkExists(resolve(root, '.pnp.cjs'))) {
|
|
47
|
+
return [root, 'pnp'];
|
|
48
|
+
}
|
|
49
|
+
|
|
46
50
|
if (await checkExists(resolve(root, 'yarn.lock'))) {
|
|
47
51
|
return [root, 'yarn'];
|
|
48
52
|
}
|
|
@@ -74,8 +78,6 @@ export async function determineNpmClient(root: string, selected?: NpmClientType)
|
|
|
74
78
|
`Results of the lock file check: ${searchedClients.map((m) => `${m.client}=${m.result}`).join(', ')}`,
|
|
75
79
|
);
|
|
76
80
|
|
|
77
|
-
const defaultClient = config.npmClient;
|
|
78
|
-
|
|
79
81
|
if (foundClients.length > 1) {
|
|
80
82
|
const wrapperClient = foundClients.find((m) => isWrapperClient(m.client));
|
|
81
83
|
|
|
@@ -97,12 +99,14 @@ export async function determineNpmClient(root: string, selected?: NpmClientType)
|
|
|
97
99
|
return client;
|
|
98
100
|
}
|
|
99
101
|
|
|
102
|
+
const defaultClient = config.npmClient;
|
|
103
|
+
|
|
100
104
|
if (clientTypeKeys.includes(defaultClient)) {
|
|
101
105
|
log('generalDebug_0003', `Using the default client: "${defaultClient}".`);
|
|
102
106
|
return defaultClient;
|
|
103
107
|
}
|
|
104
108
|
|
|
105
|
-
log('generalDebug_0003', 'Using the
|
|
109
|
+
log('generalDebug_0003', 'Using the fallback "npm" client.');
|
|
106
110
|
return 'npm';
|
|
107
111
|
}
|
|
108
112
|
|
|
@@ -148,9 +152,20 @@ export function initNpmProject(client: NpmClientType, projectName: string, targe
|
|
|
148
152
|
return initProject(projectName, target);
|
|
149
153
|
}
|
|
150
154
|
|
|
151
|
-
export function publishNpmPackage(
|
|
152
|
-
|
|
153
|
-
|
|
155
|
+
export function publishNpmPackage(
|
|
156
|
+
target = '.',
|
|
157
|
+
file = '*.tgz',
|
|
158
|
+
flags: Array<string> = [],
|
|
159
|
+
interactive = false,
|
|
160
|
+
): Promise<string> {
|
|
161
|
+
const { publishPackage, loginUser } = clients.npm;
|
|
162
|
+
return publishPackage(target, file, ...flags).catch(err => {
|
|
163
|
+
if (!interactive) {
|
|
164
|
+
throw err;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return loginUser().then(() => publishNpmPackage(target, file, flags, false));
|
|
168
|
+
});
|
|
154
169
|
}
|
|
155
170
|
|
|
156
171
|
export function createNpmPackage(target = '.'): Promise<string> {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { findPackageVersion, getPiralPackage, getPiletsInfo, retrievePiletData } from './package';
|
|
2
2
|
import { cliVersion } from './info';
|
|
3
|
-
import { SourceLanguage } from './enums';
|
|
4
3
|
|
|
5
4
|
describe('CLI package module', () => {
|
|
6
5
|
it('findPackageVersion finds the current package version', async () => {
|
|
@@ -48,9 +47,18 @@ describe('CLI package module', () => {
|
|
|
48
47
|
});
|
|
49
48
|
|
|
50
49
|
it('getPiralPackage returns piral package', () => {
|
|
51
|
-
let result = getPiralPackage(
|
|
50
|
+
let result = getPiralPackage(
|
|
51
|
+
'app',
|
|
52
|
+
{ language: 'ts', packageName: 'piral-base', reactRouterVersion: 5, reactVersion: 17 },
|
|
53
|
+
'1.0.0',
|
|
54
|
+
'webpack',
|
|
55
|
+
);
|
|
52
56
|
expect(result.devDependencies['piral-cli-webpack']).toEqual('1.0.0');
|
|
53
|
-
result = getPiralPackage(
|
|
57
|
+
result = getPiralPackage(
|
|
58
|
+
'app',
|
|
59
|
+
{ language: 'ts', packageName: 'piral-base', reactRouterVersion: 5, reactVersion: 17 },
|
|
60
|
+
'1.0.0',
|
|
61
|
+
);
|
|
54
62
|
expect(result.devDependencies).not.toContain('piral-cli-webpack');
|
|
55
63
|
});
|
|
56
64
|
|
package/src/common/package.ts
CHANGED
|
@@ -2,18 +2,17 @@ import { resolve, join, extname, basename, dirname, relative } from 'path';
|
|
|
2
2
|
import { log, fail } from './log';
|
|
3
3
|
import { cliVersion } from './info';
|
|
4
4
|
import { unpackTarball } from './archive';
|
|
5
|
-
import { getDependencies, getDevDependencies } from './language';
|
|
6
|
-
import {
|
|
5
|
+
import { getDependencies, getDependencyPackages, getDevDependencies, getDevDependencyPackages } from './language';
|
|
6
|
+
import { ForceOverwrite } from './enums';
|
|
7
7
|
import { checkAppShellCompatibility } from './compatibility';
|
|
8
8
|
import { deepMerge } from './merge';
|
|
9
|
-
import { applyTemplate } from './template';
|
|
10
9
|
import { readImportmap } from './importmap';
|
|
11
10
|
import { filesTar, filesOnceTar, declarationEntryExtensions, bundlerNames } from './constants';
|
|
12
11
|
import { getHash, checkIsDirectory, matchFiles } from './io';
|
|
13
12
|
import { readJson, copy, updateExistingJson, findFile, checkExists } from './io';
|
|
14
13
|
import { isGitPackage, isLocalPackage, makeGitUrl, makeFilePath } from './npm';
|
|
15
14
|
import { makePiletExternals, makeExternals, findPackageRoot } from './npm';
|
|
16
|
-
import { Framework, FileInfo, PiletsInfo, TemplateFileLocation, PackageData } from '../types';
|
|
15
|
+
import { SourceLanguage, Framework, FileInfo, PiletsInfo, TemplateFileLocation, PackageData } from '../types';
|
|
17
16
|
|
|
18
17
|
function appendBundler(devDependencies: Record<string, string>, bundler: string, version: string) {
|
|
19
18
|
if (bundler && bundler !== 'none') {
|
|
@@ -49,7 +48,6 @@ function getDependencyVersion(
|
|
|
49
48
|
interface FileDescriptor {
|
|
50
49
|
sourcePath: string;
|
|
51
50
|
targetPath: string;
|
|
52
|
-
template: boolean;
|
|
53
51
|
}
|
|
54
52
|
|
|
55
53
|
const globPatternStartIndicators = ['*', '?', '[', '!(', '?(', '+(', '@('];
|
|
@@ -59,12 +57,7 @@ async function getMatchingFiles(
|
|
|
59
57
|
target: string,
|
|
60
58
|
file: string | TemplateFileLocation,
|
|
61
59
|
): Promise<Array<FileDescriptor>> {
|
|
62
|
-
const {
|
|
63
|
-
from,
|
|
64
|
-
to,
|
|
65
|
-
deep = true,
|
|
66
|
-
template = false,
|
|
67
|
-
} = typeof file === 'string' ? { from: file, to: file, deep: true } : file;
|
|
60
|
+
const { from, to, deep = true } = typeof file === 'string' ? { from: file, to: file, deep: true } : file;
|
|
68
61
|
const sourcePath = resolve(source, from);
|
|
69
62
|
const targetPath = resolve(target, to);
|
|
70
63
|
const isDirectory = await checkIsDirectory(sourcePath);
|
|
@@ -76,7 +69,6 @@ async function getMatchingFiles(
|
|
|
76
69
|
return files.map((file) => ({
|
|
77
70
|
sourcePath: file,
|
|
78
71
|
targetPath: resolve(targetPath, relative(sourcePath, file)),
|
|
79
|
-
template,
|
|
80
72
|
}));
|
|
81
73
|
} else if (globPatternStartIndicators.some((m) => from.indexOf(m) !== -1)) {
|
|
82
74
|
log('generalDebug_0003', `Matching using glob "${sourcePath}".`);
|
|
@@ -98,7 +90,6 @@ async function getMatchingFiles(
|
|
|
98
90
|
return files.map((file) => ({
|
|
99
91
|
sourcePath: file,
|
|
100
92
|
targetPath: resolve(tarRoot, relative(relRoot, file)),
|
|
101
|
-
template,
|
|
102
93
|
}));
|
|
103
94
|
}
|
|
104
95
|
|
|
@@ -108,7 +99,6 @@ async function getMatchingFiles(
|
|
|
108
99
|
{
|
|
109
100
|
sourcePath,
|
|
110
101
|
targetPath,
|
|
111
|
-
template,
|
|
112
102
|
},
|
|
113
103
|
];
|
|
114
104
|
}
|
|
@@ -155,23 +145,24 @@ export function readPiralPackage(root: string, name: string): Promise<PackageDat
|
|
|
155
145
|
return readJson(path, 'package.json');
|
|
156
146
|
}
|
|
157
147
|
|
|
158
|
-
export
|
|
159
|
-
|
|
160
|
-
language: SourceLanguage
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const
|
|
167
|
-
// take default dev packages only if not piral-base
|
|
168
|
-
const typings = framework === 'piral-base' ? {} : undefined;
|
|
148
|
+
export interface PiralPackageData {
|
|
149
|
+
packageName: Framework;
|
|
150
|
+
language: SourceLanguage;
|
|
151
|
+
reactVersion: number;
|
|
152
|
+
reactRouterVersion: number;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function getPiralPackage(app: string, data: PiralPackageData, version: string, bundler?: string) {
|
|
156
|
+
const framework = data.packageName;
|
|
169
157
|
const devDependencies = {
|
|
170
|
-
...getDevDependencies(
|
|
158
|
+
...getDevDependencies(
|
|
159
|
+
data.language,
|
|
160
|
+
getDevDependencyPackages(framework, data.reactVersion, data.reactRouterVersion),
|
|
161
|
+
),
|
|
171
162
|
'piral-cli': `${version}`,
|
|
172
163
|
};
|
|
173
164
|
const dependencies = {
|
|
174
|
-
...getDependencies(language,
|
|
165
|
+
...getDependencies(data.language, getDependencyPackages(framework, data.reactVersion, data.reactRouterVersion)),
|
|
175
166
|
};
|
|
176
167
|
|
|
177
168
|
appendBundler(devDependencies, bundler, version);
|
|
@@ -219,7 +210,6 @@ async function getAvailableFiles(
|
|
|
219
210
|
return files.map((file) => ({
|
|
220
211
|
sourcePath: file,
|
|
221
212
|
targetPath: resolve(root, relative(base, file)),
|
|
222
|
-
template: fileMap.find((m) => resolve(source, m.from) === file)?.template || false,
|
|
223
213
|
}));
|
|
224
214
|
}
|
|
225
215
|
|
|
@@ -249,17 +239,13 @@ async function copyFiles(
|
|
|
249
239
|
variables?: Record<string, string>,
|
|
250
240
|
) {
|
|
251
241
|
for (const subfile of subfiles) {
|
|
252
|
-
const { sourcePath, targetPath
|
|
242
|
+
const { sourcePath, targetPath } = subfile;
|
|
253
243
|
const exists = await checkExists(sourcePath);
|
|
254
244
|
|
|
255
245
|
if (exists) {
|
|
256
246
|
const overwrite = originalFiles.some((m) => m.path === targetPath && !m.changed);
|
|
257
247
|
const force = overwrite ? ForceOverwrite.yes : forceOverwrite;
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
if (written && template && variables) {
|
|
261
|
-
await applyTemplate(targetPath, variables);
|
|
262
|
-
}
|
|
248
|
+
await copy(sourcePath, targetPath, force);
|
|
263
249
|
} else {
|
|
264
250
|
fail('cannotFindFile_0046', sourcePath);
|
|
265
251
|
}
|