piral-cli 0.14.20 → 0.14.21
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/build-pilet.d.ts +4 -0
- package/lib/apps/build-pilet.js +8 -6
- package/lib/apps/build-pilet.js.map +1 -1
- package/lib/apps/debug-pilet.d.ts +10 -0
- package/lib/apps/debug-pilet.js +15 -7
- package/lib/apps/debug-pilet.js.map +1 -1
- package/lib/apps/new-pilet.js +4 -3
- package/lib/apps/new-pilet.js.map +1 -1
- package/lib/build/bundler-calls.d.ts +1 -1
- package/lib/build/run-build-pilet.js.map +1 -1
- package/lib/build/run-build-piral.js.map +1 -1
- package/lib/build/run-debug-mono-piral.js +1 -1
- package/lib/build/run-debug-mono-piral.js.map +1 -1
- package/lib/build/run-debug-pilet.js +3 -5
- package/lib/build/run-debug-pilet.js.map +1 -1
- package/lib/build/run-debug-piral.js +1 -1
- package/lib/build/run-debug-piral.js.map +1 -1
- package/lib/commands.js +12 -0
- package/lib/commands.js.map +1 -1
- package/lib/common/clients/npm.js +10 -4
- package/lib/common/clients/npm.js.map +1 -1
- package/lib/common/clients/pnpm.js +10 -4
- package/lib/common/clients/pnpm.js.map +1 -1
- package/lib/common/clients/yarn.js +10 -4
- package/lib/common/clients/yarn.js.map +1 -1
- package/lib/common/package.d.ts +1 -0
- package/lib/common/package.js +2 -1
- package/lib/common/package.js.map +1 -1
- package/lib/common/scaffold.js.map +1 -1
- package/lib/external/index.js +6 -2
- package/lib/injectors/pilet.d.ts +2 -0
- package/lib/injectors/pilet.js +18 -14
- package/lib/injectors/pilet.js.map +1 -1
- package/lib/types/common.d.ts +1 -0
- package/lib/types/public.d.ts +2 -0
- package/package.json +2 -2
- package/src/apps/build-pilet.ts +15 -6
- package/src/apps/debug-pilet.ts +31 -6
- package/src/apps/new-pilet.ts +4 -3
- package/src/build/bundler-calls.ts +1 -1
- package/src/build/run-build-pilet.ts +1 -1
- package/src/build/run-build-piral.ts +1 -1
- package/src/build/run-debug-mono-piral.ts +2 -2
- package/src/build/run-debug-pilet.ts +5 -5
- package/src/build/run-debug-piral.ts +2 -2
- package/src/commands.ts +12 -0
- package/src/common/clients/npm.ts +12 -4
- package/src/common/clients/pnpm.ts +12 -4
- package/src/common/clients/yarn.ts +12 -4
- package/src/common/package.test.ts +2 -0
- package/src/common/package.ts +2 -0
- package/src/common/scaffold.ts +1 -0
- package/src/injectors/pilet.ts +22 -15
- package/src/types/common.ts +1 -0
- package/src/types/public.ts +2 -0
package/src/apps/new-pilet.ts
CHANGED
|
@@ -101,7 +101,7 @@ export const newPiletDefaults: NewPiletOptions = {
|
|
|
101
101
|
forceOverwrite: ForceOverwrite.no,
|
|
102
102
|
language: config.language,
|
|
103
103
|
install: true,
|
|
104
|
-
template:
|
|
104
|
+
template: undefined,
|
|
105
105
|
logLevel: LogLevels.info,
|
|
106
106
|
npmClient: config.npmClient,
|
|
107
107
|
bundlerName: 'none',
|
|
@@ -184,7 +184,7 @@ always-auth=true`,
|
|
|
184
184
|
|
|
185
185
|
const isEmulator = checkAppShellPackage(piralInfo);
|
|
186
186
|
|
|
187
|
-
const { preScaffold, postScaffold, files } = getPiletsInfo(piralInfo);
|
|
187
|
+
const { preScaffold, postScaffold, files, template: preSelectedTemplate } = getPiletsInfo(piralInfo);
|
|
188
188
|
|
|
189
189
|
if (preScaffold) {
|
|
190
190
|
progress(`Running preScaffold script ...`);
|
|
@@ -195,7 +195,8 @@ always-auth=true`,
|
|
|
195
195
|
progress(`Taking care of templating ...`);
|
|
196
196
|
|
|
197
197
|
const data = getPiletScaffoldData(language, root, packageName, variables);
|
|
198
|
-
|
|
198
|
+
const chosenTemplate = template || preSelectedTemplate || 'default';
|
|
199
|
+
await scaffoldPiletSourceFiles(chosenTemplate, registry, data, forceOverwrite);
|
|
199
200
|
|
|
200
201
|
if (isEmulator) {
|
|
201
202
|
// in the emulator case we get the files (and files_once) from the contained tarballs
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolve } from 'path';
|
|
2
2
|
import { fork, ChildProcess } from 'child_process';
|
|
3
|
-
import { Bundler, BundleDetails, BaseBundleParameters } from '../types';
|
|
3
|
+
import type { Bundler, BundleDetails, BaseBundleParameters } from '../types';
|
|
4
4
|
|
|
5
5
|
function getPath(name: string) {
|
|
6
6
|
return resolve(__dirname, '..', '..', 'lib', 'build', `run-${name}.js`);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PiletSchemaVersion, LogLevels, SharedDependency, PiletBuildHandler } from '../types';
|
|
2
1
|
import { setStandardEnvs } from '../common';
|
|
2
|
+
import type { PiletSchemaVersion, LogLevels, SharedDependency, PiletBuildHandler } from '../types';
|
|
3
3
|
|
|
4
4
|
let handler: PiletBuildHandler;
|
|
5
5
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { LogLevels, PiralBuildHandler } from '../types';
|
|
2
|
-
import { setStandardEnvs, progress, logReset } from '../common';
|
|
3
1
|
import { resolve } from 'path';
|
|
2
|
+
import { setStandardEnvs, progress, logReset } from '../common';
|
|
3
|
+
import type { LogLevels, PiralBuildHandler } from '../types';
|
|
4
4
|
|
|
5
5
|
let handler: PiralBuildHandler;
|
|
6
6
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { setStandardEnvs } from '../common';
|
|
1
2
|
import type {
|
|
2
3
|
PiletSchemaVersion,
|
|
3
4
|
LogLevels,
|
|
@@ -5,8 +6,6 @@ import type {
|
|
|
5
6
|
BundleHandlerResponse,
|
|
6
7
|
PiletBuildHandler,
|
|
7
8
|
} from '../types';
|
|
8
|
-
import { setStandardEnvs } from '../common';
|
|
9
|
-
import { resolve } from 'path';
|
|
10
9
|
|
|
11
10
|
let handler: PiletBuildHandler;
|
|
12
11
|
let bundler: BundleHandlerResponse;
|
|
@@ -15,6 +14,7 @@ function run(
|
|
|
15
14
|
root: string,
|
|
16
15
|
targetDir: string,
|
|
17
16
|
outDir: string,
|
|
17
|
+
outFile: string,
|
|
18
18
|
piral: string,
|
|
19
19
|
externals: Array<string>,
|
|
20
20
|
importmap: Array<SharedDependency>,
|
|
@@ -63,11 +63,11 @@ process.on('message', async (msg) => {
|
|
|
63
63
|
|
|
64
64
|
break;
|
|
65
65
|
case 'start':
|
|
66
|
-
const dist = resolve(root, 'dist');
|
|
67
66
|
bundler = await run(
|
|
68
67
|
root,
|
|
69
68
|
msg.targetDir,
|
|
70
|
-
|
|
69
|
+
msg.outDir,
|
|
70
|
+
msg.outFile,
|
|
71
71
|
msg.piral,
|
|
72
72
|
msg.externals,
|
|
73
73
|
msg.importmap,
|
|
@@ -100,7 +100,7 @@ process.on('message', async (msg) => {
|
|
|
100
100
|
|
|
101
101
|
process.send({
|
|
102
102
|
type: 'done',
|
|
103
|
-
outDir:
|
|
103
|
+
outDir: msg.outDir,
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { BundleHandlerResponse, LogLevels, PiralBuildHandler } from '../types';
|
|
2
|
-
import { setStandardEnvs } from '../common';
|
|
3
1
|
import { resolve } from 'path';
|
|
2
|
+
import { setStandardEnvs } from '../common';
|
|
3
|
+
import type { BundleHandlerResponse, LogLevels, PiralBuildHandler } from '../types';
|
|
4
4
|
|
|
5
5
|
let handler: PiralBuildHandler;
|
|
6
6
|
let bundler: BundleHandlerResponse;
|
package/src/commands.ts
CHANGED
|
@@ -400,6 +400,12 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
400
400
|
describe: 'Sets the source file containing the pilet root module.',
|
|
401
401
|
default: apps.debugPiletDefaults.entry,
|
|
402
402
|
})
|
|
403
|
+
.string('target')
|
|
404
|
+
.describe('target', 'Sets the target directory or file of bundling.')
|
|
405
|
+
.default('target', apps.debugPiletDefaults.target)
|
|
406
|
+
.string('public-url')
|
|
407
|
+
.describe('public-url', 'Sets the public URL (path) of the application.')
|
|
408
|
+
.default('public-url', apps.debugPiletDefaults.publicUrl)
|
|
403
409
|
.number('port')
|
|
404
410
|
.describe('port', 'Sets the port of the local development server.')
|
|
405
411
|
.default('port', apps.debugPiletDefaults.port)
|
|
@@ -437,6 +443,8 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
437
443
|
run(args) {
|
|
438
444
|
return apps.debugPilet(args.base as string, {
|
|
439
445
|
entry: args.source as string,
|
|
446
|
+
target: args.target as string,
|
|
447
|
+
publicUrl: args['public-url'] as string,
|
|
440
448
|
port: args.port as number,
|
|
441
449
|
hmr: args.hmr as boolean,
|
|
442
450
|
bundlerName: args.bundler as string,
|
|
@@ -469,6 +477,9 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
469
477
|
.string('target')
|
|
470
478
|
.describe('target', 'Sets the target file of bundling.')
|
|
471
479
|
.default('target', apps.buildPiletDefaults.target)
|
|
480
|
+
.string('public-url')
|
|
481
|
+
.describe('public-url', 'Sets the public URL (path) of the application.')
|
|
482
|
+
.default('public-url', apps.buildPiletDefaults.publicUrl)
|
|
472
483
|
.number('log-level')
|
|
473
484
|
.describe('log-level', 'Sets the log level to use (1-5).')
|
|
474
485
|
.default('log-level', apps.buildPiletDefaults.logLevel)
|
|
@@ -512,6 +523,7 @@ const allCommands: Array<ToolCommand<any>> = [
|
|
|
512
523
|
return apps.buildPilet(args.base as string, {
|
|
513
524
|
entry: args.source as string,
|
|
514
525
|
target: args.target as string,
|
|
526
|
+
publicUrl: args['public-url'] as string,
|
|
515
527
|
minify: args.minify as boolean,
|
|
516
528
|
contentHash: args['content-hash'] as boolean,
|
|
517
529
|
bundlerName: args.bundler as string,
|
|
@@ -24,10 +24,18 @@ export async function unpackPackage(packageRef: string, target = '.', ...flags:
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export async function installPackage(packageRef: string, target = '.', ...flags: Array<string>) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
try {
|
|
28
|
+
const ms = new MemoryStream();
|
|
29
|
+
await runNpmProcess(['install', packageRef, '--legacy-peer-deps', ...flags], target, ms);
|
|
30
|
+
log('generalDebug_0003', `npm install package result: ${ms.value}`);
|
|
31
|
+
return ms.value;
|
|
32
|
+
} catch (ex) {
|
|
33
|
+
log(
|
|
34
|
+
'generalError_0002',
|
|
35
|
+
`Could not install the package "${packageRef}" using npm. Make sure npm is correctly installed and accessible: ${ex}`,
|
|
36
|
+
);
|
|
37
|
+
throw ex;
|
|
38
|
+
}
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
export async function createPackage(target = '.', ...flags: Array<string>) {
|
|
@@ -29,8 +29,16 @@ export async function installDependencies(target = '.', ...flags: Array<string>)
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export async function installPackage(packageRef: string, target = '.', ...flags: Array<string>) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
try {
|
|
33
|
+
const ms = new MemoryStream();
|
|
34
|
+
await runPnpmProcess(['add', packageRef, ...convert(flags)], target, ms);
|
|
35
|
+
log('generalDebug_0003', `Pnpm install package result: ${ms.value}`);
|
|
36
|
+
return ms.value;
|
|
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;
|
|
43
|
+
}
|
|
36
44
|
}
|
|
@@ -33,8 +33,16 @@ export async function installDependencies(target = '.', ...flags: Array<string>)
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export async function installPackage(packageRef: string, target = '.', ...flags: Array<string>) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
try {
|
|
37
|
+
const ms = new MemoryStream();
|
|
38
|
+
await runYarnProcess(['add', packageRef, ...convert(flags)], target, ms);
|
|
39
|
+
log('generalDebug_0003', `Yarn install package result: ${ms.value}`);
|
|
40
|
+
return ms.value;
|
|
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;
|
|
47
|
+
}
|
|
40
48
|
}
|
|
@@ -29,6 +29,7 @@ describe('CLI package module', () => {
|
|
|
29
29
|
it('getPiletsInfo returns pilets information about provided piralInfo', () => {
|
|
30
30
|
const emptyPiletsInfo = {
|
|
31
31
|
files: [],
|
|
32
|
+
template: 'default',
|
|
32
33
|
externals: [],
|
|
33
34
|
scripts: {},
|
|
34
35
|
validators: {},
|
|
@@ -45,6 +46,7 @@ describe('CLI package module', () => {
|
|
|
45
46
|
const piralInfo = {
|
|
46
47
|
pilets: {
|
|
47
48
|
files: ['foo.tgz', 'foo2.tgz'],
|
|
49
|
+
template: 'default',
|
|
48
50
|
externals: [],
|
|
49
51
|
scripts: {},
|
|
50
52
|
validators: {},
|
package/src/common/package.ts
CHANGED
|
@@ -347,6 +347,7 @@ export function getPiletsInfo(piralInfo: any): PiletsInfo {
|
|
|
347
347
|
files = [],
|
|
348
348
|
externals = [],
|
|
349
349
|
scripts = {},
|
|
350
|
+
template = 'default',
|
|
350
351
|
validators = {},
|
|
351
352
|
devDependencies = {},
|
|
352
353
|
preScaffold = '',
|
|
@@ -360,6 +361,7 @@ export function getPiletsInfo(piralInfo: any): PiletsInfo {
|
|
|
360
361
|
files,
|
|
361
362
|
externals,
|
|
362
363
|
scripts,
|
|
364
|
+
template,
|
|
363
365
|
validators,
|
|
364
366
|
devDependencies,
|
|
365
367
|
preScaffold,
|
package/src/common/scaffold.ts
CHANGED
package/src/injectors/pilet.ts
CHANGED
|
@@ -19,6 +19,7 @@ interface Pilet {
|
|
|
19
19
|
|
|
20
20
|
export interface PiletInjectorConfig extends KrasInjectorConfig {
|
|
21
21
|
pilets: Array<Pilet>;
|
|
22
|
+
publicUrl: string;
|
|
22
23
|
meta: string;
|
|
23
24
|
api: string;
|
|
24
25
|
app: string;
|
|
@@ -74,6 +75,7 @@ async function loadFeed(feed: string) {
|
|
|
74
75
|
export default class PiletInjector implements KrasInjector {
|
|
75
76
|
public config: PiletInjectorConfig;
|
|
76
77
|
private piletApi: string;
|
|
78
|
+
private indexPath: string;
|
|
77
79
|
|
|
78
80
|
constructor(options: PiletInjectorConfig, config: KrasConfiguration, core: EventEmitter) {
|
|
79
81
|
this.config = options;
|
|
@@ -82,7 +84,8 @@ export default class PiletInjector implements KrasInjector {
|
|
|
82
84
|
? options.api
|
|
83
85
|
: `${config.ssl ? 'https' : 'http'}://${host}:${config.port}${options.api}`;
|
|
84
86
|
|
|
85
|
-
const { pilets, api } = options;
|
|
87
|
+
const { pilets, api, publicUrl } = options;
|
|
88
|
+
this.indexPath = `${publicUrl}index.html`;
|
|
86
89
|
const cbs = {};
|
|
87
90
|
|
|
88
91
|
core.on('user-connected', (e) => {
|
|
@@ -210,26 +213,30 @@ export default class PiletInjector implements KrasInjector {
|
|
|
210
213
|
}
|
|
211
214
|
|
|
212
215
|
handle(req: KrasRequest): KrasResponse {
|
|
213
|
-
const { app, api } = this.config;
|
|
214
|
-
const path = req.url.substring(1).split('?')[0];
|
|
216
|
+
const { app, api, publicUrl } = this.config;
|
|
215
217
|
|
|
216
218
|
if (!req.target) {
|
|
217
|
-
|
|
219
|
+
if (req.url.startsWith(publicUrl)) {
|
|
220
|
+
const path = req.url.substring(publicUrl.length).split('?')[0];
|
|
221
|
+
const target = join(app, path);
|
|
218
222
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
223
|
+
if (existsSync(target) && statSync(target).isFile()) {
|
|
224
|
+
if (req.url === this.indexPath) {
|
|
225
|
+
return this.sendIndexFile(target, req.url);
|
|
226
|
+
} else {
|
|
227
|
+
return this.sendFile(target, req.url);
|
|
228
|
+
}
|
|
229
|
+
} else if (req.url !== this.indexPath) {
|
|
230
|
+
return this.handle({
|
|
231
|
+
...req,
|
|
232
|
+
url: this.indexPath,
|
|
233
|
+
});
|
|
222
234
|
}
|
|
223
|
-
return this.sendFile(target, req.url);
|
|
224
|
-
} else if (req.url !== '/index.html') {
|
|
225
|
-
return this.handle({
|
|
226
|
-
...req,
|
|
227
|
-
url: '/index.html',
|
|
228
|
-
});
|
|
229
|
-
} else {
|
|
230
|
-
return undefined;
|
|
231
235
|
}
|
|
236
|
+
|
|
237
|
+
return undefined;
|
|
232
238
|
} else if (req.target === api) {
|
|
239
|
+
const path = req.url.substring(1).split('?')[0];
|
|
233
240
|
return this.sendResponse(path, req.url);
|
|
234
241
|
}
|
|
235
242
|
}
|
package/src/types/common.ts
CHANGED
package/src/types/public.ts
CHANGED
|
@@ -103,6 +103,8 @@ export interface DebugPiletParameters extends BaseBundleParameters {
|
|
|
103
103
|
externals: Array<string>;
|
|
104
104
|
importmap: Array<SharedDependency>;
|
|
105
105
|
targetDir: string;
|
|
106
|
+
outFile: string;
|
|
107
|
+
outDir: string;
|
|
106
108
|
entryModule: string;
|
|
107
109
|
logLevel: LogLevels;
|
|
108
110
|
version: PiletSchemaVersion;
|