piral-cli 1.4.0-beta.6247 → 1.4.0-beta.6252
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/api.js +8 -17
- package/lib/api.js.map +1 -1
- package/lib/apps/add-piral-instance-pilet.js +20 -34
- package/lib/apps/add-piral-instance-pilet.js.map +1 -1
- package/lib/apps/build-pilet.js +139 -147
- package/lib/apps/build-pilet.js.map +1 -1
- package/lib/apps/build-piral.js +130 -144
- package/lib/apps/build-piral.js.map +1 -1
- package/lib/apps/debug-pilet.js +107 -119
- package/lib/apps/debug-pilet.js.map +1 -1
- package/lib/apps/debug-piral.js +62 -70
- package/lib/apps/debug-piral.js.map +1 -1
- package/lib/apps/declaration-piral.js +6 -17
- package/lib/apps/declaration-piral.js.map +1 -1
- package/lib/apps/new-pilet.js +71 -81
- package/lib/apps/new-pilet.js.map +1 -1
- package/lib/apps/new-piral.js +42 -53
- package/lib/apps/new-piral.js.map +1 -1
- package/lib/apps/pack-pilet.js +7 -18
- package/lib/apps/pack-pilet.js.map +1 -1
- package/lib/apps/publish-pilet.js +127 -141
- package/lib/apps/publish-pilet.js.map +1 -1
- package/lib/apps/publish-piral.js +48 -63
- package/lib/apps/publish-piral.js.map +1 -1
- package/lib/apps/remove-piral-instance-pilet.js +30 -35
- package/lib/apps/remove-piral-instance-pilet.js.map +1 -1
- package/lib/apps/run-emulator-piral.js +49 -61
- package/lib/apps/run-emulator-piral.js.map +1 -1
- package/lib/apps/upgrade-pilet.js +64 -75
- package/lib/apps/upgrade-pilet.js.map +1 -1
- package/lib/apps/upgrade-piral.js +31 -43
- package/lib/apps/upgrade-piral.js.map +1 -1
- package/lib/apps/validate-pilet.js +34 -45
- package/lib/apps/validate-pilet.js.map +1 -1
- package/lib/apps/validate-piral.js +29 -51
- package/lib/apps/validate-piral.js.map +1 -1
- package/lib/build/bundler-calls.js +12 -3
- package/lib/build/bundler-calls.js.map +1 -1
- package/lib/build/run-build-pilet.js +5 -14
- package/lib/build/run-build-pilet.js.map +1 -1
- package/lib/build/run-build-piral.js +5 -14
- package/lib/build/run-build-piral.js.map +1 -1
- package/lib/build/run-debug-mono-piral.js +5 -14
- package/lib/build/run-debug-mono-piral.js.map +1 -1
- package/lib/build/run-debug-pilet.js +5 -14
- package/lib/build/run-debug-pilet.js.map +1 -1
- package/lib/build/run-debug-piral.js +5 -14
- package/lib/build/run-debug-piral.js.map +1 -1
- package/lib/bundler.js +100 -127
- package/lib/bundler.js.map +1 -1
- package/lib/commands.js +5 -1
- package/lib/commands.js.map +1 -1
- package/lib/common/browser.js +13 -26
- package/lib/common/browser.js.map +1 -1
- package/lib/common/compatibility.js +10 -21
- package/lib/common/compatibility.js.map +1 -1
- package/lib/common/declaration.js +80 -101
- package/lib/common/declaration.js.map +1 -1
- package/lib/common/emulator.js +186 -182
- package/lib/common/emulator.js.map +1 -1
- package/lib/common/http.js +7 -4
- package/lib/common/http.js.map +1 -1
- package/lib/common/importmap.js +172 -187
- package/lib/common/importmap.js.map +1 -1
- package/lib/common/injectors.js +4 -1
- package/lib/common/injectors.js.map +1 -1
- package/lib/common/inspect.js +5 -2
- package/lib/common/inspect.js.map +1 -1
- package/lib/common/interactive.js +9 -15
- package/lib/common/interactive.js.map +1 -1
- package/lib/common/io.js +256 -299
- package/lib/common/io.js.map +1 -1
- package/lib/common/language.js +21 -5
- package/lib/common/language.js.map +1 -1
- package/lib/common/npm.js +193 -228
- package/lib/common/npm.js.map +1 -1
- package/lib/common/pack.js +71 -86
- package/lib/common/pack.js.map +1 -1
- package/lib/common/package.d.ts +1 -2
- package/lib/common/package.js +428 -458
- package/lib/common/package.js.map +1 -1
- package/lib/common/parallel.js +12 -23
- package/lib/common/parallel.js.map +1 -1
- package/lib/common/patcher.js +54 -71
- package/lib/common/patcher.js.map +1 -1
- package/lib/common/platform.js +1 -12
- package/lib/common/platform.js.map +1 -1
- package/lib/common/port.js +11 -24
- package/lib/common/port.js.map +1 -1
- package/lib/common/rules.js +6 -17
- package/lib/common/rules.js.map +1 -1
- package/lib/common/scaffold.js +52 -59
- package/lib/common/scaffold.js.map +1 -1
- package/lib/common/shell.d.ts +2 -2
- package/lib/common/shell.js +53 -31
- package/lib/common/shell.js.map +1 -1
- package/lib/common/spec.js +1 -1
- package/lib/common/spec.js.map +1 -1
- package/lib/common/template.js +3 -14
- package/lib/common/template.js.map +1 -1
- package/lib/common/watcher.js +7 -16
- package/lib/common/watcher.js.map +1 -1
- package/lib/common/website.d.ts +2 -2
- package/lib/common/website.js +68 -56
- package/lib/common/website.js.map +1 -1
- package/lib/injectors/pilet-injector.d.ts +12 -10
- package/lib/injectors/pilet-injector.js +123 -87
- package/lib/injectors/pilet-injector.js.map +1 -1
- package/lib/injectors/piral-injector.d.ts +5 -5
- package/lib/injectors/piral-injector.js +32 -14
- package/lib/injectors/piral-injector.js.map +1 -1
- package/lib/messages.d.ts +81 -0
- package/lib/messages.js +94 -1
- package/lib/messages.js.map +1 -1
- package/lib/npm-clients/bun.js +36 -60
- package/lib/npm-clients/bun.js.map +1 -1
- package/lib/npm-clients/index.js +10 -21
- package/lib/npm-clients/index.js.map +1 -1
- package/lib/npm-clients/lerna.js +48 -72
- package/lib/npm-clients/lerna.js.map +1 -1
- package/lib/npm-clients/npm.js +69 -105
- package/lib/npm-clients/npm.js.map +1 -1
- package/lib/npm-clients/pnp.js +35 -59
- package/lib/npm-clients/pnp.js.map +1 -1
- package/lib/npm-clients/pnpm.js +35 -59
- package/lib/npm-clients/pnpm.js.map +1 -1
- package/lib/npm-clients/rush.js +53 -77
- package/lib/npm-clients/rush.js.map +1 -1
- package/lib/npm-clients/yarn.js +35 -59
- package/lib/npm-clients/yarn.js.map +1 -1
- package/lib/platforms/node.js +4 -17
- package/lib/platforms/node.js.map +1 -1
- package/lib/platforms/web.js +81 -96
- package/lib/platforms/web.js.map +1 -1
- package/lib/plugin.js +56 -75
- package/lib/plugin.js.map +1 -1
- package/lib/questionnaire.js +46 -12
- package/lib/questionnaire.js.map +1 -1
- package/lib/release.js +32 -47
- package/lib/release.js.map +1 -1
- package/lib/rules/index.js +10 -23
- package/lib/rules/index.js.map +1 -1
- package/lib/rules/pilet-has-externals-as-peers.js +34 -45
- package/lib/rules/pilet-has-externals-as-peers.js.map +1 -1
- package/lib/rules/pilet-has-no-self-reference.js +16 -27
- package/lib/rules/pilet-has-no-self-reference.js.map +1 -1
- package/lib/rules/pilet-has-non-conflicting-css.js +27 -42
- package/lib/rules/pilet-has-non-conflicting-css.js.map +1 -1
- package/lib/rules/pilet-stays-small.js +20 -33
- package/lib/rules/pilet-stays-small.js.map +1 -1
- package/lib/rules/pilet-uses-latest-piral.js +17 -28
- package/lib/rules/pilet-uses-latest-piral.js.map +1 -1
- package/lib/rules/piral-has-valid-devDependencies.js +4 -1
- package/lib/rules/piral-has-valid-devDependencies.js.map +1 -1
- package/lib/runner.js +3 -12
- package/lib/runner.js.map +1 -1
- package/lib/select.js +21 -32
- package/lib/select.js.map +1 -1
- package/lib/start.js +6 -17
- package/lib/start.js.map +1 -1
- package/package.json +2 -2
- package/src/apps/add-piral-instance-pilet.ts +1 -16
- package/src/apps/build-piral.test.ts +1 -1
- package/src/apps/new-pilet.ts +4 -10
- package/src/apps/run-emulator-piral.ts +1 -1
- package/src/apps/upgrade-pilet.ts +3 -2
- package/src/common/package.ts +29 -37
- package/src/common/shell.ts +59 -18
- package/src/common/website.ts +47 -17
- package/src/injectors/pilet-injector.test.ts +4 -4
- package/src/injectors/pilet-injector.ts +97 -41
- package/src/injectors/piral-injector.test.ts +2 -2
- package/src/injectors/piral-injector.ts +31 -20
- package/src/messages.ts +93 -0
|
@@ -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 ...`);
|
package/src/common/package.ts
CHANGED
|
@@ -11,11 +11,11 @@ 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 { scaffoldFromEmulatorWebsite } from './website';
|
|
14
|
+
import { scaffoldFromEmulatorWebsite, updateFromEmulatorWebsite } from './website';
|
|
15
15
|
import { getDependencies, getDependencyPackages, getDevDependencies } from './language';
|
|
16
16
|
import { getDevDependencyPackages, getFrameworkDependencies } from './language';
|
|
17
|
-
import { piralJsonSchemaUrl,
|
|
18
|
-
import { frameworkLibs, declarationEntryExtensions, piralJson, piletJson
|
|
17
|
+
import { piralJsonSchemaUrl, filesTar, filesOnceTar, bundlerNames, packageJson } from './constants';
|
|
18
|
+
import { frameworkLibs, declarationEntryExtensions, piralJson, piletJson } from './constants';
|
|
19
19
|
import { getModulePath } from '../external';
|
|
20
20
|
import { PiletsInfo, SharedDependency, PiletDefinition, AppDefinition } from '../types';
|
|
21
21
|
import { SourceLanguage, PiralInstancePackageData, PiralInstanceDetails } from '../types';
|
|
@@ -156,12 +156,19 @@ export async function findPiralInstance(
|
|
|
156
156
|
|
|
157
157
|
if (path) {
|
|
158
158
|
log('generalDebug_0003', `Following the app package in "${path}" ...`);
|
|
159
|
+
const url = details?.url;
|
|
159
160
|
const root = dirname(path);
|
|
160
161
|
const appPackage = await readJson(root, basename(path));
|
|
161
|
-
const relPath = appPackage
|
|
162
|
+
const relPath = appPackage.app;
|
|
162
163
|
appPackage.app = relPath && resolve(root, relPath);
|
|
163
164
|
appPackage.root = root;
|
|
164
165
|
appPackage.port = details?.port || 0;
|
|
166
|
+
|
|
167
|
+
if (url) {
|
|
168
|
+
log('generalDebug_0003', `Updating the emulator from remote "${url}" ...`);
|
|
169
|
+
await updateFromEmulatorWebsite(root, url);
|
|
170
|
+
}
|
|
171
|
+
|
|
165
172
|
return appPackage;
|
|
166
173
|
} else if (details?.url) {
|
|
167
174
|
const { url, ...rest } = details;
|
|
@@ -216,11 +223,11 @@ export async function patchPiralPackage(
|
|
|
216
223
|
version: string,
|
|
217
224
|
bundler?: string,
|
|
218
225
|
) {
|
|
219
|
-
log('generalDebug_0003', `Patching the
|
|
226
|
+
log('generalDebug_0003', `Patching the ${packageJson} in "${root}" ...`);
|
|
220
227
|
const pkg = await getPiralPackage(app, data, version, bundler);
|
|
221
228
|
|
|
222
|
-
await updateExistingJson(root,
|
|
223
|
-
log('generalDebug_0003', `Succesfully patched the
|
|
229
|
+
await updateExistingJson(root, packageJson, pkg);
|
|
230
|
+
log('generalDebug_0003', `Succesfully patched the ${packageJson}.`);
|
|
224
231
|
|
|
225
232
|
await updateExistingJson(root, piralJson, {
|
|
226
233
|
$schema: piralJsonSchemaUrl,
|
|
@@ -353,7 +360,7 @@ export async function copyScaffoldingFiles(
|
|
|
353
360
|
}
|
|
354
361
|
|
|
355
362
|
async function extendPackageOverridesFromTemplateFragment(root: string, piralInfo: any, files: Array<FileDescriptor>) {
|
|
356
|
-
const packageTarget = resolve(root,
|
|
363
|
+
const packageTarget = resolve(root, packageJson);
|
|
357
364
|
|
|
358
365
|
for (let i = files.length; i--; ) {
|
|
359
366
|
const file = files[i];
|
|
@@ -384,7 +391,7 @@ function isTemplateFileLocation(item: string | TemplateFileLocation): item is Te
|
|
|
384
391
|
|
|
385
392
|
function tryFindPackageVersion(packageName: string): string {
|
|
386
393
|
try {
|
|
387
|
-
const { version } = require(`${packageName}
|
|
394
|
+
const { version } = require(`${packageName}/${packageJson}`);
|
|
388
395
|
return version;
|
|
389
396
|
} catch {
|
|
390
397
|
return undefined;
|
|
@@ -447,7 +454,7 @@ export async function retrievePiralRoot(baseDir: string, entry: string) {
|
|
|
447
454
|
log('generalDebug_0003', `Retrieving Piral root from "${rootDir}" ...`);
|
|
448
455
|
|
|
449
456
|
if (!declarationEntryExtensions.includes(extname(rootDir).toLowerCase())) {
|
|
450
|
-
const packageName = basename(rootDir) ===
|
|
457
|
+
const packageName = basename(rootDir) === packageJson ? rootDir : join(rootDir, packageJson);
|
|
451
458
|
log('generalDebug_0003', `Trying to get entry point from "${packageName}".`);
|
|
452
459
|
const exists = await checkExists(packageName);
|
|
453
460
|
|
|
@@ -527,9 +534,9 @@ export async function findPackageVersion(rootPath: string, packageName: string |
|
|
|
527
534
|
try {
|
|
528
535
|
log('generalDebug_0003', `Finding the version of "${packageName}" in "${rootPath}".`);
|
|
529
536
|
const moduleName = getModulePath(rootPath, pckg);
|
|
530
|
-
const
|
|
531
|
-
const root = dirname(
|
|
532
|
-
const { version } = await readJson(root,
|
|
537
|
+
const packageJsonPath = await findFile(moduleName, packageJson);
|
|
538
|
+
const root = dirname(packageJsonPath);
|
|
539
|
+
const { version } = await readJson(root, packageJson);
|
|
533
540
|
return version;
|
|
534
541
|
} catch {}
|
|
535
542
|
}
|
|
@@ -635,31 +642,18 @@ export function isValidDependency(name: string) {
|
|
|
635
642
|
|
|
636
643
|
export async function patchPiletPackage(
|
|
637
644
|
root: string,
|
|
638
|
-
name: string,
|
|
639
|
-
version: string,
|
|
640
645
|
piralInfo: PiralPackageData,
|
|
641
646
|
fromEmulator: boolean,
|
|
642
|
-
newInfo?: { language: SourceLanguage; bundler: string
|
|
647
|
+
newInfo?: { language: SourceLanguage; bundler: string },
|
|
643
648
|
) {
|
|
644
|
-
log('generalDebug_0003', `Patching the
|
|
645
|
-
const pkg = await getPiletPackage(root,
|
|
646
|
-
|
|
649
|
+
log('generalDebug_0003', `Patching the ${packageJson} in "${root}" ...`);
|
|
650
|
+
const pkg = await getPiletPackage(root, piralInfo, fromEmulator, newInfo);
|
|
647
651
|
await updateExistingJson(root, packageJson, pkg);
|
|
648
|
-
log('generalDebug_0003', `Succesfully patched the
|
|
649
|
-
|
|
650
|
-
await updateExistingJson(root, piletJson, {
|
|
651
|
-
$schema: piletJsonSchemaUrl,
|
|
652
|
-
piralInstances: {
|
|
653
|
-
[name]: newInfo?.details || {},
|
|
654
|
-
},
|
|
655
|
-
});
|
|
656
|
-
log('generalDebug_0003', `Succesfully patched the pilet.json.`);
|
|
652
|
+
log('generalDebug_0003', `Succesfully patched the ${packageJson}.`);
|
|
657
653
|
}
|
|
658
654
|
|
|
659
655
|
async function getPiletPackage(
|
|
660
656
|
root: string,
|
|
661
|
-
name: string,
|
|
662
|
-
version: string,
|
|
663
657
|
piralInfo: PiralPackageData,
|
|
664
658
|
fromEmulator: boolean,
|
|
665
659
|
newInfo?: { language: SourceLanguage; bundler: string },
|
|
@@ -701,11 +695,9 @@ async function getPiletPackage(
|
|
|
701
695
|
|
|
702
696
|
return deps;
|
|
703
697
|
}, {}),
|
|
704
|
-
[name]: `${version || piralInfo.version}`,
|
|
705
698
|
['piral-cli']: toolVersion,
|
|
706
699
|
};
|
|
707
700
|
const dependencies: Record<string, string> = {
|
|
708
|
-
[name]: undefined,
|
|
709
701
|
['piral-cli']: undefined,
|
|
710
702
|
};
|
|
711
703
|
|
|
@@ -716,7 +708,7 @@ async function getPiletPackage(
|
|
|
716
708
|
return deepMerge(packageOverrides, {
|
|
717
709
|
importmap: {
|
|
718
710
|
imports: {},
|
|
719
|
-
inherit: [
|
|
711
|
+
inherit: [],
|
|
720
712
|
},
|
|
721
713
|
devDependencies,
|
|
722
714
|
dependencies,
|
|
@@ -768,20 +760,20 @@ export function combinePiletExternals(
|
|
|
768
760
|
}
|
|
769
761
|
|
|
770
762
|
export async function findPiletRoot(proposedRoot: string) {
|
|
771
|
-
const
|
|
763
|
+
const packageJsonPath = await findFile(proposedRoot, packageJson);
|
|
772
764
|
|
|
773
|
-
if (!
|
|
765
|
+
if (!packageJsonPath) {
|
|
774
766
|
fail('packageJsonMissing_0075');
|
|
775
767
|
}
|
|
776
768
|
|
|
777
|
-
return dirname(
|
|
769
|
+
return dirname(packageJsonPath);
|
|
778
770
|
}
|
|
779
771
|
|
|
780
772
|
export async function retrievePiletData(target: string, app?: string) {
|
|
781
773
|
const piletJsonPath = await findFile(target, piletJson);
|
|
782
774
|
const proposedRoot = piletJsonPath ? dirname(piletJsonPath) : target;
|
|
783
775
|
const root = await findPiletRoot(proposedRoot);
|
|
784
|
-
const piletPackage = await readJson(root,
|
|
776
|
+
const piletPackage = await readJson(root, packageJson);
|
|
785
777
|
const piletDefinition: PiletDefinition = piletJsonPath && (await readJson(proposedRoot, piletJson));
|
|
786
778
|
const appPackages = await findPiralInstances(app && [app], piletPackage, piletDefinition, root);
|
|
787
779
|
const apps: Array<AppDefinition> = [];
|
package/src/common/shell.ts
CHANGED
|
@@ -1,35 +1,76 @@
|
|
|
1
1
|
import { progress } from './log';
|
|
2
|
+
import { packageJson, piletJson } from './constants';
|
|
3
|
+
import { readJson, updateExistingJson, writeJson } from './io';
|
|
2
4
|
import { scaffoldFromEmulatorWebsite } from './website';
|
|
3
5
|
import { combinePackageRef, getPackageName, getPackageVersion } from './npm';
|
|
4
6
|
import { dissectPackageName, installNpmPackage, isLinkedPackage } from './npm';
|
|
5
|
-
import { NpmClientType, PiralInstanceDetails } from '../types';
|
|
7
|
+
import { NpmClientType, PackageType, PiralInstanceDetails } from '../types';
|
|
8
|
+
|
|
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,
|
|
30
|
+
rootDir: string,
|
|
31
|
+
sourceVersion: string,
|
|
32
|
+
npmClient: NpmClientType,
|
|
33
|
+
) {
|
|
34
|
+
if (!isLinkedPackage(sourceName, type, hadVersion, rootDir)) {
|
|
35
|
+
const packageRef = combinePackageRef(sourceName, sourceVersion, type);
|
|
36
|
+
|
|
37
|
+
progress(`Installing npm package %s ...`, packageRef);
|
|
38
|
+
await installNpmPackage(npmClient, packageRef, rootDir, '--save-dev', '--save-exact');
|
|
39
|
+
return await getPackageName(rootDir, sourceName, type);
|
|
40
|
+
} else {
|
|
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;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
6
52
|
|
|
7
53
|
export async function installPiralInstance(
|
|
8
54
|
usedSource: string,
|
|
9
55
|
baseDir: string,
|
|
10
56
|
rootDir: string,
|
|
11
57
|
npmClient: NpmClientType,
|
|
12
|
-
|
|
58
|
+
selected?: boolean,
|
|
59
|
+
): Promise<string> {
|
|
13
60
|
const [sourceName, sourceVersion, hadVersion, type] = await dissectPackageName(baseDir, usedSource);
|
|
14
61
|
|
|
15
62
|
if (type === 'remote') {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
63
|
+
const packageName = await scaffoldFromEmulatorWebsite(rootDir, sourceName);
|
|
64
|
+
await updatePiletJson(rootDir, packageName, {
|
|
65
|
+
selected,
|
|
19
66
|
url: sourceName,
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
return [emulatorJson.name, emulatorJson.version, details];
|
|
23
|
-
} else if (!isLinkedPackage(sourceName, type, hadVersion, rootDir)) {
|
|
24
|
-
const packageRef = combinePackageRef(sourceName, sourceVersion, type);
|
|
25
|
-
|
|
26
|
-
progress(`Installing npm package %s ...`, packageRef);
|
|
27
|
-
await installNpmPackage(npmClient, packageRef, rootDir, '--save-dev', '--save-exact');
|
|
67
|
+
});
|
|
68
|
+
return packageName;
|
|
28
69
|
} else {
|
|
29
|
-
|
|
70
|
+
const packageName = await setupPiralInstance(sourceName, type, hadVersion, rootDir, sourceVersion, npmClient);
|
|
71
|
+
await updatePiletJson(rootDir, packageName, {
|
|
72
|
+
selected,
|
|
73
|
+
});
|
|
74
|
+
return packageName;
|
|
30
75
|
}
|
|
31
|
-
|
|
32
|
-
const packageName = await getPackageName(rootDir, sourceName, type);
|
|
33
|
-
const packageVersion = getPackageVersion(hadVersion, sourceName, sourceVersion, type, rootDir);
|
|
34
|
-
return [packageName, packageVersion, {}];
|
|
35
76
|
}
|
package/src/common/website.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { join, resolve } from 'path';
|
|
1
|
+
import { join, relative, resolve } from 'path';
|
|
3
2
|
import { createPiralStubIndexIfNotExists } from './template';
|
|
4
3
|
import { packageJson } from './constants';
|
|
5
4
|
import { ForceOverwrite } from './enums';
|
|
6
|
-
import { createDirectory, writeBinary } from './io';
|
|
5
|
+
import { createDirectory, readJson, writeBinary } from './io';
|
|
7
6
|
import { writeJson } from './io';
|
|
7
|
+
import { progress, log } from './log';
|
|
8
8
|
import { axios } from '../external';
|
|
9
9
|
import { EmulatorWebsiteManifestFiles, EmulatorWebsiteManifest } from '../types';
|
|
10
10
|
|
|
@@ -13,22 +13,22 @@ async function downloadEmulatorFiles(manifestUrl: string, target: string, files:
|
|
|
13
13
|
|
|
14
14
|
await Promise.all(
|
|
15
15
|
requiredFiles.map(async (file) => {
|
|
16
|
-
const
|
|
16
|
+
const url = new URL(file, manifestUrl);
|
|
17
|
+
const res = await axios.default.get(url.href, { responseType: 'arraybuffer' });
|
|
17
18
|
const data: Buffer = res.data;
|
|
18
19
|
await writeBinary(target, file, data);
|
|
19
20
|
}),
|
|
20
21
|
);
|
|
21
22
|
}
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
async function createEmulatorFiles(
|
|
25
|
+
targetDir: string,
|
|
26
|
+
appDir: string,
|
|
27
|
+
manifestUrl: string,
|
|
28
|
+
emulatorJson: EmulatorWebsiteManifest,
|
|
29
|
+
) {
|
|
29
30
|
const mainFile = 'index.js';
|
|
30
|
-
const
|
|
31
|
-
await createDirectory(appDir);
|
|
31
|
+
const appDirName = relative(targetDir, appDir);
|
|
32
32
|
|
|
33
33
|
await writeJson(
|
|
34
34
|
targetDir,
|
|
@@ -45,10 +45,10 @@ export async function scaffoldFromEmulatorWebsite(rootDir: string, manifestUrl:
|
|
|
45
45
|
source: manifestUrl,
|
|
46
46
|
generated: true,
|
|
47
47
|
},
|
|
48
|
-
files: emulatorJson.files,
|
|
49
|
-
main:
|
|
50
|
-
typings:
|
|
51
|
-
app:
|
|
48
|
+
files: emulatorJson.files.assets,
|
|
49
|
+
main: join(appDirName, mainFile),
|
|
50
|
+
typings: join(appDirName, emulatorJson.files.typings),
|
|
51
|
+
app: join(appDirName, emulatorJson.files.app),
|
|
52
52
|
peerDependencies: {},
|
|
53
53
|
optionalDependencies: emulatorJson.dependencies.optional,
|
|
54
54
|
devDependencies: emulatorJson.dependencies.included,
|
|
@@ -63,5 +63,35 @@ export async function scaffoldFromEmulatorWebsite(rootDir: string, manifestUrl:
|
|
|
63
63
|
});
|
|
64
64
|
|
|
65
65
|
await downloadEmulatorFiles(manifestUrl, appDir, emulatorJson.files);
|
|
66
|
-
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function updateFromEmulatorWebsite(targetDir: string, manifestUrl: string) {
|
|
69
|
+
progress(`Updating emulator from %s ...`, manifestUrl);
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
const response = await axios.default.get(manifestUrl);
|
|
73
|
+
const nextEmulator: EmulatorWebsiteManifest = response.data;
|
|
74
|
+
const currentEmulator = await readJson(targetDir, packageJson);
|
|
75
|
+
|
|
76
|
+
if (currentEmulator.name !== nextEmulator.name) {
|
|
77
|
+
log('remoteEmulatorNameChanged_0121', currentEmulator.name);
|
|
78
|
+
} else if (currentEmulator.piralCLI.timstamp !== nextEmulator.timestamp) {
|
|
79
|
+
const appDir = resolve(targetDir, 'app');
|
|
80
|
+
await createEmulatorFiles(targetDir, appDir, manifestUrl, nextEmulator);
|
|
81
|
+
}
|
|
82
|
+
} catch (ex) {
|
|
83
|
+
log('generalDebug_0003', `HTTP request for emulator update failed: ${ex}`);
|
|
84
|
+
log('skipEmulatorUpdate_0120', manifestUrl);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export async function scaffoldFromEmulatorWebsite(rootDir: string, manifestUrl: string) {
|
|
89
|
+
progress(`Downloading emulator from %s ...`, manifestUrl);
|
|
90
|
+
const response = await axios.default.get(manifestUrl);
|
|
91
|
+
const emulatorJson: EmulatorWebsiteManifest = response.data;
|
|
92
|
+
const targetDir = resolve(rootDir, 'node_modules', emulatorJson.name);
|
|
93
|
+
const appDir = resolve(targetDir, 'app');
|
|
94
|
+
await createDirectory(appDir);
|
|
95
|
+
await createEmulatorFiles(targetDir, appDir, manifestUrl, emulatorJson);
|
|
96
|
+
return emulatorJson.name;
|
|
67
97
|
}
|
|
@@ -40,7 +40,7 @@ describe('Piral-CLI pilet injector', () => {
|
|
|
40
40
|
expect(injector.active).toBeFalsy();
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
it('PiletInjector does not send empty content', () => {
|
|
43
|
+
it('PiletInjector does not send empty content', async () => {
|
|
44
44
|
// Arrange
|
|
45
45
|
const core = new EventEmitter();
|
|
46
46
|
const injector = new PiletInjector(optionsMock, configMock, core);
|
|
@@ -51,7 +51,7 @@ describe('Piral-CLI pilet injector', () => {
|
|
|
51
51
|
|
|
52
52
|
// Act
|
|
53
53
|
try {
|
|
54
|
-
injector.sendFile(target, url); // this file does not exist
|
|
54
|
+
await injector.sendFile(target, url); // this file does not exist
|
|
55
55
|
} catch {
|
|
56
56
|
hasFailed = true;
|
|
57
57
|
}
|
|
@@ -113,7 +113,7 @@ describe('Piral-CLI pilet injector', () => {
|
|
|
113
113
|
expect(res).toBeUndefined();
|
|
114
114
|
});
|
|
115
115
|
|
|
116
|
-
it('PiletInjector wont crash on request with no target', () => {
|
|
116
|
+
it('PiletInjector wont crash on request with no target', async () => {
|
|
117
117
|
// Arrange
|
|
118
118
|
const optionsMock = {
|
|
119
119
|
pilets: [],
|
|
@@ -136,7 +136,7 @@ describe('Piral-CLI pilet injector', () => {
|
|
|
136
136
|
} as KrasRequest;
|
|
137
137
|
|
|
138
138
|
// Act
|
|
139
|
-
const res = injector.handle(request);
|
|
139
|
+
const res = await injector.handle(request);
|
|
140
140
|
|
|
141
141
|
// Assert
|
|
142
142
|
expect(res).toBeUndefined();
|