piral-cli 0.15.0-beta.4830 → 0.15.1-beta.4903

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/add-piral-instance-pilet.d.ts +26 -0
  2. package/lib/apps/add-piral-instance-pilet.js +54 -0
  3. package/lib/apps/add-piral-instance-pilet.js.map +1 -0
  4. package/lib/apps/debug-pilet.js +1 -1
  5. package/lib/apps/debug-pilet.js.map +1 -1
  6. package/lib/apps/index.d.ts +2 -0
  7. package/lib/apps/index.js +2 -0
  8. package/lib/apps/index.js.map +1 -1
  9. package/lib/apps/new-pilet.js +1 -13
  10. package/lib/apps/new-pilet.js.map +1 -1
  11. package/lib/apps/pack-pilet.d.ts +9 -0
  12. package/lib/apps/pack-pilet.js +0 -9
  13. package/lib/apps/pack-pilet.js.map +1 -1
  14. package/lib/apps/remove-piral-instance-pilet.d.ts +17 -0
  15. package/lib/apps/remove-piral-instance-pilet.js +62 -0
  16. package/lib/apps/remove-piral-instance-pilet.js.map +1 -0
  17. package/lib/build/bundler-calls.js +2 -2
  18. package/lib/build/bundler-calls.js.map +1 -1
  19. package/lib/commands.js +78 -6
  20. package/lib/commands.js.map +1 -1
  21. package/lib/common/declaration.js +1 -1
  22. package/lib/common/declaration.js.map +1 -1
  23. package/lib/common/emulator.js +1 -1
  24. package/lib/common/emulator.js.map +1 -1
  25. package/lib/common/index.d.ts +1 -0
  26. package/lib/common/index.js +1 -0
  27. package/lib/common/index.js.map +1 -1
  28. package/lib/common/npm.d.ts +1 -1
  29. package/lib/common/package.d.ts +2 -0
  30. package/lib/common/package.js +19 -6
  31. package/lib/common/package.js.map +1 -1
  32. package/lib/common/shell.d.ts +2 -0
  33. package/lib/common/shell.js +33 -0
  34. package/lib/common/shell.js.map +1 -0
  35. package/lib/messages.d.ts +35 -10
  36. package/lib/messages.js +39 -11
  37. package/lib/messages.js.map +1 -1
  38. package/package.json +2 -2
  39. package/src/apps/add-piral-instance-pilet.ts +99 -0
  40. package/src/apps/build-piral.test.ts +11 -2
  41. package/src/apps/debug-pilet.ts +2 -1
  42. package/src/apps/index.ts +2 -0
  43. package/src/apps/new-pilet.ts +7 -21
  44. package/src/apps/pack-pilet.ts +8 -8
  45. package/src/apps/remove-piral-instance-pilet.ts +85 -0
  46. package/src/build/bundler-calls.ts +2 -2
  47. package/src/commands.ts +78 -6
  48. package/src/common/declaration.ts +2 -2
  49. package/src/common/emulator.ts +2 -2
  50. package/src/common/index.ts +1 -0
  51. package/src/common/npm.ts +1 -1
  52. package/src/common/package.ts +17 -5
  53. package/src/common/shell.ts +34 -0
  54. package/src/messages.ts +38 -10
