piral-cli 0.14.20-beta.4067 → 0.14.21-beta.4078

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.
Files changed (54) hide show
  1. package/lib/apps/build-pilet.d.ts +4 -0
  2. package/lib/apps/build-pilet.js +8 -6
  3. package/lib/apps/build-pilet.js.map +1 -1
  4. package/lib/apps/debug-pilet.d.ts +10 -0
  5. package/lib/apps/debug-pilet.js +15 -7
  6. package/lib/apps/debug-pilet.js.map +1 -1
  7. package/lib/apps/new-pilet.js +4 -3
  8. package/lib/apps/new-pilet.js.map +1 -1
  9. package/lib/build/bundler-calls.d.ts +1 -1
  10. package/lib/build/run-build-pilet.js.map +1 -1
  11. package/lib/build/run-build-piral.js.map +1 -1
  12. package/lib/build/run-debug-mono-piral.js +1 -1
  13. package/lib/build/run-debug-mono-piral.js.map +1 -1
  14. package/lib/build/run-debug-pilet.js +3 -5
  15. package/lib/build/run-debug-pilet.js.map +1 -1
  16. package/lib/build/run-debug-piral.js +1 -1
  17. package/lib/build/run-debug-piral.js.map +1 -1
  18. package/lib/commands.js +12 -0
  19. package/lib/commands.js.map +1 -1
  20. package/lib/common/clients/npm.js +10 -4
  21. package/lib/common/clients/npm.js.map +1 -1
  22. package/lib/common/clients/pnpm.js +10 -4
  23. package/lib/common/clients/pnpm.js.map +1 -1
  24. package/lib/common/clients/yarn.js +10 -4
  25. package/lib/common/clients/yarn.js.map +1 -1
  26. package/lib/common/package.d.ts +1 -0
  27. package/lib/common/package.js +2 -1
  28. package/lib/common/package.js.map +1 -1
  29. package/lib/common/scaffold.js.map +1 -1
  30. package/lib/injectors/pilet.d.ts +2 -0
  31. package/lib/injectors/pilet.js +18 -14
  32. package/lib/injectors/pilet.js.map +1 -1
  33. package/lib/types/common.d.ts +1 -0
  34. package/lib/types/public.d.ts +2 -0
  35. package/package.json +2 -2
  36. package/src/apps/build-pilet.ts +15 -6
  37. package/src/apps/debug-pilet.ts +31 -6
  38. package/src/apps/new-pilet.ts +4 -3
  39. package/src/build/bundler-calls.ts +1 -1
  40. package/src/build/run-build-pilet.ts +1 -1
  41. package/src/build/run-build-piral.ts +1 -1
  42. package/src/build/run-debug-mono-piral.ts +2 -2
  43. package/src/build/run-debug-pilet.ts +5 -5
  44. package/src/build/run-debug-piral.ts +2 -2
  45. package/src/commands.ts +12 -0
  46. package/src/common/clients/npm.ts +12 -4
  47. package/src/common/clients/pnpm.ts +12 -4
  48. package/src/common/clients/yarn.ts +12 -4
  49. package/src/common/package.test.ts +2 -0
  50. package/src/common/package.ts +2 -0
  51. package/src/common/scaffold.ts +1 -0
  52. package/src/injectors/pilet.ts +22 -15
  53. package/src/types/common.ts +1 -0
  54. package/src/types/public.ts +2 -0
@@ -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,5 +1,5 @@
1
- import type { PiralBuildHandler, LogLevels } from '../types';
2
1
  import { setStandardEnvs } from '../common';
2
+ import type { PiralBuildHandler, LogLevels } from '../types';
3
3
 
4
4
  let handler: PiralBuildHandler;
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
- dist,
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: dist,
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
- const ms = new MemoryStream();
28
- await runNpmProcess(['install', packageRef, '--legacy-peer-deps', ...flags], target, ms);
29
- log('generalDebug_0003', `npm install package result: ${ms.value}`);
30
- return ms.value;
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
- const ms = new MemoryStream();
33
- await runPnpmProcess(['add', packageRef, ...convert(flags)], target, ms);
34
- log('generalDebug_0003', `Pnpm install package result: ${ms.value}`);
35
- return ms.value;
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
- const ms = new MemoryStream();
37
- await runYarnProcess(['add', packageRef, ...convert(flags)], target, ms);
38
- log('generalDebug_0003', `Yarn install package result: ${ms.value}`);
39
- return ms.value;
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: {},
@@ -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,
@@ -38,6 +38,7 @@ async function getTemplateFiles(
38
38
  } else {
39
39
  await installPackage(templatePackageName, __dirname, '--registry', registry);
40
40
  }
41
+
41
42
  const templateRunner = getTemplatePackage(templatePackageName);
42
43
 
43
44
  if (typeof templateRunner === 'function') {
@@ -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
- const target = join(app, path);
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
- if (existsSync(target) && statSync(target).isFile()) {
220
- if (req.url === '/index.html') {
221
- return this.sendIndexFile(target, req.url);
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
  }
@@ -55,6 +55,7 @@ export interface TemplateFileLocation {
55
55
 
56
56
  export interface PiletsInfo {
57
57
  files: Array<string | TemplateFileLocation>;
58
+ template: string;
58
59
  externals: Array<string>;
59
60
  devDependencies: Record<string, string | true>;
60
61
  scripts: Record<string, string>;
@@ -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;