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
@@ -118,6 +118,7 @@ export interface BundlerPrepareArgs<T> {
118
118
  }
119
119
  export interface BaseBundlerDefinition<T> {
120
120
  path: string;
121
+ exec?: string;
121
122
  prepare?: BundlerPrepareArgs<T>;
122
123
  }
123
124
  export interface WatchPiralBundlerDefinition extends BaseBundlerDefinition<WatchPiralParameters> {
@@ -197,9 +198,9 @@ export type PiletSchemaVersion = 'none' | 'v0' | 'v1' | 'v2' | 'v3';
197
198
  export type SourceLanguage = 'js' | 'ts';
198
199
  export type PiletPublishScheme = 'none' | 'digest' | 'bearer' | 'basic';
199
200
  export type PiletPublishSource = 'local' | 'npm' | 'remote';
200
- export type PiralBuildType = 'all' | 'release' | 'emulator' | 'emulator-sources';
201
+ export type PiralBuildType = 'all' | 'release' | 'emulator' | 'emulator-sources' | 'emulator-website';
201
202
  export type PiletBuildType = 'default' | 'standalone' | 'manifest';
202
- export type PackageType = 'registry' | 'file' | 'git';
203
+ export type PackageType = 'registry' | 'file' | 'git' | 'remote';
203
204
  export type NpmClientType = 'npm' | 'yarn' | 'pnp' | 'pnpm' | 'lerna' | 'rush' | 'bun';
204
205
  export type Framework = 'piral' | 'piral-core' | 'piral-base';
205
206
  export interface StandardEnvProps {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-cli",
3
- "version": "1.4.0-beta.6228",
3
+ "version": "1.4.0-beta.6247",
4
4
  "description": "The standard CLI for creating and building a Piral instance or a Pilet.",
5
5
  "keywords": [
6
6
  "portal",
@@ -81,5 +81,5 @@
81
81
  "typescript": "^5.0.0",
82
82
  "yargs": "^15.0.0"
83
83
  },
84
- "gitHead": "cbcd72a90e216dfa92f4a36f75208a1a11d840a5"
84
+ "gitHead": "31188a71482165dea7606cfafd7f9b77ce919331"
85
85
  }
@@ -74,13 +74,14 @@ export async function addPiralInstancePilet(baseDir = process.cwd(), options: Ad
74
74
  const piletJsonDir = dirname(piletJsonPath);
75
75
  const root = await findPiletRoot(piletJsonDir);
76
76
  const oldContent = await readJson(piletJsonDir, piletJson);
77
- const [appName] = await installPiralInstance(app, fullBase, root, npmClient);
77
+ const [appName, _, appDetails] = await installPiralInstance(app, fullBase, root, npmClient);
78
78
 
79
79
  const newContent = {
80
80
  ...oldContent,
81
81
  piralInstances: {
82
82
  ...oldContent.piralInstances,
83
83
  [appName]: {
84
+ ...appDetails,
84
85
  selected,
85
86
  },
86
87
  },
@@ -19,11 +19,14 @@ import {
19
19
  getDestination,
20
20
  validateSharedDependencies,
21
21
  flattenExternals,
22
+ createEmulatorWebsite,
22
23
  } from '../common';
23
24
 
25
+ const allName = 'all';
24
26
  const releaseName = 'release';
25
27
  const emulatorName = 'emulator';
26
28
  const emulatorSourcesName = 'emulator-sources';
29
+ const emulatorWebsiteName = 'emulator-website';
27
30
 
28
31
  export interface BuildPiralOptions {
29
32
  /**
@@ -118,7 +121,7 @@ export const buildPiralDefaults: BuildPiralOptions = {
118
121
  logLevel: LogLevels.info,
119
122
  fresh: false,
120
123
  minify: true,
121
- type: 'all',
124
+ type: allName,
122
125
  subdir: true,
123
126
  sourceMaps: true,
124
127
  watch: false,
@@ -177,10 +180,11 @@ export async function buildPiral(baseDir = process.cwd(), options: BuildPiralOpt
177
180
  await removeDirectory(dest.outDir);
178
181
  }
179
182
 
180
- // everything except release -> build emulator
181
- if (type !== releaseName) {
183
+ // either 'emulator-*' or 'all'
184
+ if (type === emulatorName || type === emulatorSourcesName || type === emulatorWebsiteName || type === allName) {
182
185
  const emulatorPublicUrl = '/';
183
186
  const targetDir = useSubdir ? join(dest.outDir, emulatorName) : dest.outDir;
187
+ const appDir = type !== emulatorWebsiteName ? join(targetDir, 'app') : targetDir;
184
188
  progress('Starting emulator build ...');
185
189
 
186
190
  // since we create this anyway let's just pretend we want to have it clean!
@@ -209,7 +213,7 @@ export async function buildPiral(baseDir = process.cwd(), options: BuildPiralOpt
209
213
  entryFiles,
210
214
  logLevel,
211
215
  ignored,
212
- outDir: join(targetDir, 'app'),
216
+ outDir: appDir,
213
217
  outFile: dest.outFile,
214
218
  _,
215
219
  },
@@ -233,24 +237,28 @@ export async function buildPiral(baseDir = process.cwd(), options: BuildPiralOpt
233
237
 
234
238
  await hooks.beforeEmulator?.({ root, externals, targetDir, outDir });
235
239
 
236
- const rootDir = await createEmulatorSources(root, externals, outDir, outFile, logLevel);
240
+ const rootDir = await (type !== emulatorWebsiteName
241
+ ? createEmulatorSources(root, externals, outDir, outFile, logLevel)
242
+ : createEmulatorWebsite(root, externals, outDir, outFile, logLevel));
237
243
 
238
244
  await hooks.afterEmulator?.({ root, externals, targetDir, outDir, rootDir });
239
245
 
240
- if (type !== emulatorSourcesName) {
246
+ if (type === allName || type === emulatorName) {
241
247
  await hooks.beforePackage?.({ root, externals, targetDir, outDir, rootDir });
242
248
  await packageEmulator(rootDir);
243
249
  await hooks.afterPackage?.({ root, externals, targetDir, outDir, rootDir });
244
250
  logDone(`Emulator package available in "${rootDir}".`);
245
- } else {
251
+ } else if (type === emulatorSourcesName) {
246
252
  logDone(`Emulator sources available in "${rootDir}".`);
253
+ } else if (type === emulatorWebsiteName) {
254
+ logDone(`Emulator website available in "${rootDir}".`);
247
255
  }
248
256
 
249
257
  logReset();
250
258
  }
251
259
 
252
- // everything except emulator and emulator-soruces -> build release
253
- if (type !== emulatorName && type !== emulatorSourcesName) {
260
+ // either 'release' or 'all'
261
+ if (type === releaseName || type === allName) {
254
262
  const targetDir = useSubdir ? join(dest.outDir, releaseName) : dest.outDir;
255
263
  progress('Starting release build ...');
256
264
 
@@ -184,7 +184,7 @@ always-auth=true`,
184
184
  ),
185
185
  );
186
186
 
187
- const [packageName, packageVersion] = await installPiralInstance(
187
+ const [packageName, packageVersion, packageDetails] = await installPiralInstance(
188
188
  source || `empty-piral@${cliVersion}`,
189
189
  fullBase,
190
190
  root,
@@ -209,6 +209,7 @@ always-auth=true`,
209
209
  await patchPiletPackage(root, packageName, packageVersion, piralInfo, isEmulator, {
210
210
  language,
211
211
  bundler: bundlerName,
212
+ details: packageDetails,
212
213
  });
213
214
 
214
215
  const chosenTemplate = template || preSelectedTemplate || 'default';
@@ -117,7 +117,9 @@ always-auth=true`,
117
117
 
118
118
  const npmClient = await determineNpmClient(appRoot, defaultNpmClient);
119
119
  const [packageName] = await installPiralInstance(app, fullBase, appRoot, npmClient);
120
- const piral = await findPiralInstance(packageName, appRoot, originalPort);
120
+ const piral = await findPiralInstance(packageName, appRoot, {
121
+ port: originalPort,
122
+ });
121
123
  const port = await getAvailablePort(piral.port);
122
124
 
123
125
  const krasBaseConfig = resolve(fullBase, krasrc);
@@ -55,10 +55,10 @@ function createBundler(cwd: string, ps: ChildProcess, args: any) {
55
55
  return bundler;
56
56
  }
57
57
 
58
- export function callDynamic<T extends BaseBundleParameters>(name: string, path: string, args: T) {
58
+ export function callDynamic<T extends BaseBundleParameters>(name: string, path: string, args: T, exec?: string) {
59
59
  const cwd = args.root;
60
60
  return new Promise<Bundler>((resolve, reject) => {
61
- const ps = fork(getPath(name), [], { cwd, stdio: 'pipe', env: process.env });
61
+ const ps = fork(getPath(name), [], { cwd, stdio: 'pipe', env: process.env, execPath: exec });
62
62
  const bundler = createBundler(cwd, ps, args);
63
63
  const setup = {
64
64
  type: 'init',
@@ -97,10 +97,10 @@ export function callDynamic<T extends BaseBundleParameters>(name: string, path:
97
97
  });
98
98
  }
99
99
 
100
- export function callStatic<T extends BaseBundleParameters>(name: string, path: string, args: T) {
100
+ export function callStatic<T extends BaseBundleParameters>(name: string, path: string, args: T, exec?: string) {
101
101
  const cwd = args.root;
102
102
  return new Promise<Bundler>((resolve, reject) => {
103
- const ps = fork(getPath(name), [], { cwd, stdio: 'pipe', env: process.env });
103
+ const ps = fork(getPath(name), [], { cwd, stdio: 'pipe', env: process.env, execPath: exec });
104
104
  const bundler = createBundler(cwd, ps, args);
105
105
  const setup = {
106
106
  type: 'init',
@@ -92,7 +92,7 @@ describe('Piral CLI Bundler Module', () => {
92
92
 
93
93
  const args = { root: undefined };
94
94
  await callPiletBuild(args as any, 'foo1');
95
- expect(callStatic).toHaveBeenCalledWith('build-pilet', '1', args);
95
+ expect(callStatic).toHaveBeenCalledWith('build-pilet', '1', args, undefined);
96
96
  });
97
97
 
98
98
  it('setting the bundler with optimize modules calls optimize modules', async () => {
@@ -134,7 +134,7 @@ describe('Piral CLI Bundler Module', () => {
134
134
 
135
135
  const args = { root: undefined };
136
136
  await callPiralBuild(args as any, 'foo2');
137
- expect(callStatic).toHaveBeenCalledWith('build-piral', '3', args);
137
+ expect(callStatic).toHaveBeenCalledWith('build-piral', '3', args, undefined);
138
138
  });
139
139
 
140
140
  it('setting the bundler can resolve it properly for call pilet debug', async () => {
@@ -153,7 +153,7 @@ describe('Piral CLI Bundler Module', () => {
153
153
 
154
154
  const args = { root: undefined };
155
155
  await callPiletDebug(args as any, 'foo3');
156
- expect(callDynamic).toHaveBeenCalledWith('debug-pilet', '1', args);
156
+ expect(callDynamic).toHaveBeenCalledWith('debug-pilet', '1', args, undefined);
157
157
  });
158
158
 
159
159
  it('setting the bundler can resolve it properly for call piral debug', async () => {
@@ -172,7 +172,7 @@ describe('Piral CLI Bundler Module', () => {
172
172
 
173
173
  const args = { root: undefined };
174
174
  await callPiralDebug(args as any, 'foo4');
175
- expect(callDynamic).toHaveBeenCalledWith('debug-piral', '10', args);
175
+ expect(callDynamic).toHaveBeenCalledWith('debug-piral', '10', args, undefined);
176
176
  });
177
177
 
178
178
  it('setting the bundler can resolve it properly for call piral watch', async () => {
@@ -191,7 +191,7 @@ describe('Piral CLI Bundler Module', () => {
191
191
 
192
192
  const args = { root: undefined };
193
193
  await callDebugPiralFromMonoRepo(args as any, 'foo5');
194
- expect(callStatic).toHaveBeenCalledWith('debug-mono-piral', '7', args);
194
+ expect(callStatic).toHaveBeenCalledWith('debug-mono-piral', '7', args, undefined);
195
195
  });
196
196
 
197
197
  it('using a non-available bundler should fail', () => {
package/src/bundler.ts CHANGED
@@ -122,7 +122,7 @@ export async function callPiralDebug(args: DebugPiralParameters, bundlerName?: s
122
122
  try {
123
123
  const action = bundler.actions.debugPiral;
124
124
  const params = await prepareArgs(action, args);
125
- return await callDynamic('debug-piral', action.path, params);
125
+ return await callDynamic('debug-piral', action.path, params, action.exec);
126
126
  } catch (err) {
127
127
  fail('bundlingFailed_0174', err);
128
128
  }
@@ -134,7 +134,7 @@ export async function callPiletDebug(args: DebugPiletParameters, bundlerName?: s
134
134
  try {
135
135
  const action = bundler.actions.debugPilet;
136
136
  const params = await prepareArgs(action, args);
137
- return await callDynamic('debug-pilet', action.path, params);
137
+ return await callDynamic('debug-pilet', action.path, params, action.exec);
138
138
  } catch (err) {
139
139
  fail('bundlingFailed_0174', err);
140
140
  }
@@ -146,7 +146,7 @@ export async function callPiralBuild(args: BuildPiralParameters, bundlerName?: s
146
146
  try {
147
147
  const action = bundler.actions.buildPiral;
148
148
  const params = await prepareArgs(action, args);
149
- const instance = await callStatic('build-piral', action.path, params);
149
+ const instance = await callStatic('build-piral', action.path, params, action.exec);
150
150
  return instance.bundle;
151
151
  } catch (err) {
152
152
  fail('bundlingFailed_0174', err);
@@ -159,7 +159,7 @@ export async function callPiletBuild(args: BuildPiletParameters, bundlerName?: s
159
159
  try {
160
160
  const action = bundler.actions.buildPilet;
161
161
  const params = await prepareArgs(action, args);
162
- const instance = await callStatic('build-pilet', action.path, params);
162
+ const instance = await callStatic('build-pilet', action.path, params, action.exec);
163
163
  return instance.bundle;
164
164
  } catch (err) {
165
165
  fail('bundlingFailed_0174', err);
@@ -175,7 +175,7 @@ export async function callDebugPiralFromMonoRepo(
175
175
  try {
176
176
  const action = bundler.actions.watchPiral;
177
177
  const params = await prepareArgs(action, args);
178
- const instance = await callStatic('debug-mono-piral', action.path, params);
178
+ const instance = await callStatic('debug-mono-piral', action.path, params, action.exec);
179
179
  return instance.bundle;
180
180
  } catch (err) {
181
181
  fail('bundlingFailed_0174', err);
@@ -1,4 +1,4 @@
1
- import { join, resolve, relative } from 'path';
1
+ import { join, resolve, relative, basename } from 'path';
2
2
  import { findDependencyVersion, copyScaffoldingFiles, isValidDependency, flattenExternals } from './package';
3
3
  import { createPiralStubIndexIfNotExists } from './template';
4
4
  import { filesTar, filesOnceTar, packageJson, piralJson } from './constants';
@@ -7,16 +7,9 @@ import { createNpmPackage } from './npm';
7
7
  import { createPiralDeclaration } from './declaration';
8
8
  import { ForceOverwrite } from './enums';
9
9
  import { createTarball } from './archive';
10
- import { LogLevels, SharedDependency, PiletsInfo, TemplateFileLocation } from '../types';
11
- import {
12
- createDirectory,
13
- removeDirectory,
14
- createFileIfNotExists,
15
- updateExistingJson,
16
- getFileNames,
17
- removeAny,
18
- readJson,
19
- } from './io';
10
+ import { createDirectory, removeDirectory, matchFiles, removeAny, getFileNames } from './io';
11
+ import { updateExistingJson, readJson, writeJson, createFileIfNotExists } from './io';
12
+ import { EmulatorWebsiteManifest, LogLevels, SharedDependency, PiletsInfo, TemplateFileLocation } from '../types';
20
13
 
21
14
  export async function createEmulatorSources(
22
15
  sourceDir: string,
@@ -107,9 +100,9 @@ export async function createEmulatorSources(
107
100
  version: cliVersion,
108
101
  generated: true,
109
102
  },
110
- main: `./${appDir}/index.js`,
111
- typings: `./${appDir}/index.d.ts`,
112
- app: `./${appDir}/index.html`,
103
+ main: `./${join(appDir, 'index.js')}`,
104
+ typings: `./${join(appDir, 'index.d.ts')}`,
105
+ app: `./${join(appDir, 'index.html')}`,
113
106
  peerDependencies: {},
114
107
  optionalDependencies,
115
108
  devDependencies: {
@@ -148,7 +141,7 @@ export async function createEmulatorSources(
148
141
  // actually including this one hints that the app shell should have been included - which is forbidden
149
142
  await createPiralStubIndexIfNotExists(targetDir, 'index.js', ForceOverwrite.yes, {
150
143
  name: piralPkg.name,
151
- outFile: targetFile,
144
+ outFile: basename(targetFile),
152
145
  });
153
146
 
154
147
  // generate the associated index.d.ts
@@ -166,6 +159,93 @@ export async function createEmulatorSources(
166
159
  return rootDir;
167
160
  }
168
161
 
162
+ export async function createEmulatorWebsite(
163
+ sourceDir: string,
164
+ externals: Array<SharedDependency>,
165
+ targetDir: string,
166
+ targetFile: string,
167
+ logLevel: LogLevels,
168
+ ) {
169
+ const piralPkg = await readJson(sourceDir, packageJson);
170
+ const piralJsonPkg = await readJson(sourceDir, piralJson);
171
+ const pilets: PiletsInfo = {
172
+ ...piralPkg.pilets,
173
+ ...piralJsonPkg.pilets,
174
+ };
175
+ const allDeps = {
176
+ ...piralPkg.devDependencies,
177
+ ...piralPkg.dependencies,
178
+ };
179
+
180
+ const externalPackages = await Promise.all(
181
+ externals
182
+ .filter((ext) => ext.type === 'local' && isValidDependency(ext.name))
183
+ .map(async (external) => ({
184
+ name: external.name,
185
+ version: await findDependencyVersion(piralPkg, sourceDir, external),
186
+ optional: external.isAsync,
187
+ })),
188
+ );
189
+ const externalDependencies = externalPackages.reduce((deps, dep) => {
190
+ if (!dep.optional) {
191
+ deps[dep.name] = dep.version;
192
+ }
193
+
194
+ return deps;
195
+ }, {} as Record<string, string>);
196
+
197
+ const importmapEntries = externalPackages.reduce((deps, dep) => {
198
+ if (!dep.optional) {
199
+ deps[dep.name] = dep.name;
200
+ }
201
+
202
+ return deps;
203
+ }, {} as Record<string, string>);
204
+
205
+ const optionalDependencies = externalPackages.reduce((deps, dep) => {
206
+ if (dep.optional) {
207
+ deps[dep.name] = dep.name;
208
+ }
209
+
210
+ return deps;
211
+ }, {} as Record<string, string>);
212
+
213
+ const allFiles = await matchFiles(targetDir, '*');
214
+ const data: EmulatorWebsiteManifest = {
215
+ name: piralPkg.name,
216
+ description: piralPkg.description,
217
+ version: piralPkg.version,
218
+ timestamp: new Date().toISOString(),
219
+ scaffolding: {
220
+ pilets,
221
+ cli: cliVersion,
222
+ },
223
+ files: {
224
+ typings: 'index.d.ts',
225
+ main: basename(targetFile),
226
+ app: 'index.html',
227
+ assets: allFiles.map((file) => relative(targetDir, file)),
228
+ },
229
+ importmap: {
230
+ imports: importmapEntries,
231
+ },
232
+ dependencies: {
233
+ optional: optionalDependencies,
234
+ included: {
235
+ ...allDeps,
236
+ ...externalDependencies,
237
+ },
238
+ },
239
+ };
240
+
241
+ await writeJson(targetDir, 'emulator.json', data, true);
242
+
243
+ // generate the associated index.d.ts
244
+ await createPiralDeclaration(sourceDir, piralPkg.app ?? `./src/index.html`, targetDir, ForceOverwrite.yes, logLevel);
245
+
246
+ return targetDir;
247
+ }
248
+
169
249
  export async function packageEmulator(rootDir: string) {
170
250
  // finally package everything up
171
251
  await createNpmPackage(rootDir);
@@ -36,3 +36,4 @@ export * from './template';
36
36
  export * from './url';
37
37
  export * from './version';
38
38
  export * from './watcher';
39
+ export * from './website';
package/src/common/npm.ts CHANGED
@@ -195,7 +195,7 @@ export function publishNpmPackage(
195
195
  interactive = false,
196
196
  ): Promise<string> {
197
197
  const { publishPackage, loginUser } = clients.npm;
198
- return publishPackage(target, file, ...flags).catch(err => {
198
+ return publishPackage(target, file, ...flags).catch((err) => {
199
199
  if (!interactive) {
200
200
  throw err;
201
201
  }
@@ -266,13 +266,13 @@ export function makeNpmAlias(name: string, version: string) {
266
266
  }
267
267
 
268
268
  export function isGitPackage(fullName: string) {
269
- log('generalDebug_0003', 'Checking if its a Git package ...');
269
+ log('generalDebug_0003', 'Checking if its a git package ...');
270
270
 
271
271
  if (fullName) {
272
272
  const gitted = fullName.startsWith(gitPrefix);
273
273
 
274
274
  if (gitted || /^(https?|ssh):\/\/.*\.git$/.test(fullName)) {
275
- log('generalDebug_0003', 'Found a Git package by name.');
275
+ log('generalDebug_0003', 'Found a git package by name.');
276
276
  return true;
277
277
  }
278
278
  }
@@ -280,6 +280,17 @@ export function isGitPackage(fullName: string) {
280
280
  return false;
281
281
  }
282
282
 
283
+ export function isRemotePackage(fullName: string) {
284
+ log('generalDebug_0003', 'Checking if its a remote package ...');
285
+
286
+ if (fullName && /^https?:\/\/.*/.test(fullName)) {
287
+ log('generalDebug_0003', 'Found a remote package by name.');
288
+ return true;
289
+ }
290
+
291
+ return false;
292
+ }
293
+
283
294
  export function makeGitUrl(fullName: string) {
284
295
  const gitted = fullName.startsWith(gitPrefix);
285
296
  return gitted ? fullName : `${gitPrefix}${fullName}`;
@@ -309,6 +320,8 @@ export async function dissectPackageName(
309
320
  if (isGitPackage(fullName)) {
310
321
  const gitUrl = makeGitUrl(fullName);
311
322
  return [gitUrl, 'latest', false, 'git'];
323
+ } else if (isRemotePackage(fullName)) {
324
+ return [fullName, 'latest', false, 'remote'];
312
325
  } else if (isLocalPackage(baseDir, fullName)) {
313
326
  const fullPath = resolveAbsPath(baseDir, fullName);
314
327
  const exists = await checkExists(fullPath);
@@ -11,34 +11,15 @@ import { getHash, checkIsDirectory, matchFiles } from './io';
11
11
  import { readJson, copy, updateExistingJson, findFile, checkExists } from './io';
12
12
  import { isGitPackage, isLocalPackage, makeGitUrl, makeFilePath, tryResolvePackage, isNpmPackage } from './npm';
13
13
  import { makePiletExternals, makeExternals, findPackageRoot, findSpecificVersion, makeNpmAlias } from './npm';
14
- import { getModulePath } from '../external';
14
+ import { scaffoldFromEmulatorWebsite } from './website';
15
15
  import { getDependencies, getDependencyPackages, getDevDependencies } from './language';
16
16
  import { getDevDependencyPackages, getFrameworkDependencies } from './language';
17
- import {
18
- declarationEntryExtensions,
19
- piralJsonSchemaUrl,
20
- piletJsonSchemaUrl,
21
- filesTar,
22
- filesOnceTar,
23
- bundlerNames,
24
- frameworkLibs,
25
- piralJson,
26
- piletJson,
27
- packageJson,
28
- } from './constants';
29
- import {
30
- SourceLanguage,
31
- Framework,
32
- FileInfo,
33
- PiletsInfo,
34
- TemplateFileLocation,
35
- PiletPackageData,
36
- PiralPackageData,
37
- SharedDependency,
38
- PiletDefinition,
39
- AppDefinition,
40
- PiralInstancePackageData,
41
- } from '../types';
17
+ import { piralJsonSchemaUrl, piletJsonSchemaUrl, filesTar, filesOnceTar, bundlerNames } from './constants';
18
+ import { frameworkLibs, declarationEntryExtensions, piralJson, piletJson, packageJson } from './constants';
19
+ import { getModulePath } from '../external';
20
+ import { PiletsInfo, SharedDependency, PiletDefinition, AppDefinition } from '../types';
21
+ import { SourceLanguage, PiralInstancePackageData, PiralInstanceDetails } from '../types';
22
+ import { Framework, FileInfo, TemplateFileLocation, PiletPackageData, PiralPackageData } from '../types';
42
23
 
43
24
  export interface PiralInstanceData {
44
25
  packageName: Framework;
@@ -168,10 +149,10 @@ export function getPiralPath(root: string, name: string) {
168
149
 
169
150
  export async function findPiralInstance(
170
151
  proposedApp: string,
171
- baseDir: string,
172
- port: number,
152
+ rootDir: string,
153
+ details?: PiralInstanceDetails,
173
154
  ): Promise<PiralInstancePackageData> {
174
- const path = findPackageRoot(proposedApp, baseDir);
155
+ const path = findPackageRoot(proposedApp, rootDir);
175
156
 
176
157
  if (path) {
177
158
  log('generalDebug_0003', `Following the app package in "${path}" ...`);
@@ -180,8 +161,13 @@ export async function findPiralInstance(
180
161
  const relPath = appPackage && appPackage.app;
181
162
  appPackage.app = relPath && resolve(root, relPath);
182
163
  appPackage.root = root;
183
- appPackage.port = port;
164
+ appPackage.port = details?.port || 0;
184
165
  return appPackage;
166
+ } else if (details?.url) {
167
+ const { url, ...rest } = details;
168
+ log('generalDebug_0003', `Piral instance not installed yet - trying from remote "${url}" ...`);
169
+ await scaffoldFromEmulatorWebsite(rootDir, url);
170
+ return await findPiralInstance(proposedApp, rootDir, rest);
185
171
  }
186
172
 
187
173
  fail('appInstanceNotFound_0010', proposedApp);
@@ -191,7 +177,7 @@ export async function findPiralInstances(
191
177
  proposedApps: Array<string>,
192
178
  piletPackage: PiletPackageData,
193
179
  piletDefinition: undefined | PiletDefinition,
194
- baseDir: string,
180
+ rootDir: string,
195
181
  ) {
196
182
  if (proposedApps) {
197
183
  // do nothing
@@ -209,7 +195,7 @@ export async function findPiralInstances(
209
195
  if (proposedApps.length > 0) {
210
196
  return Promise.all(
211
197
  proposedApps.map((proposedApp) =>
212
- findPiralInstance(proposedApp, baseDir, piletDefinition?.piralInstances?.[proposedApp]?.port ?? 0),
198
+ findPiralInstance(proposedApp, rootDir, piletDefinition?.piralInstances?.[proposedApp]),
213
199
  ),
214
200
  );
215
201
  }
@@ -220,7 +206,7 @@ export async function findPiralInstances(
220
206
  export function readPiralPackage(root: string, name: string): Promise<PiralPackageData> {
221
207
  log('generalDebug_0003', `Reading the piral package in "${root}" ...`);
222
208
  const path = getPiralPath(root, name);
223
- return readJson(path, 'package.json');
209
+ return readJson(path, packageJson);
224
210
  }
225
211
 
226
212
  export async function patchPiralPackage(
@@ -653,7 +639,7 @@ export async function patchPiletPackage(
653
639
  version: string,
654
640
  piralInfo: PiralPackageData,
655
641
  fromEmulator: boolean,
656
- newInfo?: { language: SourceLanguage; bundler: string },
642
+ newInfo?: { language: SourceLanguage; bundler: string; details: PiralInstanceDetails },
657
643
  ) {
658
644
  log('generalDebug_0003', `Patching the package.json in "${root}" ...`);
659
645
  const pkg = await getPiletPackage(root, name, version, piralInfo, fromEmulator, newInfo);
@@ -664,7 +650,7 @@ export async function patchPiletPackage(
664
650
  await updateExistingJson(root, piletJson, {
665
651
  $schema: piletJsonSchemaUrl,
666
652
  piralInstances: {
667
- [name]: {},
653
+ [name]: newInfo?.details || {},
668
654
  },
669
655
  });
670
656
  log('generalDebug_0003', `Succesfully patched the pilet.json.`);
@@ -797,7 +783,7 @@ export async function retrievePiletData(target: string, app?: string) {
797
783
  const root = await findPiletRoot(proposedRoot);
798
784
  const piletPackage = await readJson(root, 'package.json');
799
785
  const piletDefinition: PiletDefinition = piletJsonPath && (await readJson(proposedRoot, piletJson));
800
- const appPackages = await findPiralInstances(app && [app], piletPackage, piletDefinition, target);
786
+ const appPackages = await findPiralInstances(app && [app], piletPackage, piletDefinition, root);
801
787
  const apps: Array<AppDefinition> = [];
802
788
 
803
789
  for (const appPackage of appPackages) {
@@ -1,24 +1,26 @@
1
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';
2
+ import { scaffoldFromEmulatorWebsite } from './website';
3
+ import { combinePackageRef, getPackageName, getPackageVersion } from './npm';
4
+ import { dissectPackageName, installNpmPackage, isLinkedPackage } from './npm';
5
+ import { NpmClientType, PiralInstanceDetails } from '../types';
11
6
 
12
7
  export async function installPiralInstance(
13
8
  usedSource: string,
14
9
  baseDir: string,
15
10
  rootDir: string,
16
11
  npmClient: NpmClientType,
17
- ): Promise<[name: string, version: string]> {
12
+ ): Promise<[name: string, version: string, details: PiralInstanceDetails]> {
18
13
  const [sourceName, sourceVersion, hadVersion, type] = await dissectPackageName(baseDir, usedSource);
19
- const isLocal = isLinkedPackage(sourceName, type, hadVersion, rootDir);
20
14
 
21
- if (!isLocal) {
15
+ if (type === 'remote') {
16
+ progress(`Downloading emulator from %s ...`, sourceName);
17
+ const emulatorJson = await scaffoldFromEmulatorWebsite(rootDir, sourceName);
18
+ const details = {
19
+ url: sourceName,
20
+ };
21
+
22
+ return [emulatorJson.name, emulatorJson.version, details];
23
+ } else if (!isLinkedPackage(sourceName, type, hadVersion, rootDir)) {
22
24
  const packageRef = combinePackageRef(sourceName, sourceVersion, type);
23
25
 
24
26
  progress(`Installing npm package %s ...`, packageRef);
@@ -29,6 +31,5 @@ export async function installPiralInstance(
29
31
 
30
32
  const packageName = await getPackageName(rootDir, sourceName, type);
31
33
  const packageVersion = getPackageVersion(hadVersion, sourceName, sourceVersion, type, rootDir);
32
-
33
- return [packageName, packageVersion];
34
+ return [packageName, packageVersion, {}];
34
35
  }