package/src/commands.ts CHANGED
@@ -61,7 +61,7 @@ const allCommands: Array<ToolCommand<any>> = [
61
61
  return argv
62
62
  .positional('source', {
63
63
  type: 'string',
64
- describe: 'Sets the source root directory or index.html file for collecting all the information.',
64
+ describe: 'Sets the source Piral instance path for collecting all the information.',
65
65
  default: apps.debugPiralDefaults.entry,
66
66
  })
67
67
  .string('target')
@@ -121,7 +121,7 @@ const allCommands: Array<ToolCommand<any>> = [
121
121
  return argv
122
122
  .positional('source', {
123
123
  type: 'string',
124
- describe: 'Sets the source root directory or index.html file for collecting all the information.',
124
+ describe: 'Sets the source Piral instance path for collecting all the information.',
125
125
  default: apps.buildPiralDefaults.entry,
126
126
  })
127
127
  .string('target')
@@ -234,7 +234,7 @@ const allCommands: Array<ToolCommand<any>> = [
234
234
  return argv
235
235
  .positional('source', {
236
236
  type: 'string',
237
- describe: 'Sets the source root directory or index.html file for collecting all the information.',
237
+ describe: 'Sets the source Piral instance path for collecting all the information.',
238
238
  default: apps.declarationPiralDefaults.entry,
239
239
  })
240
240
  .string('target')
@@ -388,7 +388,7 @@ const allCommands: Array<ToolCommand<any>> = [
388
388
  return argv
389
389
  .positional('source', {
390
390
  type: 'string',
391
- describe: 'Sets the source root directory or index.html file for collecting all the information.',
391
+ describe: 'Sets the source Piral instance path for collecting all the information.',
392
392
  default: apps.validatePiralDefaults.entry,
393
393
  })
394
394
  .number('log-level')
@@ -489,7 +489,7 @@ const allCommands: Array<ToolCommand<any>> = [
489
489
  return argv
490
490
  .positional('source', {
491
491
  type: 'string',
492
- describe: 'Sets the source index.tsx file for collecting all the information.',
492
+ describe: 'Sets the source pilet path for collecting all the information.',
493
493
  default: apps.buildPiletDefaults.entry,
494
494
  })
495
495
  .string('target')
@@ -568,7 +568,7 @@ const allCommands: Array<ToolCommand<any>> = [
568
568
  return argv
569
569
  .positional('source', {
570
570
  type: 'string',
571
- describe: 'Sets the source package.json file for creating the package.',
571
+ describe: 'Sets the source pilet path for creating the package.',
572
572
  default: apps.packPiletDefaults.source,
573
573
  })
574
574
  .string('target')
@@ -807,6 +807,78 @@ const allCommands: Array<ToolCommand<any>> = [
807
807
  });
808
808
  },
809
809
  },
810
+ {
811
+ name: 'add-piral-instance-pilet',
812
+ alias: ['add-shell-pilet', 'install-shell-pilet', 'add-app-pilet', 'with-app-pilet'],
813
+ description: 'Adds another Piral instance to the available apps hosting the current pilet.',
814
+ arguments: ['[source]'],
815
+ flags(argv) {
816
+ return argv
817
+ .positional('app', {
818
+ type: 'string',
819
+ describe: 'Sets the name of the Piral instance to be added.',
820
+ default: apps.addPiralInstancePiletDefaults.app,
821
+ })
822
+ .positional('source', {
823
+ type: 'string',
824
+ describe: 'Sets the source pilet path where the Piral instance should be added.',
825
+ default: apps.addPiralInstancePiletDefaults.source,
826
+ })
827
+ .number('log-level')
828
+ .describe('log-level', 'Sets the log level to use (1-5).')
829
+ .default('log-level', apps.addPiralInstancePiletDefaults.logLevel)
830
+ .choices('npm-client', clientTypeKeys)
831
+ .describe('npm-client', 'Sets the npm client to be used for adding the Piral instance.')
832
+ .default('npm-client', apps.addPiralInstancePiletDefaults.npmClient)
833
+ .boolean('selected')
834
+ .describe('selected', 'Defines if the provided Piral instance should be selected initially.')
835
+ .default('selected', apps.addPiralInstancePiletDefaults.selected)
836
+ .string('base')
837
+ .default('base', process.cwd())
838
+ .describe('base', 'Sets the base directory. By default the current directory is used.');
839
+ },
840
+ run(args) {
841
+ return apps.addPiralInstancePilet(args.base as string, {
842
+ logLevel: args['log-level'] as LogLevels,
843
+ selected: args.selected as boolean,
844
+ npmClient: args['npm-client'] as NpmClientType,
845
+ app: args.app as string,
846
+ source: args.source as string,
847
+ });
848
+ },
849
+ },
850
+ {
851
+ name: 'remove-piral-instance-pilet',
852
+ alias: ['remove-shell-pilet', 'uninstall-shell-pilet', 'remove-app-pilet', 'without-app-pilet'],
853
+ description: 'Removes an existing Piral instance from the available apps hosting the current pilet.',
854
+ arguments: ['[source]'],
855
+ flags(argv) {
856
+ return argv
857
+ .positional('app', {
858
+ type: 'string',
859
+ describe: 'Sets the name of the Piral instance to be removed.',
860
+ default: apps.removePiralInstancePiletDefaults.app,
861
+ })
862
+ .positional('source', {
863
+ type: 'string',
864
+ describe: 'Sets the source pilet path where the Piral instance should be removed.',
865
+ default: apps.removePiralInstancePiletDefaults.source,
866
+ })
867
+ .number('log-level')
868
+ .describe('log-level', 'Sets the log level to use (1-5).')
869
+ .default('log-level', apps.removePiralInstancePiletDefaults.logLevel)
870
+ .string('base')
871
+ .default('base', process.cwd())
872
+ .describe('base', 'Sets the base directory. By default the current directory is used.');
873
+ },
874
+ run(args) {
875
+ return apps.removePiralInstancePilet(args.base as string, {
876
+ logLevel: args['log-level'] as LogLevels,
877
+ app: args.app as string,
878
+ source: args.source as string,
879
+ });
880
+ },
881
+ },
810
882
  ];
811
883
 
812
884
  class Commands implements ListCommands {
@@ -2,7 +2,7 @@ import { DeclOptions, generateDeclaration, createExcludePlugin, Logger } from 'd
2
2
  import { dirname, basename, resolve, extname } from 'path';
3
3
  import { progress, log, logWarn, logVerbose, logInfo } from './log';
4
4
  import { ForceOverwrite } from './enums';
5
- import { retrievePiralRoot, retrievePiletsInfo } from './package';
5
+ import { retrievePiralRoot, retrievePiletsInfo, flattenExternals } from './package';
6
6
  import { entryModuleExtensions, piralBaseRoot } from './constants';
7
7
  import { readText, getEntryFiles, matchFiles, createFileIfNotExists } from './io';
8
8
  import { getModulePath } from '../external';
@@ -167,7 +167,7 @@ export async function createPiralDeclaration(
167
167
  types: findDeclaredTypings(root),
168
168
  apis: findPiralBaseApi(root, framework),
169
169
  noModuleDeclaration: true,
170
- imports: externals.map(m => m.name),
170
+ imports: flattenExternals(externals),
171
171
  logLevel,
172
172
  logger: createLogger(),
173
173
  };
@@ -1,5 +1,5 @@
1
1
  import { join, resolve, relative } from 'path';
2
- import { findDependencyVersion, copyScaffoldingFiles, isValidDependency } from './package';
2
+ import { findDependencyVersion, copyScaffoldingFiles, isValidDependency, flattenExternals } from './package';
3
3
  import { createPiralStubIndexIfNotExists } from './template';
4
4
  import { filesTar, filesOnceTar } from './constants';
5
5
  import { cliVersion } from './info';
@@ -96,7 +96,7 @@ export async function createEmulatorSources(
96
96
  ...allDeps,
97
97
  ...externalDependencies,
98
98
  },
99
- sharedDependencies: externals.map(m => m.name),
99
+ sharedDependencies: flattenExternals(externals),
100
100
  repository: piralPkg.repository,
101
101
  bugs: piralPkg.bugs,
102
102
  author: piralPkg.author,
@@ -29,6 +29,7 @@ export * from './port';
29
29
  export * from './rules';
30
30
  export * from './scaffold';
31
31
  export * from './scripts';
32
+ export * from './shell';
32
33
  export * from './spec';
33
34
  export * from './template';
34
35
  export * from './url';
package/src/common/npm.ts CHANGED
@@ -394,7 +394,7 @@ export function combinePackageRef(name: string, version: string, type: PackageTy
394
394
  return name;
395
395
  }
396
396
 
397
- export async function getPackageName(root: string, name: string, type: PackageType) {
397
+ export async function getPackageName(root: string, name: string, type: PackageType): Promise<string> {
398
398
  switch (type) {
399
399
  case 'file':
400
400
  const originalPackageJson = await readJson(name, 'package.json');
@@ -532,6 +532,14 @@ export async function findPackageVersion(rootPath: string, packageName: string |
532
532
  return 'latest';
533
533
  }
534
534
 
535
+ function onlyUnique<T>(value: T, index: number, self: Array<T>) {
536
+ return self.indexOf(value) === index;
537
+ }
538
+
539
+ export function flattenExternals(dependencies: Array<SharedDependency>) {
540
+ return dependencies.map((m) => m.name).filter(onlyUnique);
541
+ }
542
+
535
543
  export async function retrieveExternals(root: string, packageInfo: any): Promise<Array<SharedDependency>> {
536
544
  const sharedDependencies = await readImportmap(root, packageInfo);
537
545
 
@@ -729,17 +737,21 @@ export function combinePiletExternals(
729
737
  return externals;
730
738
  }
731
739
 
732
- export async function retrievePiletData(target: string, app?: string) {
733
- const piletJson = await findFile(target, 'pilet.json');
734
- const proposedRoot = piletJson ? dirname(piletJson) : target;
740
+ export async function findPiletRoot(proposedRoot: string) {
735
741
  const packageJson = await findFile(proposedRoot, 'package.json');
736
742
 
737
743
  if (!packageJson) {
738
744
  fail('packageJsonMissing_0075');
739
745
  }
740
746
 
741
- const root = dirname(packageJson);
742
- const piletPackage = require(packageJson);
747
+ return dirname(packageJson);
748
+ }
749
+
750
+ export async function retrievePiletData(target: string, app?: string) {
751
+ const piletJson = await findFile(target, 'pilet.json');
752
+ const proposedRoot = piletJson ? dirname(piletJson) : target;
753
+ const root = await findPiletRoot(proposedRoot);
754
+ const piletPackage = require(resolve(root, 'package.json'));
743
755
  const piletDefinition = piletJson && require(piletJson);
744
756
  const appPackages = findPiralInstances(app && [app], piletPackage, piletDefinition, target);
745
757
  const apps: Array<AppDefinition> = [];
@@ -0,0 +1,34 @@
1
+ import { progress } from './log';
2
+ import {
3
+ combinePackageRef,
4
+ dissectPackageName,
5
+ getPackageName,
6
+ getPackageVersion,
7
+ installNpmPackage,
8
+ isLinkedPackage,
9
+ } from './npm';
10
+ import { NpmClientType } from '../types';
11
+
12
+ export async function installPiralInstance(
13
+ usedSource: string,
14
+ baseDir: string,
15
+ rootDir: string,
16
+ npmClient: NpmClientType,
17
+ ): Promise<[name: string, version: string]> {
18
+ const [sourceName, sourceVersion, hadVersion, type] = await dissectPackageName(baseDir, usedSource);
19
+ const isLocal = isLinkedPackage(sourceName, type, hadVersion);
20
+
21
+ if (!isLocal) {
22
+ const packageRef = combinePackageRef(sourceName, sourceVersion, type);
23
+
24
+ progress(`Installing npm package %s ...`, packageRef);
25
+ await installNpmPackage(npmClient, packageRef, rootDir, '--save-dev', '--save-exact');
26
+ } else {
27
+ progress(`Using locally available npm package %s ...`, sourceName);
28
+ }
29
+
30
+ const packageName = await getPackageName(rootDir, sourceName, type);
31
+ const packageVersion = getPackageVersion(hadVersion, sourceName, sourceVersion, type, rootDir);
32
+
33
+ return [packageName, packageVersion];
34
+ }
package/src/messages.ts CHANGED
@@ -777,7 +777,7 @@ export function invalidPiletTarget_0040(): QuickMessage {
777
777
  * contains an object with additional fields.
778
778
  *
779
779
  * @see
780
- * - [Pilet Package Definition](https://docs.piral.io/reference/documentation/metadata#pilets---package-definition)
780
+ * - [Pilet Package Definition](https://docs.piral.io/reference/documentation/C31-pilet-metadata)
781
781
  *
782
782
  * @example
783
783
  * Your pilet's package.json may look similar to the following snippet:
@@ -826,7 +826,7 @@ export function invalidPiletPackage_0041(): QuickMessage {
826
826
  * should contain (among others) a field `name` pointing to the Piral instance to use.
827
827
  *
828
828
  * @see
829
- * - [Pilet Package Definition](https://docs.piral.io/reference/documentation/metadata#pilets---package-definition)
829
+ * - [Pilet Package Definition](https://docs.piral.io/reference/documentation/C31-pilet-metadata)
830
830
  *
831
831
  * @example
832
832
  * If your Piral instance is called `my-piral` then the package.json may look similar to
@@ -866,7 +866,7 @@ export function invalidPiletPackage_0042(): QuickMessage {
866
866
  * - The Piral instance's name is invalid (e.g., due to a typo)
867
867
  *
868
868
  * @see
869
- * - [Pilet Package Definition](https://docs.piral.io/reference/documentation/metadata#pilets---package-definition)
869
+ * - [Pilet Package Definition](https://docs.piral.io/reference/documentation/C31-pilet-metadata)
870
870
  * - [Node Modules Loading](https://nodejs.org/api/modules.html#modules_loading_from_node_modules_folders)
871
871
  *
872
872
  * @example
@@ -1135,7 +1135,7 @@ export function gitLatestForUpgradeMissing_0051(): QuickMessage {
1135
1135
  * - Disk failures
1136
1136
  *
1137
1137
  * @see
1138
- * - [Piral Instance Package Definition](https://docs.piral.io/reference/documentation/metadata#piral-instance---package-definition)
1138
+ * - [Piral Instance Package Definition](https://docs.piral.io/reference/documentation/C21-piral-metadata)
1139
1139
  *
1140
1140
  * @example
1141
1141
  * The primary example hits when a dev dependency was specified that is otherwise not given.
@@ -1196,7 +1196,7 @@ export function cannotResolveVersion_0052(name: string): QuickMessage {
1196
1196
  * - Disk failures
1197
1197
  *
1198
1198
  * @see
1199
- * - [Piral Instance Package Definition](https://docs.piral.io/reference/documentation/metadata#piral-instance---package-definition)
1199
+ * - [Piral Instance Package Definition](https://docs.piral.io/reference/documentation/C21-piral-metadata)
1200
1200
  *
1201
1201
  * @example
1202
1202
  * The primary example hits when a dev dependency was specified that is otherwise not given.
@@ -2491,7 +2491,7 @@ export function invalidSchemaVersion_0171(schemaVersion: string, schemas: Array<
2491
2491
  * - [Webpack](https://webpack.js.org)
2492
2492
  * - [Parcel](https://parceljs.org)
2493
2493
  * - [esbuild](https://esbuild.github.io)
2494
- * - [Pluggable bundlers](https://docs.piral.io/reference/documentation/bundlers)
2494
+ * - [Pluggable bundlers](https://docs.piral.io/concepts/T02-bundlers)
2495
2495
  *
2496
2496
  * @example
2497
2497
  * Use the following command to make the parcel bundler available:
@@ -2523,7 +2523,7 @@ export function bundlerMissing_0172(bundlerName: string, installed: Array<string
2523
2523
  * - [Webpack](https://webpack.js.org)
2524
2524
  * - [Parcel](https://parceljs.org)
2525
2525
  * - [esbuild](https://esbuild.github.io)
2526
- * - [Pluggable bundlers](https://docs.piral.io/reference/documentation/bundlers)
2526
+ * - [Pluggable bundlers](https://docs.piral.io/concepts/T02-bundlers)
2527
2527
  *
2528
2528
  * @example
2529
2529
  * Use the following command to make the parcel bundler available:
@@ -2555,7 +2555,7 @@ export function defaultBundlerMissing_0173(): QuickMessage {
2555
2555
  * - [Webpack](https://webpack.js.org)
2556
2556
  * - [Parcel](https://parceljs.org)
2557
2557
  * - [esbuild](https://esbuild.github.io)
2558
- * - [Pluggable bundlers](https://docs.piral.io/reference/documentation/bundlers)
2558
+ * - [Pluggable bundlers](https://docs.piral.io/concepts/T02-bundlers)
2559
2559
  *
2560
2560
  * @example
2561
2561
  * Use the following command to make the parcel bundler available:
@@ -2588,7 +2588,7 @@ export function bundlingFailed_0174(error: string): QuickMessage {
2588
2588
  * dependent we recommend setting the bundler explicitly.
2589
2589
  *
2590
2590
  * @see
2591
- * - [Pluggable bundlers](https://docs.piral.io/reference/documentation/bundlers)
2591
+ * - [Pluggable bundlers](https://docs.piral.io/concepts/T02-bundlers)
2592
2592
  *
2593
2593
  * @example
2594
2594
  * Use the following command to explicitly choose the Parcel bundler:
@@ -2622,7 +2622,7 @@ export function bundlerUnspecified_0175(available: Array<string>): QuickMessage
2622
2622
  * choice (even if this could also be the default bundler) explicitly.
2623
2623
  *
2624
2624
  * @see
2625
- * - [Pluggable bundlers](https://docs.piral.io/reference/documentation/bundlers)
2625
+ * - [Pluggable bundlers](https://docs.piral.io/concepts/T02-bundlers)
2626
2626
  *
2627
2627
  * @example
2628
2628
  * Use the following command to install esbuild as a bundler with the npm client:
@@ -2635,6 +2635,34 @@ export function bundlerNotInstalled_0176(): QuickMessage {
2635
2635
  return [LogLevels.warning, '0176', `Installing default bundler since no bundler has been found.`];
2636
2636
  }
2637
2637
 
2638
+ /**
2639
+ * @kind Warning
2640
+ *
2641
+ * @summary
2642
+ * No pilet.json has been found.
2643
+ *
2644
+ * @abstract
2645
+ * For some functionality such as multi Piral instance support when debugging
2646
+ * a pilet, a special file called pilet.json is required. While this file is
2647
+ * optional in general, it must be available for certain tasks such as adding
2648
+ * or removing a Piral instance for debugging purposes.
2649
+ *
2650
+ * @see
2651
+ * - [Pluggable bundlers](https://docs.piral.io/concepts/T02-bundlers)
2652
+ *
2653
+ * @example
2654
+ * If no pilet.json is yet available you can create one. It should be adjacent to
2655
+ * the package.json of your pilet, even though different locations are also possible.
2656
+ * By default, the following content can be used for an empty file:
2657
+ *
2658
+ * ```json
2659
+ *
2660
+ * ```
2661
+ */
2662
+ export function piletJsonNotAvailable_0180(root: string): QuickMessage {
2663
+ return [LogLevels.warning, '0180', `No "pilet.json" was found for the pilet at "${root}".`];
2664
+ }
2665
+
2638
2666
  /**
2639
2667
  * @kind Warning
2640
2668
  *