piral-cli 1.4.0-beta.6243 → 1.4.0-beta.6250
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.
- package/lib/apps/add-piral-instance-pilet.js +1 -6
- package/lib/apps/add-piral-instance-pilet.js.map +1 -1
- package/lib/apps/new-pilet.js +4 -2
- package/lib/apps/new-pilet.js.map +1 -1
- package/lib/apps/run-emulator-piral.js +4 -2
- package/lib/apps/run-emulator-piral.js.map +1 -1
- package/lib/apps/upgrade-pilet.js +3 -2
- package/lib/apps/upgrade-pilet.js.map +1 -1
- package/lib/build/bundler-calls.d.ts +2 -2
- package/lib/build/bundler-calls.js +4 -4
- package/lib/build/bundler-calls.js.map +1 -1
- package/lib/bundler.js +5 -5
- package/lib/bundler.js.map +1 -1
- package/lib/common/emulator.js +5 -4
- package/lib/common/emulator.js.map +1 -1
- package/lib/common/index.d.ts +1 -0
- package/lib/common/index.js +1 -0
- package/lib/common/index.js.map +1 -1
- package/lib/common/npm.d.ts +1 -0
- package/lib/common/npm.js +16 -4
- package/lib/common/npm.js.map +1 -1
- package/lib/common/package.d.ts +6 -4
- package/lib/common/package.js +42 -42
- package/lib/common/package.js.map +1 -1
- package/lib/common/shell.d.ts +1 -1
- package/lib/common/shell.js +48 -8
- package/lib/common/shell.js.map +1 -1
- package/lib/common/website.d.ts +1 -0
- package/lib/common/website.js +72 -0
- package/lib/common/website.js.map +1 -0
- package/lib/injectors/pilet-injector.d.ts +12 -10
- package/lib/injectors/pilet-injector.js +103 -60
- package/lib/injectors/pilet-injector.js.map +1 -1
- package/lib/injectors/piral-injector.d.ts +5 -5
- package/lib/injectors/piral-injector.js +64 -34
- package/lib/injectors/piral-injector.js.map +1 -1
- package/lib/types/common.d.ts +22 -0
- package/lib/types/common.js.map +1 -1
- package/lib/types/internal.d.ts +7 -4
- package/lib/types/public.d.ts +2 -1
- package/package.json +2 -2
- package/src/apps/add-piral-instance-pilet.ts +1 -15
- package/src/apps/new-pilet.ts +4 -9
- package/src/apps/run-emulator-piral.ts +4 -2
- package/src/apps/upgrade-pilet.ts +3 -2
- package/src/build/bundler-calls.ts +4 -4
- package/src/bundler.test.ts +5 -5
- package/src/bundler.ts +5 -5
- package/src/common/emulator.ts +28 -32
- package/src/common/index.ts +1 -0
- package/src/common/npm.ts +16 -3
- package/src/common/package.ts +37 -66
- package/src/common/shell.ts +62 -20
- package/src/common/website.ts +69 -0
- package/src/injectors/pilet-injector.test.ts +4 -4
- package/src/injectors/pilet-injector.ts +87 -41
- package/src/injectors/piral-injector.test.ts +2 -2
- package/src/injectors/piral-injector.ts +31 -20
- package/src/types/common.ts +24 -0
- package/src/types/internal.ts +8 -7
- package/src/types/public.ts +2 -1
|
@@ -107,6 +107,7 @@ export async function upgradePilet(baseDir = process.cwd(), options: UpgradePile
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
for (const { appPackage } of apps) {
|
|
110
|
+
//TODO distinguish if it's a website / remote emulator or an npm package
|
|
110
111
|
const sourceName = appPackage.name;
|
|
111
112
|
const language = /\.jsx?$/.test(source) ? 'js' : 'ts';
|
|
112
113
|
|
|
@@ -121,7 +122,7 @@ export async function upgradePilet(baseDir = process.cwd(), options: UpgradePile
|
|
|
121
122
|
}
|
|
122
123
|
|
|
123
124
|
const monorepoRef = await isMonorepoPackageRef(sourceName, fullBase);
|
|
124
|
-
const [packageRef
|
|
125
|
+
const [packageRef] = await getCurrentPackageDetails(
|
|
125
126
|
fullBase,
|
|
126
127
|
sourceName,
|
|
127
128
|
currentVersion,
|
|
@@ -162,7 +163,7 @@ export async function upgradePilet(baseDir = process.cwd(), options: UpgradePile
|
|
|
162
163
|
await copyScaffoldingFiles(packageRoot, root, notOnceFiles, piralInfo, data);
|
|
163
164
|
}
|
|
164
165
|
|
|
165
|
-
await patchPiletPackage(root,
|
|
166
|
+
await patchPiletPackage(root, piralInfo, isEmulator);
|
|
166
167
|
|
|
167
168
|
if (install) {
|
|
168
169
|
progress(`Updating dependencies ...`);
|
|
@@ -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',
|
package/src/bundler.test.ts
CHANGED
|
@@ -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);
|
package/src/common/emulator.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { ForceOverwrite } from './enums';
|
|
|
9
9
|
import { createTarball } from './archive';
|
|
10
10
|
import { createDirectory, removeDirectory, matchFiles, removeAny, getFileNames } from './io';
|
|
11
11
|
import { updateExistingJson, readJson, writeJson, createFileIfNotExists } from './io';
|
|
12
|
-
import { LogLevels, SharedDependency, PiletsInfo, TemplateFileLocation } from '../types';
|
|
12
|
+
import { EmulatorWebsiteManifest, LogLevels, SharedDependency, PiletsInfo, TemplateFileLocation } from '../types';
|
|
13
13
|
|
|
14
14
|
export async function createEmulatorSources(
|
|
15
15
|
sourceDir: string,
|
|
@@ -102,7 +102,7 @@ export async function createEmulatorSources(
|
|
|
102
102
|
},
|
|
103
103
|
main: `./${join(appDir, 'index.js')}`,
|
|
104
104
|
typings: `./${join(appDir, 'index.d.ts')}`,
|
|
105
|
-
app: `./${join(appDir, '
|
|
105
|
+
app: `./${join(appDir, 'index.html')}`,
|
|
106
106
|
peerDependencies: {},
|
|
107
107
|
optionalDependencies,
|
|
108
108
|
devDependencies: {
|
|
@@ -211,38 +211,34 @@ export async function createEmulatorWebsite(
|
|
|
211
211
|
}, {} as Record<string, string>);
|
|
212
212
|
|
|
213
213
|
const allFiles = await matchFiles(targetDir, '*');
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
optional: optionalDependencies,
|
|
238
|
-
included: {
|
|
239
|
-
...allDeps,
|
|
240
|
-
...externalDependencies,
|
|
241
|
-
},
|
|
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,
|
|
242
237
|
},
|
|
243
238
|
},
|
|
244
|
-
|
|
245
|
-
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
await writeJson(targetDir, 'emulator.json', data, true);
|
|
246
242
|
|
|
247
243
|
// generate the associated index.d.ts
|
|
248
244
|
await createPiralDeclaration(sourceDir, piralPkg.app ?? `./src/index.html`, targetDir, ForceOverwrite.yes, logLevel);
|
package/src/common/index.ts
CHANGED
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
|
|
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
|
|
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);
|
package/src/common/package.ts
CHANGED
|
@@ -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 {
|
|
14
|
+
import { scaffoldFromEmulatorWebsite } from './website';
|
|
15
15
|
import { getDependencies, getDependencyPackages, getDevDependencies } from './language';
|
|
16
16
|
import { getDevDependencyPackages, getFrameworkDependencies } from './language';
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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, filesTar, filesOnceTar, bundlerNames, packageJson } from './constants';
|
|
18
|
+
import { frameworkLibs, declarationEntryExtensions, piralJson, piletJson } 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
|
-
|
|
172
|
-
|
|
152
|
+
rootDir: string,
|
|
153
|
+
details?: PiralInstanceDetails,
|
|
173
154
|
): Promise<PiralInstancePackageData> {
|
|
174
|
-
const path = findPackageRoot(proposedApp,
|
|
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
|
-
|
|
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,
|
|
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,
|
|
209
|
+
return readJson(path, packageJson);
|
|
224
210
|
}
|
|
225
211
|
|
|
226
212
|
export async function patchPiralPackage(
|
|
@@ -230,11 +216,11 @@ export async function patchPiralPackage(
|
|
|
230
216
|
version: string,
|
|
231
217
|
bundler?: string,
|
|
232
218
|
) {
|
|
233
|
-
log('generalDebug_0003', `Patching the
|
|
219
|
+
log('generalDebug_0003', `Patching the ${packageJson} in "${root}" ...`);
|
|
234
220
|
const pkg = await getPiralPackage(app, data, version, bundler);
|
|
235
221
|
|
|
236
|
-
await updateExistingJson(root,
|
|
237
|
-
log('generalDebug_0003', `Succesfully patched the
|
|
222
|
+
await updateExistingJson(root, packageJson, pkg);
|
|
223
|
+
log('generalDebug_0003', `Succesfully patched the ${packageJson}.`);
|
|
238
224
|
|
|
239
225
|
await updateExistingJson(root, piralJson, {
|
|
240
226
|
$schema: piralJsonSchemaUrl,
|
|
@@ -367,7 +353,7 @@ export async function copyScaffoldingFiles(
|
|
|
367
353
|
}
|
|
368
354
|
|
|
369
355
|
async function extendPackageOverridesFromTemplateFragment(root: string, piralInfo: any, files: Array<FileDescriptor>) {
|
|
370
|
-
const packageTarget = resolve(root,
|
|
356
|
+
const packageTarget = resolve(root, packageJson);
|
|
371
357
|
|
|
372
358
|
for (let i = files.length; i--; ) {
|
|
373
359
|
const file = files[i];
|
|
@@ -398,7 +384,7 @@ function isTemplateFileLocation(item: string | TemplateFileLocation): item is Te
|
|
|
398
384
|
|
|
399
385
|
function tryFindPackageVersion(packageName: string): string {
|
|
400
386
|
try {
|
|
401
|
-
const { version } = require(`${packageName}
|
|
387
|
+
const { version } = require(`${packageName}/${packageJson}`);
|
|
402
388
|
return version;
|
|
403
389
|
} catch {
|
|
404
390
|
return undefined;
|
|
@@ -461,7 +447,7 @@ export async function retrievePiralRoot(baseDir: string, entry: string) {
|
|
|
461
447
|
log('generalDebug_0003', `Retrieving Piral root from "${rootDir}" ...`);
|
|
462
448
|
|
|
463
449
|
if (!declarationEntryExtensions.includes(extname(rootDir).toLowerCase())) {
|
|
464
|
-
const packageName = basename(rootDir) ===
|
|
450
|
+
const packageName = basename(rootDir) === packageJson ? rootDir : join(rootDir, packageJson);
|
|
465
451
|
log('generalDebug_0003', `Trying to get entry point from "${packageName}".`);
|
|
466
452
|
const exists = await checkExists(packageName);
|
|
467
453
|
|
|
@@ -541,9 +527,9 @@ export async function findPackageVersion(rootPath: string, packageName: string |
|
|
|
541
527
|
try {
|
|
542
528
|
log('generalDebug_0003', `Finding the version of "${packageName}" in "${rootPath}".`);
|
|
543
529
|
const moduleName = getModulePath(rootPath, pckg);
|
|
544
|
-
const
|
|
545
|
-
const root = dirname(
|
|
546
|
-
const { version } = await readJson(root,
|
|
530
|
+
const packageJsonPath = await findFile(moduleName, packageJson);
|
|
531
|
+
const root = dirname(packageJsonPath);
|
|
532
|
+
const { version } = await readJson(root, packageJson);
|
|
547
533
|
return version;
|
|
548
534
|
} catch {}
|
|
549
535
|
}
|
|
@@ -649,31 +635,18 @@ export function isValidDependency(name: string) {
|
|
|
649
635
|
|
|
650
636
|
export async function patchPiletPackage(
|
|
651
637
|
root: string,
|
|
652
|
-
name: string,
|
|
653
|
-
version: string,
|
|
654
638
|
piralInfo: PiralPackageData,
|
|
655
639
|
fromEmulator: boolean,
|
|
656
640
|
newInfo?: { language: SourceLanguage; bundler: string },
|
|
657
641
|
) {
|
|
658
|
-
log('generalDebug_0003', `Patching the
|
|
659
|
-
const pkg = await getPiletPackage(root,
|
|
660
|
-
|
|
642
|
+
log('generalDebug_0003', `Patching the ${packageJson} in "${root}" ...`);
|
|
643
|
+
const pkg = await getPiletPackage(root, piralInfo, fromEmulator, newInfo);
|
|
661
644
|
await updateExistingJson(root, packageJson, pkg);
|
|
662
|
-
log('generalDebug_0003', `Succesfully patched the
|
|
663
|
-
|
|
664
|
-
await updateExistingJson(root, piletJson, {
|
|
665
|
-
$schema: piletJsonSchemaUrl,
|
|
666
|
-
piralInstances: {
|
|
667
|
-
[name]: {},
|
|
668
|
-
},
|
|
669
|
-
});
|
|
670
|
-
log('generalDebug_0003', `Succesfully patched the pilet.json.`);
|
|
645
|
+
log('generalDebug_0003', `Succesfully patched the ${packageJson}.`);
|
|
671
646
|
}
|
|
672
647
|
|
|
673
648
|
async function getPiletPackage(
|
|
674
649
|
root: string,
|
|
675
|
-
name: string,
|
|
676
|
-
version: string,
|
|
677
650
|
piralInfo: PiralPackageData,
|
|
678
651
|
fromEmulator: boolean,
|
|
679
652
|
newInfo?: { language: SourceLanguage; bundler: string },
|
|
@@ -715,11 +688,9 @@ async function getPiletPackage(
|
|
|
715
688
|
|
|
716
689
|
return deps;
|
|
717
690
|
}, {}),
|
|
718
|
-
[name]: `${version || piralInfo.version}`,
|
|
719
691
|
['piral-cli']: toolVersion,
|
|
720
692
|
};
|
|
721
693
|
const dependencies: Record<string, string> = {
|
|
722
|
-
[name]: undefined,
|
|
723
694
|
['piral-cli']: undefined,
|
|
724
695
|
};
|
|
725
696
|
|
|
@@ -730,7 +701,7 @@ async function getPiletPackage(
|
|
|
730
701
|
return deepMerge(packageOverrides, {
|
|
731
702
|
importmap: {
|
|
732
703
|
imports: {},
|
|
733
|
-
inherit: [
|
|
704
|
+
inherit: [],
|
|
734
705
|
},
|
|
735
706
|
devDependencies,
|
|
736
707
|
dependencies,
|
|
@@ -782,22 +753,22 @@ export function combinePiletExternals(
|
|
|
782
753
|
}
|
|
783
754
|
|
|
784
755
|
export async function findPiletRoot(proposedRoot: string) {
|
|
785
|
-
const
|
|
756
|
+
const packageJsonPath = await findFile(proposedRoot, packageJson);
|
|
786
757
|
|
|
787
|
-
if (!
|
|
758
|
+
if (!packageJsonPath) {
|
|
788
759
|
fail('packageJsonMissing_0075');
|
|
789
760
|
}
|
|
790
761
|
|
|
791
|
-
return dirname(
|
|
762
|
+
return dirname(packageJsonPath);
|
|
792
763
|
}
|
|
793
764
|
|
|
794
765
|
export async function retrievePiletData(target: string, app?: string) {
|
|
795
766
|
const piletJsonPath = await findFile(target, piletJson);
|
|
796
767
|
const proposedRoot = piletJsonPath ? dirname(piletJsonPath) : target;
|
|
797
768
|
const root = await findPiletRoot(proposedRoot);
|
|
798
|
-
const piletPackage = await readJson(root,
|
|
769
|
+
const piletPackage = await readJson(root, packageJson);
|
|
799
770
|
const piletDefinition: PiletDefinition = piletJsonPath && (await readJson(proposedRoot, piletJson));
|
|
800
|
-
const appPackages = await findPiralInstances(app && [app], piletPackage, piletDefinition,
|
|
771
|
+
const appPackages = await findPiralInstances(app && [app], piletPackage, piletDefinition, root);
|
|
801
772
|
const apps: Array<AppDefinition> = [];
|
|
802
773
|
|
|
803
774
|
for (const appPackage of appPackages) {
|
package/src/common/shell.ts
CHANGED
|
@@ -1,34 +1,76 @@
|
|
|
1
1
|
import { progress } from './log';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
isLinkedPackage,
|
|
9
|
-
} from './npm';
|
|
10
|
-
import { NpmClientType } from '../types';
|
|
2
|
+
import { packageJson, piletJson } from './constants';
|
|
3
|
+
import { readJson, updateExistingJson, writeJson } from './io';
|
|
4
|
+
import { scaffoldFromEmulatorWebsite } from './website';
|
|
5
|
+
import { combinePackageRef, getPackageName, getPackageVersion } from './npm';
|
|
6
|
+
import { dissectPackageName, installNpmPackage, isLinkedPackage } from './npm';
|
|
7
|
+
import { NpmClientType, PackageType, PiralInstanceDetails } from '../types';
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
async function updatePiletJson(target: string, appName: string, appDetails: PiralInstanceDetails) {
|
|
10
|
+
const oldContent = await readJson(target, piletJson);
|
|
11
|
+
const newContent = {
|
|
12
|
+
...oldContent,
|
|
13
|
+
piralInstances: {
|
|
14
|
+
...oldContent.piralInstances,
|
|
15
|
+
[appName]: appDetails,
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
await writeJson(target, piletJson, newContent, true);
|
|
19
|
+
await updateExistingJson(target, packageJson, {
|
|
20
|
+
importmap: {
|
|
21
|
+
inherit: [appName],
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function setupPiralInstance(
|
|
27
|
+
sourceName: string,
|
|
28
|
+
type: PackageType,
|
|
29
|
+
hadVersion: boolean,
|
|
15
30
|
rootDir: string,
|
|
31
|
+
sourceVersion: string,
|
|
16
32
|
npmClient: NpmClientType,
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
const isLocal = isLinkedPackage(sourceName, type, hadVersion, rootDir);
|
|
20
|
-
|
|
21
|
-
if (!isLocal) {
|
|
33
|
+
) {
|
|
34
|
+
if (!isLinkedPackage(sourceName, type, hadVersion, rootDir)) {
|
|
22
35
|
const packageRef = combinePackageRef(sourceName, sourceVersion, type);
|
|
23
36
|
|
|
24
37
|
progress(`Installing npm package %s ...`, packageRef);
|
|
25
38
|
await installNpmPackage(npmClient, packageRef, rootDir, '--save-dev', '--save-exact');
|
|
39
|
+
return await getPackageName(rootDir, sourceName, type);
|
|
26
40
|
} else {
|
|
27
41
|
progress(`Using locally available npm package %s ...`, sourceName);
|
|
42
|
+
const packageName = await getPackageName(rootDir, sourceName, type);
|
|
43
|
+
const packageVersion = getPackageVersion(hadVersion, sourceName, sourceVersion, type, rootDir);
|
|
44
|
+
await updateExistingJson(rootDir, packageJson, {
|
|
45
|
+
devDependencies: {
|
|
46
|
+
[packageName]: packageVersion,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
return packageName;
|
|
28
50
|
}
|
|
51
|
+
}
|
|
29
52
|
|
|
30
|
-
|
|
31
|
-
|
|
53
|
+
export async function installPiralInstance(
|
|
54
|
+
usedSource: string,
|
|
55
|
+
baseDir: string,
|
|
56
|
+
rootDir: string,
|
|
57
|
+
npmClient: NpmClientType,
|
|
58
|
+
selected?: boolean,
|
|
59
|
+
): Promise<string> {
|
|
60
|
+
const [sourceName, sourceVersion, hadVersion, type] = await dissectPackageName(baseDir, usedSource);
|
|
32
61
|
|
|
33
|
-
|
|
62
|
+
if (type === 'remote') {
|
|
63
|
+
const packageName = await scaffoldFromEmulatorWebsite(rootDir, sourceName);
|
|
64
|
+
await updatePiletJson(rootDir, packageName, {
|
|
65
|
+
selected,
|
|
66
|
+
url: sourceName,
|
|
67
|
+
});
|
|
68
|
+
return packageName;
|
|
69
|
+
} else {
|
|
70
|
+
const packageName = await setupPiralInstance(sourceName, type, hadVersion, rootDir, sourceVersion, npmClient);
|
|
71
|
+
await updatePiletJson(rootDir, packageName, {
|
|
72
|
+
selected,
|
|
73
|
+
});
|
|
74
|
+
return packageName;
|
|
75
|
+
}
|
|
34
76
|
}
|