piral-cli 1.4.0-beta.6228 → 1.4.0-beta.6247

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 (59) hide show
  1. package/lib/apps/add-piral-instance-pilet.js +2 -4
  2. package/lib/apps/add-piral-instance-pilet.js.map +1 -1
  3. package/lib/apps/build-piral.js +17 -9
  4. package/lib/apps/build-piral.js.map +1 -1
  5. package/lib/apps/new-pilet.js +2 -1
  6. package/lib/apps/new-pilet.js.map +1 -1
  7. package/lib/apps/run-emulator-piral.js +3 -1
  8. package/lib/apps/run-emulator-piral.js.map +1 -1
  9. package/lib/build/bundler-calls.d.ts +2 -2
  10. package/lib/build/bundler-calls.js +4 -4
  11. package/lib/build/bundler-calls.js.map +1 -1
  12. package/lib/bundler.js +5 -5
  13. package/lib/bundler.js.map +1 -1
  14. package/lib/common/emulator.d.ts +1 -0
  15. package/lib/common/emulator.js +75 -9
  16. package/lib/common/emulator.js.map +1 -1
  17. package/lib/common/index.d.ts +1 -0
  18. package/lib/common/index.js +1 -0
  19. package/lib/common/index.js.map +1 -1
  20. package/lib/common/npm.d.ts +1 -0
  21. package/lib/common/npm.js +16 -4
  22. package/lib/common/npm.js.map +1 -1
  23. package/lib/common/package.d.ts +6 -3
  24. package/lib/common/package.js +28 -20
  25. package/lib/common/package.js.map +1 -1
  26. package/lib/common/shell.d.ts +2 -2
  27. package/lib/common/shell.js +14 -5
  28. package/lib/common/shell.js.map +1 -1
  29. package/lib/common/template.d.ts +5 -1
  30. package/lib/common/template.js +1 -1
  31. package/lib/common/template.js.map +1 -1
  32. package/lib/common/website.d.ts +2 -0
  33. package/lib/common/website.js +70 -0
  34. package/lib/common/website.js.map +1 -0
  35. package/lib/helpers.js +7 -1
  36. package/lib/helpers.js.map +1 -1
  37. package/lib/types/common.d.ts +22 -0
  38. package/lib/types/common.js.map +1 -1
  39. package/lib/types/internal.d.ts +7 -4
  40. package/lib/types/public.d.ts +3 -2
  41. package/package.json +2 -2
  42. package/src/apps/add-piral-instance-pilet.ts +2 -1
  43. package/src/apps/build-piral.ts +17 -9
  44. package/src/apps/new-pilet.ts +2 -1
  45. package/src/apps/run-emulator-piral.ts +3 -1
  46. package/src/build/bundler-calls.ts +4 -4
  47. package/src/bundler.test.ts +5 -5
  48. package/src/bundler.ts +5 -5
  49. package/src/common/emulator.ts +95 -15
  50. package/src/common/index.ts +1 -0
  51. package/src/common/npm.ts +16 -3
  52. package/src/common/package.ts +22 -36
  53. package/src/common/shell.ts +15 -14
  54. package/src/common/template.ts +8 -3
  55. package/src/common/website.ts +67 -0
  56. package/src/helpers.ts +7 -1
  57. package/src/types/common.ts +24 -0
  58. package/src/types/internal.ts +8 -7
  59. package/src/types/public.ts +3 -2
@@ -1,7 +1,12 @@
1
1
  import { ForceOverwrite } from './enums';
2
2
  import { createFileIfNotExists } from './io';
3
3
 
