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.
Files changed (94) hide show
  1. package/lib/apps/new-pilet.d.ts +2 -2
  2. package/lib/apps/new-pilet.js +3 -3
  3. package/lib/apps/new-pilet.js.map +1 -1
  4. package/lib/apps/new-piral.d.ts +2 -2
  5. package/lib/apps/new-piral.js +6 -5
  6. package/lib/apps/new-piral.js.map +1 -1
  7. package/lib/apps/publish-piral.d.ts +2 -2
  8. package/lib/apps/publish-piral.js +8 -7
  9. package/lib/apps/publish-piral.js.map +1 -1
  10. package/lib/apps/upgrade-pilet.js +3 -3
  11. package/lib/apps/upgrade-pilet.js.map +1 -1
  12. package/lib/apps/upgrade-piral.js +2 -2
  13. package/lib/apps/upgrade-piral.js.map +1 -1
  14. package/lib/commands.js +8 -8
  15. package/lib/commands.js.map +1 -1
  16. package/lib/common/clients/index.d.ts +3 -1
  17. package/lib/common/clients/index.js +3 -1
  18. package/lib/common/clients/index.js.map +1 -1
  19. package/lib/common/clients/npm.d.ts +1 -0
  20. package/lib/common/clients/npm.js +7 -1
  21. package/lib/common/clients/npm.js.map +1 -1
  22. package/lib/common/clients/pnp.d.ts +6 -0
  23. package/lib/common/clients/pnp.js +95 -0
  24. package/lib/common/clients/pnp.js.map +1 -0
  25. package/lib/common/clients/yarn.js +3 -3
  26. package/lib/common/clients/yarn.js.map +1 -1
  27. package/lib/common/config.d.ts +1 -2
  28. package/lib/common/config.js +1 -2
  29. package/lib/common/config.js.map +1 -1
  30. package/lib/common/emulator.js +1 -1
  31. package/lib/common/emulator.js.map +1 -1
  32. package/lib/common/enums.d.ts +0 -4
  33. package/lib/common/enums.js +1 -6
  34. package/lib/common/enums.js.map +1 -1
  35. package/lib/common/interactive.js +4 -1
  36. package/lib/common/interactive.js.map +1 -1
  37. package/lib/common/language.d.ts +3 -13
  38. package/lib/common/language.js +46 -12
  39. package/lib/common/language.js.map +1 -1
  40. package/lib/common/npm.d.ts +1 -1
  41. package/lib/common/npm.js +13 -5
  42. package/lib/common/npm.js.map +1 -1
  43. package/lib/common/package.d.ts +9 -3
  44. package/lib/common/package.js +11 -25
  45. package/lib/common/package.js.map +1 -1
  46. package/lib/common/scaffold.d.ts +12 -10
  47. package/lib/common/scaffold.js +6 -12
  48. package/lib/common/scaffold.js.map +1 -1
  49. package/lib/common/template.d.ts +1 -3
  50. package/lib/common/template.js +21 -47
  51. package/lib/common/template.js.map +1 -1
  52. package/lib/external/index.js +79 -79
  53. package/lib/helpers.d.ts +3 -5
  54. package/lib/helpers.js +3 -21
  55. package/lib/helpers.js.map +1 -1
  56. package/lib/injectors/pilet-injector.d.ts +1 -0
  57. package/lib/injectors/piral-injector.d.ts +1 -0
  58. package/lib/messages.d.ts +11 -11
  59. package/lib/messages.js +14 -14
  60. package/lib/messages.js.map +1 -1
  61. package/lib/release.js +1 -1
  62. package/lib/release.js.map +1 -1
  63. package/lib/types/common.d.ts +0 -1
  64. package/lib/types/public.d.ts +2 -1
  65. package/package.json +3 -5
  66. package/src/apps/new-pilet.test.ts +9 -6
  67. package/src/apps/new-pilet.ts +4 -4
  68. package/src/apps/new-piral.test.ts +3 -6
  69. package/src/apps/new-piral.ts +8 -12
  70. package/src/apps/publish-piral.ts +20 -9
  71. package/src/apps/upgrade-pilet.ts +3 -3
  72. package/src/apps/upgrade-piral.ts +2 -1
  73. package/src/commands.ts +9 -10
  74. package/src/common/clients/index.ts +3 -1
  75. package/src/common/clients/npm.ts +4 -0
  76. package/src/common/clients/pnp.ts +77 -0
  77. package/src/common/clients/yarn.ts +3 -3
  78. package/src/common/config.ts +2 -3
  79. package/src/common/emulator.ts +2 -2
  80. package/src/common/enums.ts +0 -5
  81. package/src/common/interactive.ts +5 -1
  82. package/src/common/language.ts +59 -11
  83. package/src/common/npm.ts +21 -6
  84. package/src/common/package.test.ts +11 -3
  85. package/src/common/package.ts +20 -34
  86. package/src/common/scaffold.ts +8 -16
  87. package/src/common/template.ts +19 -40
  88. package/src/helpers.test.ts +2 -22
  89. package/src/helpers.ts +4 -24
  90. package/src/messages.ts +14 -14
  91. package/src/release.ts +1 -1
  92. package/src/types/common.ts +0 -1
  93. package/src/types/public.ts +3 -1
  94. package/templates/piral-index.js.ejs +0 -16
