piral-cli 0.15.0-alpha.4257 → 0.15.0-alpha.4314
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/README.md +7 -5
- package/lib/apps/debug-pilet.js +2 -1
- package/lib/apps/debug-pilet.js.map +1 -1
- package/lib/apps/debug-piral.js +2 -1
- package/lib/apps/debug-piral.js.map +1 -1
- 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 +9 -8
- 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/http.d.ts +4 -2
- package/lib/common/http.js +25 -11
- package/lib/common/http.js.map +1 -1
- package/lib/common/interactive.js +10 -5
- package/lib/common/interactive.js.map +1 -1
- package/lib/common/language.d.ts +3 -13
- package/lib/common/language.js +52 -12
- package/lib/common/language.js.map +1 -1
- package/lib/common/log.d.ts +1 -0
- package/lib/common/log.js +9 -2
- package/lib/common/log.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/port.d.ts +1 -0
- package/lib/common/port.js +11 -1
- package/lib/common/port.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/helpers.d.ts +3 -5
- package/lib/helpers.js +3 -21
- package/lib/helpers.js.map +1 -1
- package/lib/messages.d.ts +83 -5
- package/lib/messages.js +95 -8
- package/lib/messages.js.map +1 -1
- package/lib/release.d.ts +1 -1
- package/lib/release.js +32 -5
- package/lib/release.js.map +1 -1
- package/lib/types/common.d.ts +1 -2
- package/lib/types/public.d.ts +2 -1
- package/package.json +3 -5
- package/src/apps/debug-pilet.ts +3 -1
- package/src/apps/debug-piral.ts +3 -1
- package/src/apps/new-pilet.test.ts +1 -2
- package/src/apps/new-pilet.ts +4 -4
- package/src/apps/new-piral.test.ts +1 -2
- package/src/apps/new-piral.ts +8 -12
- package/src/apps/publish-piral.ts +21 -10
- 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/http.ts +37 -14
- package/src/common/interactive.ts +12 -7
- package/src/common/language.ts +66 -11
- package/src/common/log.ts +9 -1
- 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/port.ts +10 -0
- 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 +93 -6
- package/src/release.ts +40 -6
- package/src/types/common.ts +1 -2
- package/src/types/public.ts +3 -1
- package/templates/piral-index.js.ejs +0 -16
|
@@ -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
package/src/common/http.ts
CHANGED
|
@@ -57,28 +57,35 @@ export function downloadFile(target: string, ca?: Buffer): Promise<Array<string>
|
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
export interface
|
|
60
|
+
export interface PostFormResult {
|
|
61
61
|
status: number;
|
|
62
62
|
success: boolean;
|
|
63
63
|
response?: object;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
export
|
|
66
|
+
export type FormDataObj = Record<string, string | [Buffer, string]>;
|
|
67
|
+
|
|
68
|
+
export function postForm(
|
|
67
69
|
target: string,
|
|
68
70
|
scheme: PiletPublishScheme,
|
|
69
71
|
key: string,
|
|
70
|
-
|
|
71
|
-
customFields: Record<string, string> = {},
|
|
72
|
+
formData: FormDataObj,
|
|
72
73
|
customHeaders: Record<string, string> = {},
|
|
73
74
|
ca?: Buffer,
|
|
74
75
|
interactive = false,
|
|
75
|
-
): Promise<
|
|
76
|
-
const form = new FormData();
|
|
76
|
+
): Promise<PostFormResult> {
|
|
77
77
|
const httpsAgent = ca ? new Agent({ ca }) : undefined;
|
|
78
|
+
const form = new FormData();
|
|
78
79
|
|
|
79
|
-
Object.keys(
|
|
80
|
+
Object.keys(formData).forEach((key) => {
|
|
81
|
+
const value = formData[key];
|
|
80
82
|
|
|
81
|
-
|
|
83
|
+
if (typeof value === 'string') {
|
|
84
|
+
form.append(key, value);
|
|
85
|
+
} else {
|
|
86
|
+
form.append(key, value[0], value[1]);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
82
89
|
|
|
83
90
|
const headers: Record<string, string> = {
|
|
84
91
|
...form.getHeaders(),
|
|
@@ -112,11 +119,13 @@ export function postFile(
|
|
|
112
119
|
maxBodyLength: Infinity,
|
|
113
120
|
})
|
|
114
121
|
.then(
|
|
115
|
-
(res) =>
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
122
|
+
(res) => {
|
|
123
|
+
return {
|
|
124
|
+
status: res.status,
|
|
125
|
+
success: true,
|
|
126
|
+
response: res.data,
|
|
127
|
+
};
|
|
128
|
+
},
|
|
120
129
|
(error) => {
|
|
121
130
|
if (error.response) {
|
|
122
131
|
// The request was made and the server responded with a status code
|
|
@@ -133,7 +142,7 @@ export function postFile(
|
|
|
133
142
|
);
|
|
134
143
|
|
|
135
144
|
return getTokenInteractively(interactiveAuth, httpsAgent).then(({ mode, token }) =>
|
|
136
|
-
|
|
145
|
+
postForm(target, mode, token, formData, customHeaders, ca, false),
|
|
137
146
|
);
|
|
138
147
|
}
|
|
139
148
|
}
|
|
@@ -178,3 +187,17 @@ export function postFile(
|
|
|
178
187
|
},
|
|
179
188
|
);
|
|
180
189
|
}
|
|
190
|
+
|
|
191
|
+
export function postFile(
|
|
192
|
+
target: string,
|
|
193
|
+
scheme: PiletPublishScheme,
|
|
194
|
+
key: string,
|
|
195
|
+
file: Buffer,
|
|
196
|
+
customFields: Record<string, string> = {},
|
|
197
|
+
customHeaders: Record<string, string> = {},
|
|
198
|
+
ca?: Buffer,
|
|
199
|
+
interactive = false,
|
|
200
|
+
): Promise<PostFormResult> {
|
|
201
|
+
const data: FormDataObj = { ...customFields, file: [file, 'pilet.tgz'] };
|
|
202
|
+
return postForm(target, scheme, key, data, customHeaders, ca, interactive);
|
|
203
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Agent } from 'https';
|
|
2
2
|
import { openBrowserAt } from './browser';
|
|
3
3
|
import { standardHeaders } from './info';
|
|
4
|
+
import { logSuspend } from './log';
|
|
4
5
|
import { axios, inquirer } from '../external';
|
|
5
6
|
import { PiletPublishScheme } from '../types';
|
|
6
7
|
|
|
@@ -35,6 +36,8 @@ const tokenRetrievers: Record<string, TokenResult> = {};
|
|
|
35
36
|
|
|
36
37
|
export function getTokenInteractively(url: string, httpsAgent: Agent): TokenResult {
|
|
37
38
|
if (!(url in tokenRetrievers)) {
|
|
39
|
+
const logResume = logSuspend();
|
|
40
|
+
|
|
38
41
|
tokenRetrievers[url] = axios.default
|
|
39
42
|
.post(
|
|
40
43
|
url,
|
|
@@ -53,19 +56,21 @@ export function getTokenInteractively(url: string, httpsAgent: Agent): TokenResu
|
|
|
53
56
|
)
|
|
54
57
|
.then((res) => {
|
|
55
58
|
const { loginUrl, callbackUrl, expires } = res.data;
|
|
56
|
-
|
|
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}).`);
|
|
57
64
|
console.log('===');
|
|
58
65
|
console.log(loginUrl);
|
|
59
66
|
console.log('===');
|
|
60
67
|
|
|
61
68
|
openBrowserAt(loginUrl);
|
|
62
69
|
|
|
63
|
-
return axios.default
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
};
|
|
68
|
-
});
|
|
70
|
+
return axios.default
|
|
71
|
+
.get(callbackUrl)
|
|
72
|
+
.then(({ data }) => ({ ...data }))
|
|
73
|
+
.finally(logResume);
|
|
69
74
|
});
|
|
70
75
|
}
|
|
71
76
|
|
package/src/common/language.ts
CHANGED
|
@@ -1,45 +1,100 @@
|
|
|
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 reactRouter6Typings = {
|
|
40
|
+
'@types/react-router': '^6',
|
|
41
|
+
'@types/react-router-dom': '^6',
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const defaultDeps = {};
|
|
45
|
+
|
|
46
|
+
const defaultTypings = {
|
|
47
|
+
'@types/react': '*',
|
|
48
|
+
'@types/react-dom': '*',
|
|
49
|
+
'@types/react-router': '*',
|
|
50
|
+
'@types/react-router-dom': '*',
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export function getDependencyPackages(framework: Framework, reactVersion: number, reactRouterVersion: number) {
|
|
54
|
+
// take default packages only if piral-core
|
|
55
|
+
return framework !== 'piral-core'
|
|
56
|
+
? {}
|
|
57
|
+
: {
|
|
58
|
+
...(reactVersion < 18 ? react17Deps : react18Deps),
|
|
59
|
+
...(reactRouterVersion < 6 ? reactRouter5Deps : reactRouter6Deps),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function getDevDependencyPackages(framework: Framework, reactVersion: number, reactRouterVersion: number) {
|
|
64
|
+
// take default dev packages only if not piral-base
|
|
65
|
+
return framework === 'piral-base'
|
|
66
|
+
? {}
|
|
67
|
+
: {
|
|
68
|
+
...(reactVersion < 18 ? react17Typings : react18Typings),
|
|
69
|
+
...(reactRouterVersion < 6 ? reactRouter5Typings : reactRouter6Typings),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function getDependencies(language: SourceLanguage, packages: Record<string, string> = defaultDeps) {
|
|
19
74
|
switch (language) {
|
|
20
|
-
case
|
|
21
|
-
case
|
|
75
|
+
case 'js':
|
|
76
|
+
case 'ts':
|
|
22
77
|
return {
|
|
23
78
|
...packages,
|
|
24
79
|
};
|
|
25
80
|
default:
|
|
26
|
-
log('generalDebug_0003', 'Did not find a valid language.
|
|
81
|
+
log('generalDebug_0003', 'Did not find a valid language. Skipping "dependencies".');
|
|
27
82
|
return {};
|
|
28
83
|
}
|
|
29
84
|
}
|
|
30
85
|
|
|
31
|
-
export function getDevDependencies(language: SourceLanguage, typings: Record<string, string> =
|
|
86
|
+
export function getDevDependencies(language: SourceLanguage, typings: Record<string, string> = defaultTypings) {
|
|
32
87
|
switch (language) {
|
|
33
|
-
case
|
|
88
|
+
case 'ts':
|
|
34
89
|
return {
|
|
35
90
|
...typings,
|
|
36
91
|
'@types/node': 'latest',
|
|
37
92
|
typescript: 'latest',
|
|
38
93
|
};
|
|
39
|
-
case
|
|
94
|
+
case 'js':
|
|
40
95
|
return {};
|
|
41
96
|
default:
|
|
42
|
-
log('generalDebug_0003', 'Did not find a valid language.
|
|
97
|
+
log('generalDebug_0003', 'Did not find a valid language. Skipping "devDependencies".');
|
|
43
98
|
return {};
|
|
44
99
|
}
|
|
45
100
|
}
|
package/src/common/log.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { LogLevels, QuickMessage } from '../types';
|
|
|
8
8
|
|
|
9
9
|
type Messages = typeof messages;
|
|
10
10
|
type MessageTypes = keyof Messages;
|
|
11
|
+
let currentProgress: string = undefined;
|
|
11
12
|
|
|
12
13
|
const logger = (() => {
|
|
13
14
|
try {
|
|
@@ -92,7 +93,8 @@ export function logFail(message: string, ...args: Array<string | number | boolea
|
|
|
92
93
|
}
|
|
93
94
|
|
|
94
95
|
export function progress(message: string, ...args: Array<string | number | boolean>) {
|
|
95
|
-
|
|
96
|
+
currentProgress = format(message, ...args)
|
|
97
|
+
logger.progress(currentProgress);
|
|
96
98
|
}
|
|
97
99
|
|
|
98
100
|
export function logReset() {
|
|
@@ -100,6 +102,12 @@ export function logReset() {
|
|
|
100
102
|
logger.stopSpinner();
|
|
101
103
|
}
|
|
102
104
|
|
|
105
|
+
export function logSuspend() {
|
|
106
|
+
logReset();
|
|
107
|
+
|
|
108
|
+
return () => logger.progress(currentProgress);
|
|
109
|
+
}
|
|
110
|
+
|
|
103
111
|
export function fail<T extends MessageTypes>(type: T, ...args: Parameters<Messages[T]>): never {
|
|
104
112
|
const message = log(type, ...args);
|
|
105
113
|
const error = new Error(message);
|
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
|
}
|
package/src/common/port.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { log } from './log';
|
|
2
2
|
import { getPort } from '../external';
|
|
3
3
|
|
|
4
|
+
export async function getAvailablePort(defaultPort: number) {
|
|
5
|
+
const selectedPort = await getFreePort(defaultPort);
|
|
6
|
+
|
|
7
|
+
if (selectedPort !== defaultPort) {
|
|
8
|
+
log('portNotFree_0047', selectedPort, defaultPort);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return selectedPort;
|
|
12
|
+
}
|
|
13
|
+
|
|
4
14
|
export async function getFreePort(preferred?: number) {
|
|
5
15
|
log('generalDebug_0003', `Looking for a free port. Preferred port: ${preferred}`);
|
|
6
16
|
const port = await getPort(preferred && { port: preferred });
|
package/src/common/scaffold.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { join, dirname, resolve, basename, isAbsolute } from 'path';
|
|
2
2
|
import { installNpmPackage } from './npm';
|
|
3
|
-
import { ForceOverwrite
|
|
3
|
+
import { ForceOverwrite } from './enums';
|
|
4
4
|
import { createDirectory, createFileIfNotExists, updateExistingJson } from './io';
|
|
5
5
|
import { cliVersion, isWindows } from './info';
|
|
6
6
|
import { log, fail, getLogLevel } from './log';
|
|
7
|
-
import { Framework } from '../types';
|
|
7
|
+
import { Framework, SourceLanguage } from '../types';
|
|
8
8
|
|
|
9
9
|
interface TemplateFile {
|
|
10
10
|
path: string;
|
|
@@ -103,16 +103,6 @@ function getTemplatePackageName(type: 'piral' | 'pilet', template: string) {
|
|
|
103
103
|
return template;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
function getLanguageName(language: SourceLanguage) {
|
|
107
|
-
switch (language) {
|
|
108
|
-
case SourceLanguage.js:
|
|
109
|
-
return 'js';
|
|
110
|
-
case SourceLanguage.ts:
|
|
111
|
-
default:
|
|
112
|
-
return 'ts';
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
106
|
export function getPiralScaffoldData(
|
|
117
107
|
language: SourceLanguage,
|
|
118
108
|
root: string,
|
|
@@ -125,9 +115,11 @@ export function getPiralScaffoldData(
|
|
|
125
115
|
...variables,
|
|
126
116
|
root,
|
|
127
117
|
src,
|
|
128
|
-
language
|
|
118
|
+
language,
|
|
129
119
|
packageName,
|
|
130
|
-
|
|
120
|
+
reactVersion: parseInt(variables.reactVersion) || 17,
|
|
121
|
+
reactRouterVersion: parseInt(variables.reactRouterVersion) || 17,
|
|
122
|
+
} as const;
|
|
131
123
|
}
|
|
132
124
|
|
|
133
125
|
export async function scaffoldPiralSourceFiles(
|
|
@@ -157,9 +149,9 @@ export function getPiletScaffoldData(
|
|
|
157
149
|
...variables,
|
|
158
150
|
root,
|
|
159
151
|
src,
|
|
160
|
-
language
|
|
152
|
+
language,
|
|
161
153
|
sourceName,
|
|
162
|
-
};
|
|
154
|
+
} as const;
|
|
163
155
|
}
|
|
164
156
|
|
|
165
157
|
export async function scaffoldPiletSourceFiles(
|