4
- function fillTemplate(data: any = {}) {
4
+ export interface PiralStubFileTemplateData {
5
+ outFile: string;
6
+ name: string;
7
+ }
8
+
9
+ function fillTemplate(data: PiralStubFileTemplateData) {
5
10
  return `if (process.env.NODE_ENV === 'test') {
6
11
  // behavior for the test environment, we'll try to make it work
7
12
 
@@ -24,8 +29,8 @@ function fillTemplate(data: any = {}) {
24
29
  export async function createPiralStubIndexIfNotExists(
25
30
  targetDir: string,
26
31
  fileName: string,
27
- forceOverwrite?: ForceOverwrite,
28
- data?: any,
32
+ forceOverwrite: ForceOverwrite,
33
+ data: PiralStubFileTemplateData,
29
34
  ) {
30
35
  const content = fillTemplate(data);
31
36
  await createFileIfNotExists(targetDir, fileName, content, forceOverwrite);
@@ -0,0 +1,67 @@
1
+ import { resolve as resolveUrl } from 'url';
2
+ import { join, resolve } from 'path';
3
+ import { createPiralStubIndexIfNotExists } from './template';
4
+ import { packageJson } from './constants';
5
+ import { ForceOverwrite } from './enums';
6
+ import { createDirectory, writeBinary } from './io';
7
+ import { writeJson } from './io';
8
+ import { axios } from '../external';
9
+ import { EmulatorWebsiteManifestFiles, EmulatorWebsiteManifest } from '../types';
10
+
11
+ async function downloadEmulatorFiles(manifestUrl: string, target: string, files: EmulatorWebsiteManifestFiles) {
12
+ const requiredFiles = [files.typings, files.main, files.app];
13
+
14
+ await Promise.all(
15
+ requiredFiles.map(async (file) => {
16
+ const res = await axios.default.get(resolveUrl(manifestUrl, file), { responseType: 'arraybuffer' });
17
+ const data: Buffer = res.data;
18
+ await writeBinary(target, file, data);
19
+ }),
20
+ );
21
+ }
22
+
23
+ export async function scaffoldFromEmulatorWebsite(rootDir: string, manifestUrl: string) {
24
+ const response = await axios.default.get(manifestUrl);
25
+ const emulatorJson: EmulatorWebsiteManifest = response.data;
26
+
27
+ const targetDir = resolve(rootDir, 'node_modules', emulatorJson.name);
28
+ const appDirName = 'app';
29
+ const mainFile = 'index.js';
30
+ const appDir = resolve(targetDir, appDirName);
31
+ await createDirectory(appDir);
32
+
33
+ await writeJson(
34
+ targetDir,
35
+ packageJson,
36
+ {
37
+ name: emulatorJson.name,
38
+ description: emulatorJson.description,
39
+ version: emulatorJson.version,
40
+ importmap: emulatorJson.importmap,
41
+ pilets: emulatorJson.scaffolding.pilets,
42
+ piralCLI: {
43
+ version: emulatorJson.scaffolding.cli,
44
+ timestamp: emulatorJson.timestamp,
45
+ source: manifestUrl,
46
+ generated: true,
47
+ },
48
+ files: emulatorJson.files,
49
+ main: `./${join(appDirName, mainFile)}`,
50
+ typings: `./${join(appDirName, emulatorJson.files.typings)}`,
51
+ app: `./${join(appDirName, emulatorJson.files.app)}`,
52
+ peerDependencies: {},
53
+ optionalDependencies: emulatorJson.dependencies.optional,
54
+ devDependencies: emulatorJson.dependencies.included,
55
+ },
56
+ true,
57
+ );
58
+
59
+ // actually including this one hints that the app shell should have been included - which is forbidden
60
+ await createPiralStubIndexIfNotExists(appDir, mainFile, ForceOverwrite.yes, {
61
+ name: emulatorJson.name,
62
+ outFile: emulatorJson.files.main,
63
+ });
64
+
65
+ await downloadEmulatorFiles(manifestUrl, appDir, emulatorJson.files);
66
+ return emulatorJson;
67
+ }
package/src/helpers.ts CHANGED
@@ -14,7 +14,13 @@ import type {
14
14
  export const schemaKeys: Array<PiletSchemaVersion> = ['v0', 'v1', 'v2', 'v3', 'none'];
15
15
  export const publishModeKeys: Array<PiletPublishScheme> = ['none', 'basic', 'bearer', 'digest'];
16
16
  export const fromKeys: Array<PiletPublishSource> = ['local', 'remote', 'npm'];
17
- export const piralBuildTypeKeys: Array<PiralBuildType> = ['all', 'release', 'emulator', 'emulator-sources'];
17
+ export const piralBuildTypeKeys: Array<PiralBuildType> = [
18
+ 'all',
19
+ 'release',
20
+ 'emulator',
21
+ 'emulator-sources',
22
+ 'emulator-website',
23
+ ];
18
24
  export const piletBuildTypeKeys: Array<PiletBuildType> = ['default', 'standalone', 'manifest'];
19
25
  export const clientTypeKeys: Array<NpmClientType> = ['npm', 'pnpm', 'pnp', 'yarn', 'lerna', 'rush', 'bun'];
20
26
  export const sourceLanguageKeys: Array<SourceLanguage> = ['ts', 'js'];
@@ -4,6 +4,30 @@ export interface Importmap {
4
4
  exclude?: Array<string>;
5
5
  }
6
6
 
7
+ export interface EmulatorWebsiteManifestFiles {
8
+ typings: string;
9
+ main: string;
10
+ app: string;
11
+ assets: Array<string>;
12
+ }
13
+
14
+ export interface EmulatorWebsiteManifest {
15
+ name: string;
16
+ description: string;
17
+ version: string;
18
+ timestamp: string;
19
+ scaffolding: {
20
+ pilets: PiletsInfo;
21
+ cli: string;
22
+ };
23
+ files: EmulatorWebsiteManifestFiles;
24
+ importmap: Importmap;
25
+ dependencies: {
26
+ optional: Record<string, string>;
27
+ included: Record<string, string>;
28
+ };
29
+ }
30
+
7
31
  export interface PackageData {
8
32
  name: string;
9
33
  version: string;
@@ -1,19 +1,20 @@
1
1
  import type { LogLevels } from './common';
2
2
  import type { ImportmapVersions, PiletSchemaVersion } from './public';
3
3
 
4
+ export interface PiralInstanceDetails {
5
+ selected?: boolean;
6
+ port?: number;
7
+ path?: string;
8
+ url?: string;
9
+ }
10
+
4
11
  /**
5
12
  * Shape of the pilet.json
6
13
  */
7
14
  export interface PiletDefinition {
8
15
  schemaVersion?: PiletSchemaVersion;
9
16
  importmapVersions?: ImportmapVersions;
10
- piralInstances?: Record<
11
- string,
12
- {
13
- selected?: boolean;
14
- port?: number;
15
- }
16
- >;
17
+ piralInstances?: Record<string, PiralInstanceDetails>;
17
18
  }
18
19
 
19
20
  export interface PackageFiles {
@@ -136,6 +136,7 @@ export interface BundlerPrepareArgs<T> {
136
136
 
137
137
  export interface BaseBundlerDefinition<T> {
138
138
  path: string;
139
+ exec?: string;
139
140
  prepare?: BundlerPrepareArgs<T>;
140
141
  }
141
142
 
@@ -231,11 +232,11 @@ export type PiletPublishScheme = 'none' | 'digest' | 'bearer' | 'basic';
231
232
 
232
233
  export type PiletPublishSource = 'local' | 'npm' | 'remote';
233
234
 
234
- export type PiralBuildType = 'all' | 'release' | 'emulator' | 'emulator-sources';
235
+ export type PiralBuildType = 'all' | 'release' | 'emulator' | 'emulator-sources' | 'emulator-website';
235
236
 
236
237
  export type PiletBuildType = 'default' | 'standalone' | 'manifest';
237
238
 
238
- export type PackageType = 'registry' | 'file' | 'git';
239
+ export type PackageType = 'registry' | 'file' | 'git' | 'remote';
239
240
 
240
241
  export type NpmClientType = 'npm' | 'yarn' | 'pnp' | 'pnpm' | 'lerna' | 'rush' | 'bun';
241
242