@@ -1,10 +1,10 @@
1
1
  import { join, dirname, resolve, basename, isAbsolute } from 'path';
2
2
  import { installNpmPackage } from './npm';
3
- import { ForceOverwrite, SourceLanguage } from './enums';
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: getLanguageName(language),
118
+ language,
129
119
  packageName,
130
- };
120
+ reactVersion: parseInt(variables.reactVersion) || 18,
121
+ reactRouterVersion: parseInt(variables.reactRouterVersion) || 5,
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: getLanguageName(language),
152
+ language,
161
153
  sourceName,
162
- };
154
+ } as const;
163
155
  }
164
156
 
165
157
  export async function scaffoldPiletSourceFiles(
@@ -1,53 +1,32 @@
1
- import { renderFile } from 'ejs';
2
- import { writeFile } from 'fs';
3
- import { resolve } from 'path';
4
- import { log } from './log';
5
1
  import { ForceOverwrite } from './enums';
6
2
  import { createFileIfNotExists } from './io';
7
3
 
8
- export async function applyTemplate(file: string, data: Record<string, string>) {
9
- const content = await new Promise<string>((resolve, reject) => {
10
- log('generalDebug_0003', `Filling template in "${file}".`);
11
- renderFile(file, data, (err, str) => {
12
- if (err) {
13
- reject(err);
14
- } else {
15
- resolve(str);
16
- }
17
- });
18
- });
19
- await new Promise<void>((resolve, reject) => {
20
- writeFile(file, content, 'utf8', (err) => {
21
- if (err) {
22
- reject(err);
23
- } else {
24
- resolve();
25
- }
26
- });
27
- });
28
- }
4
+ function fillTemplate(data: any = {}) {
5
+ return `if (process.env.NODE_ENV === 'test') {
6
+ // behavior for the test environment, we'll try to make it work
29
7
 
30
- export function fillTemplate(name: string, data: any = {}) {
31
- const path = resolve(__dirname, '..', '..', 'templates', `${name}.ejs`);
32
- return new Promise<string>((resolve, reject) => {
33
- log('generalDebug_0003', `Rendering template "${name}" in "${path}".`);
34
- renderFile(path, data, (err, str) => {
35
- if (err) {
36
- reject(err);
37
- } else {
38
- resolve(str);
39
- }
40
- });
41
- });
8
+ if (typeof window !== 'undefined') {
9
+ require('./${data.outFile}');
10
+ const ctx = window['dbg:piral'];
11
+ const dependencies = (ctx && ctx.pilets && ctx.pilets.getDependencies({})) || {};
12
+ module.exports = dependencies['${data.name}'] || {};
13
+ } else {
14
+ console.error('Your test environment does not define "window". Please make sure to provide a proper environment.');
15
+ module.exports = {};
16
+ }
17
+ } else {
18
+ // under "normal" circumstances disallow such an import
19
+ throw new Error("This file should not be included anywhere. Usually, this means you've imported the Piral instance directly.");
20
+ }
21
+ `;
42
22
  }
43
23
 
44
- export async function createFileFromTemplateIfNotExists(
45
- prefix: string,
24
+ export async function createPiralStubIndexIfNotExists(
46
25
  targetDir: string,
47
26
  fileName: string,
48
27
  forceOverwrite?: ForceOverwrite,
49
28
  data?: any,
50
29
  ) {
51
- const content = await fillTemplate(`${prefix}-${fileName}`, data);
30
+ const content = fillTemplate(data);
52
31
  await createFileIfNotExists(targetDir, fileName, content, forceOverwrite);
53
32
  }
@@ -1,5 +1,5 @@
1
- import { keyOfForceOverwrite, keyOfSourceLanguage, valueOfForceOverwrite, valueOfSourceLanguage } from './helpers';
2
- import { ForceOverwrite, SourceLanguage } from './common/enums';
1
+ import { keyOfForceOverwrite, valueOfForceOverwrite } from './helpers';
2
+ import { ForceOverwrite } from './common/enums';
3
3
 
4
4
  describe('Piral CLI Command Helpers Module', () => {
5
5
  it('correct value of keyOfForceOverwrite results in same key', () => {
@@ -12,16 +12,6 @@ describe('Piral CLI Command Helpers Module', () => {
12
12
  expect(result).toBe('no');
13
13
  });
14
14
 
15
- it('correct value of keyOfPiletLanguage results in same key', () => {
16
- const result = keyOfSourceLanguage(SourceLanguage.ts);
17
- expect(result).toBe('ts');
18
- });
19
-
20
- it('incorrect value of keyOfPiletLanguage results in key for TS', () => {
21
- const result = keyOfSourceLanguage(5);
22
- expect(result).toBe('ts');
23
- });
24
-
25
15
  it('correct key of valueOfForceOverwrite results in same value', () => {
26
16
  const result = valueOfForceOverwrite('prompt');
27
17
  expect(result).toBe(ForceOverwrite.prompt);
@@ -31,14 +21,4 @@ describe('Piral CLI Command Helpers Module', () => {
31
21
  const result = valueOfForceOverwrite('foo');
32
22
  expect(result).toBe(ForceOverwrite.no);
33
23
  });
34
-
35
- it('correct key of valueOfPiletLanguage results in same value', () => {
36
- const result = valueOfSourceLanguage('ts');
37
- expect(result).toBe(SourceLanguage.ts);
38
- });
39
-
40
- it('incorrect key of valueOfPiletLanguage results in value for TS', () => {
41
- const result = valueOfSourceLanguage('foo');
42
- expect(result).toBe(SourceLanguage.ts);
43
- });
44
24
  });
package/src/helpers.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ForceOverwrite, SourceLanguage } from './common/enums';
1
+ import { ForceOverwrite } from './common/enums';
2
2
  import { bundlerNames, frameworkLibs } from './common/constants';
3
3
  import type {
4
4
  Framework,
@@ -8,6 +8,7 @@ import type {
8
8
  PiralBuildType,
9
9
  PiletBuildType,
10
10
  PiletPublishScheme,
11
+ SourceLanguage,
11
12
  } from './types';
12
13
 
13
14
  export const schemaKeys: Array<PiletSchemaVersion> = ['v0', 'v1', 'v2', 'none'];
@@ -15,7 +16,8 @@ export const publishModeKeys: Array<PiletPublishScheme> = ['none', 'basic', 'bea
15
16
  export const fromKeys: Array<PiletPublishSource> = ['local', 'remote', 'npm'];
16
17
  export const piralBuildTypeKeys: Array<PiralBuildType> = ['all', 'release', 'emulator', 'emulator-sources'];
17
18
  export const piletBuildTypeKeys: Array<PiletBuildType> = ['default', 'standalone', 'manifest'];
18
- export const clientTypeKeys: Array<NpmClientType> = ['npm', 'pnpm', 'yarn', 'lerna', 'rush'];
19
+ export const clientTypeKeys: Array<NpmClientType> = ['npm', 'pnpm', 'pnp', 'yarn', 'lerna', 'rush'];
20
+ export const sourceLanguageKeys: Array<SourceLanguage> = ['ts', 'js'];
19
21
  export const bundlerKeys: Array<string> = ['none', ...bundlerNames];
20
22
  export const availableBundlers: Array<string> = [];
21
23
  export const availableReleaseProviders: Array<string> = [];
@@ -41,25 +43,3 @@ export function keyOfForceOverwrite(value: ForceOverwrite) {
41
43
 
42
44
  return forceOverwriteKeys[0];
43
45
  }
44
-
45
- export const sourceLanguageKeys = Object.keys(SourceLanguage).filter((m) => typeof SourceLanguage[m] === 'number');
46
-
47
- export function valueOfSourceLanguage(key: string): SourceLanguage {
48
- for (const piletLanguageKey of sourceLanguageKeys) {
49
- if (piletLanguageKey === key) {
50
- return SourceLanguage[piletLanguageKey];
51
- }
52
- }
53
-
54
- return SourceLanguage.ts;
55
- }
56
-
57
- export function keyOfSourceLanguage(value: SourceLanguage) {
58
- for (const piletLanguageKey of sourceLanguageKeys) {
59
- if (SourceLanguage[piletLanguageKey] === value) {
60
- return piletLanguageKey;
61
- }
62
- }
63
-
64
- return sourceLanguageKeys[0];
65
- }
package/src/messages.ts CHANGED
@@ -2217,24 +2217,24 @@ export function publishEmulatorFilesUnexpected_0111(directory: string): QuickMes
2217
2217
  * @kind Error
2218
2218
  *
2219
2219
  * @summary
2220
- * The "xcopy" provider requires a "--fields.target" argument.
2220
+ * The "xcopy" provider requires a "--opts.target" argument.
2221
2221
  *
2222
2222
  * @abstract
2223
2223
  * The `piral publish --type release` command requires the selection of a suitable
2224
2224
  * provider for running successfully. The "xcopy" provider just copies the sources from
2225
2225
  * the output directory (source) to a specified target directory.
2226
2226
  *
2227
- * Make sure to supply the target directory via the `--fields.target` command line flag.
2227
+ * Make sure to supply the target directory via the `--opts.target` command line flag.
2228
2228
  *
2229
2229
  * @example
2230
2230
  * The following command would specify `/temp/dest` as target directory:
2231
2231
  *
2232
2232
  * ```sh
2233
- * piral publish --type release --provider xcopy --fields.target "/temp/dest"
2233
+ * piral publish --type release --provider xcopy --opts.target "/temp/dest"
2234
2234
  * ```
2235
2235
  */
2236
2236
  export function publishXcopyMissingTarget_0112(): QuickMessage {
2237
- return [LogLevels.error, '0112', `The "xcopy" provider requires a "--fields.target" argument.`];
2237
+ return [LogLevels.error, '0112', `The "xcopy" provider requires a "--opts.target" argument.`];
2238
2238
  }
2239
2239
 
2240
2240
  /**
@@ -2257,7 +2257,7 @@ export function publishXcopyMissingTarget_0112(): QuickMessage {
2257
2257
  * The following command uses the in-built "xcopy" provider for releasing to a local directory.
2258
2258
  *
2259
2259
  * ```sh
2260
- * piral publish --type release --provider xcopy --fields.target "/temp/dest"
2260
+ * piral publish --type release --provider xcopy --opts.target "/temp/dest"
2261
2261
  * ```
2262
2262
  */
2263
2263
  export function publishProviderMissing_0113(providerName: string, availableProviders: Array<string>): QuickMessage {
@@ -2278,7 +2278,7 @@ export function publishProviderMissing_0113(providerName: string, availableProvi
2278
2278
  * The following command uses the in-built "xcopy" provider for releasing to a local directory.
2279
2279
  *
2280
2280
  * ```sh
2281
- * piral publish --type release --provider xcopy --fields.target "/temp/dest"
2281
+ * piral publish --type release --provider xcopy --opts.target "/temp/dest"
2282
2282
  * ```
2283
2283
  *
2284
2284
  * The type is "release".
@@ -2295,14 +2295,14 @@ export function publishEmulatorSourcesInvalid_0114(): QuickMessage {
2295
2295
  * @kind Error
2296
2296
  *
2297
2297
  * @summary
2298
- * The "feed" provider requires a "--fields.url" argument.
2298
+ * The "feed" provider requires a "--opts.url" argument.
2299
2299
  *
2300
2300
  * @abstract
2301
2301
  * The `piral publish --type release` command requires the selection of a suitable
2302
2302
  * provider for running successfully. The "feed" provider releases the files to
2303
2303
  * the a Piral Feed Service with the static page feature.
2304
2304
  *
2305
- * Make sure to supply the URL for the feed service via the `--fields.url` command
2305
+ * Make sure to supply the URL for the feed service via the `--opts.url` command
2306
2306
  * line flag.
2307
2307
  *
2308
2308
  * @example
@@ -2310,25 +2310,25 @@ export function publishEmulatorSourcesInvalid_0114(): QuickMessage {
2310
2310
  * for the feed service:
2311
2311
  *
2312
2312
  * ```sh
2313
- * piral publish --type release --provider feed --fields.url "https://feed.piral.cloud/api/v1/feed/sample/page" --fields.apikey "foobar123"
2313
+ * piral publish --type release --provider feed --opts.url "https://feed.piral.cloud/api/v1/feed/sample/page" --opts.apikey "foobar123"
2314
2314
  * ```
2315
2315
  */
2316
2316
  export function publishFeedMissingUrl_0115(): QuickMessage {
2317
- return [LogLevels.error, '0115', `The "feed" provider requires a "--fields.url" argument.`];
2317
+ return [LogLevels.error, '0115', `The "feed" provider requires a "--opts.url" argument.`];
2318
2318
  }
2319
2319
 
2320
2320
  /**
2321
2321
  * @kind Error
2322
2322
  *
2323
2323
  * @summary
2324
- * The "feed" provider requires a "--fields.version" argument.
2324
+ * The "feed" provider requires a "--opts.version" argument.
2325
2325
  *
2326
2326
  * @abstract
2327
2327
  * The `piral publish --type release` command requires the selection of a suitable
2328
2328
  * provider for running successfully. The "feed" provider releases the files to
2329
2329
  * the a Piral Feed Service with the static page feature.
2330
2330
  *
2331
- * Make sure to supply the version either explicitly via the `--fields.version` argument
2331
+ * Make sure to supply the version either explicitly via the `--opts.version` argument
2332
2332
  * or implicitly by having the artifacts stored in a sub-directory of the project's root,
2333
2333
  * which contains a package.json with the version to use.
2334
2334
  *
@@ -2336,11 +2336,11 @@ export function publishFeedMissingUrl_0115(): QuickMessage {
2336
2336
  * The following command would specify version "1.2.3" for the feed service:
2337
2337
  *
2338
2338
  * ```sh
2339
- * piral publish --type release --provider feed --fields.url "..." --fields.apikey "..." --fields.version "1.2.3"
2339
+ * piral publish --type release --provider feed --opts.url "..." --opts.apikey "..." --opts.version "1.2.3"
2340
2340
  * ```
2341
2341
  */
2342
2342
  export function publishFeedMissingVersion_0116(): QuickMessage {
2343
- return [LogLevels.error, '0116', `The "feed" provider requires either a "--fields.version" argument or a package.json with a version.`];
2343
+ return [LogLevels.error, '0116', `The "feed" provider requires either a "--opts.version" argument or a package.json with a version.`];
2344
2344
  }
2345
2345
 
2346
2346
  /**
package/src/release.ts CHANGED
@@ -49,7 +49,7 @@ const providers: Record<string, ReleaseProvider> = {
49
49
  };
50
50
 
51
51
  for (const file of files) {
52
- const relPath = relative(file, directory);
52
+ const relPath = relative(directory, file);
53
53
  const fileName = basename(file);
54
54
  const content = await readBinary(dirname(file), fileName);
55
55
  data[relPath] = [content, fileName];
@@ -48,7 +48,6 @@ export interface ReleaseProvider {
48
48
  export interface TemplateFileLocation {
49
49
  from: string;
50
50
  to: string;
51
- template?: boolean;
52
51
  deep?: boolean;
53
52
  once?: boolean;
54
53
  }
@@ -219,6 +219,8 @@ export interface BundlerDefinition {
219
219
 
220
220
  export type PiletSchemaVersion = 'none' | 'v0' | 'v1' | 'v2';
221
221
 
222
+ export type SourceLanguage = 'js' | 'ts';
223
+
222
224
  export type PiletPublishScheme = 'none' | 'digest' | 'bearer' | 'basic';
223
225
 
224
226
  export type PiletPublishSource = 'local' | 'npm' | 'remote';
@@ -229,7 +231,7 @@ export type PiletBuildType = 'default' | 'standalone' | 'manifest';
229
231
 
230
232
  export type PackageType = 'registry' | 'file' | 'git';
231
233
 
232
- export type NpmClientType = 'npm' | 'yarn' | 'pnpm' | 'lerna' | 'rush';
234
+ export type NpmClientType = 'npm' | 'yarn' | 'pnp' | 'pnpm' | 'lerna' | 'rush';
233
235
 
234
236
  export type Framework = 'piral-native' | 'piral' | 'piral-core' | 'piral-base';
235
237
 
@@ -1,16 +0,0 @@
1
- if (process.env.NODE_ENV === 'test') {
2
- // behavior for the test environment, we'll try to make it work
3
-
4
- if (typeof window !== 'undefined') {
5
- require('./<%- outFile %>');
6
- const ctx = window['dbg:piral'];
7
- const dependencies = (ctx && ctx.pilets && ctx.pilets.getDependencies({})) || {};
8
- module.exports = dependencies['<%- name %>'] || {};
9
- } else {
10
- console.error('Your test environment does not define "window". Please make sure to provide a proper environment.');
11
- module.exports = {};
12
- }
13
- } else {
14
- // under "normal" circumstances disallow such an import
15
- throw new Error("This file should not be included anywhere. Usually, this means you've imported the Piral instance directly.");
16
- }