piral-cli 1.5.0-beta.6740 → 1.5.0-beta.6746
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/build-pilet.js.map +1 -1
- package/lib/apps/declaration-pilet.js +5 -2
- package/lib/apps/declaration-pilet.js.map +1 -1
- package/lib/apps/declaration-piral.js +3 -2
- package/lib/apps/declaration-piral.js.map +1 -1
- package/lib/apps/publish-pilet.js +2 -9
- package/lib/apps/publish-pilet.js.map +1 -1
- package/lib/apps/publish-piral.js +2 -9
- package/lib/apps/publish-piral.js.map +1 -1
- package/lib/apps/upgrade-pilet.js +4 -1
- package/lib/apps/upgrade-pilet.js.map +1 -1
- package/lib/common/config.d.ts +1 -0
- package/lib/common/config.js +28 -2
- package/lib/common/config.js.map +1 -1
- package/lib/common/constants.d.ts +1 -0
- package/lib/common/constants.js +2 -1
- package/lib/common/constants.js.map +1 -1
- package/lib/common/declaration.d.ts +2 -2
- package/lib/common/declaration.js +23 -12
- package/lib/common/declaration.js.map +1 -1
- package/lib/common/http.d.ts +12 -1
- package/lib/common/http.js +113 -76
- package/lib/common/http.js.map +1 -1
- package/lib/common/interactive.js +2 -2
- package/lib/common/interactive.js.map +1 -1
- package/lib/common/package.d.ts +3 -3
- package/lib/common/package.js +6 -6
- package/lib/common/package.js.map +1 -1
- package/lib/common/website.d.ts +1 -1
- package/lib/common/website.js +33 -11
- package/lib/common/website.js.map +1 -1
- package/package.json +2 -2
- package/src/apps/build-pilet.ts +2 -8
- package/src/apps/declaration-pilet.ts +15 -11
- package/src/apps/declaration-piral.ts +4 -2
- package/src/apps/publish-pilet.ts +4 -12
- package/src/apps/publish-piral.ts +5 -14
- package/src/apps/upgrade-pilet.ts +5 -1
- package/src/common/config.ts +36 -2
- package/src/common/constants.ts +1 -0
- package/src/common/declaration.ts +21 -12
- package/src/common/http.ts +143 -97
- package/src/common/interactive.ts +2 -2
- package/src/common/package.ts +11 -5
- package/src/common/website.ts +40 -12
package/src/common/website.ts
CHANGED
|
@@ -1,27 +1,49 @@
|
|
|
1
|
+
import { Agent } from 'https';
|
|
1
2
|
import { join, relative, resolve } from 'path';
|
|
2
3
|
import { createPiralStubIndexIfNotExists } from './template';
|
|
3
|
-
import { getAxiosOptions } from './http';
|
|
4
|
+
import { getAuthorizationHeaders, getAxiosOptions, getCertificate, handleAxiosError } from './http';
|
|
4
5
|
import { packageJson } from './constants';
|
|
6
|
+
import { updateConfig } from './config';
|
|
5
7
|
import { ForceOverwrite } from './enums';
|
|
6
8
|
import { createDirectory, readJson, writeBinary } from './io';
|
|
7
9
|
import { writeJson } from './io';
|
|
8
10
|
import { progress, log } from './log';
|
|
9
|
-
import { axios } from '../external';
|
|
11
|
+
import { axios, isInteractive } from '../external';
|
|
10
12
|
import { EmulatorWebsiteManifestFiles, EmulatorWebsiteManifest } from '../types';
|
|
11
13
|
|
|
12
|
-
function requestManifest(url: string) {
|
|
14
|
+
async function requestManifest(url: string, interactive: boolean, httpsAgent?: Agent) {
|
|
13
15
|
const opts = getAxiosOptions(url);
|
|
14
|
-
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
return await axios.default.get(url, { ...opts, httpsAgent });
|
|
19
|
+
} catch (error) {
|
|
20
|
+
return await handleAxiosError(error, interactive, httpsAgent, async (mode, key) => {
|
|
21
|
+
const headers = getAuthorizationHeaders(mode, key);
|
|
22
|
+
await updateConfig('auth', {
|
|
23
|
+
[url]: {
|
|
24
|
+
mode: 'header',
|
|
25
|
+
key: 'authorization',
|
|
26
|
+
value: headers.authorization,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
return await requestManifest(url, false, httpsAgent);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
15
32
|
}
|
|
16
33
|
|
|
17
|
-
async function downloadEmulatorFiles(
|
|
34
|
+
async function downloadEmulatorFiles(
|
|
35
|
+
manifestUrl: string,
|
|
36
|
+
target: string,
|
|
37
|
+
files: EmulatorWebsiteManifestFiles,
|
|
38
|
+
httpsAgent?: Agent,
|
|
39
|
+
) {
|
|
18
40
|
const requiredFiles = [files.typings, files.main, files.app];
|
|
19
41
|
const opts = getAxiosOptions(manifestUrl);
|
|
20
42
|
|
|
21
43
|
await Promise.all(
|
|
22
44
|
requiredFiles.map(async (file) => {
|
|
23
45
|
const url = new URL(file, manifestUrl);
|
|
24
|
-
const res = await axios.default.get(url.href, { ...opts, responseType: 'arraybuffer' });
|
|
46
|
+
const res = await axios.default.get(url.href, { ...opts, httpsAgent, responseType: 'arraybuffer' });
|
|
25
47
|
const data: Buffer = res.data;
|
|
26
48
|
await writeBinary(target, file, data);
|
|
27
49
|
}),
|
|
@@ -33,6 +55,7 @@ async function createEmulatorFiles(
|
|
|
33
55
|
appDir: string,
|
|
34
56
|
manifestUrl: string,
|
|
35
57
|
emulatorJson: EmulatorWebsiteManifest,
|
|
58
|
+
httpsAgent?: Agent,
|
|
36
59
|
) {
|
|
37
60
|
const mainFile = 'index.js';
|
|
38
61
|
const appDirName = relative(targetDir, appDir);
|
|
@@ -69,14 +92,16 @@ async function createEmulatorFiles(
|
|
|
69
92
|
outFile: emulatorJson.files.main,
|
|
70
93
|
});
|
|
71
94
|
|
|
72
|
-
await downloadEmulatorFiles(manifestUrl, appDir, emulatorJson.files);
|
|
95
|
+
await downloadEmulatorFiles(manifestUrl, appDir, emulatorJson.files, httpsAgent);
|
|
73
96
|
}
|
|
74
97
|
|
|
75
|
-
export async function updateFromEmulatorWebsite(targetDir: string, manifestUrl: string) {
|
|
98
|
+
export async function updateFromEmulatorWebsite(targetDir: string, manifestUrl: string, interactive: boolean) {
|
|
76
99
|
progress(`Updating emulator from %s ...`, manifestUrl);
|
|
100
|
+
const ca = await getCertificate();
|
|
101
|
+
const httpsAgent = ca ? new Agent({ ca }) : undefined;
|
|
77
102
|
|
|
78
103
|
try {
|
|
79
|
-
const response = await requestManifest(manifestUrl);
|
|
104
|
+
const response = await requestManifest(manifestUrl, interactive, httpsAgent);
|
|
80
105
|
const nextEmulator: EmulatorWebsiteManifest = response.data;
|
|
81
106
|
const currentEmulator = await readJson(targetDir, packageJson);
|
|
82
107
|
|
|
@@ -85,7 +110,7 @@ export async function updateFromEmulatorWebsite(targetDir: string, manifestUrl:
|
|
|
85
110
|
} else if (currentEmulator.piralCLI.timstamp !== nextEmulator.timestamp) {
|
|
86
111
|
log('generalDebug_0003', `The timestamp on "${currentEmulator.name}" is different (${nextEmulator.timestamp}).`);
|
|
87
112
|
const appDir = resolve(targetDir, 'app');
|
|
88
|
-
await createEmulatorFiles(targetDir, appDir, manifestUrl, nextEmulator);
|
|
113
|
+
await createEmulatorFiles(targetDir, appDir, manifestUrl, nextEmulator, httpsAgent);
|
|
89
114
|
} else {
|
|
90
115
|
log('generalDebug_0003', `Nothing to update for "${currentEmulator.name}".`);
|
|
91
116
|
}
|
|
@@ -97,11 +122,14 @@ export async function updateFromEmulatorWebsite(targetDir: string, manifestUrl:
|
|
|
97
122
|
|
|
98
123
|
export async function scaffoldFromEmulatorWebsite(rootDir: string, manifestUrl: string) {
|
|
99
124
|
progress(`Downloading emulator from %s ...`, manifestUrl);
|
|
100
|
-
const
|
|
125
|
+
const ca = await getCertificate();
|
|
126
|
+
const httpsAgent = ca ? new Agent({ ca }) : undefined;
|
|
127
|
+
const interactive = isInteractive();
|
|
128
|
+
const response = await requestManifest(manifestUrl, interactive, httpsAgent);
|
|
101
129
|
const emulatorJson: EmulatorWebsiteManifest = response.data;
|
|
102
130
|
const targetDir = resolve(rootDir, 'node_modules', emulatorJson.name);
|
|
103
131
|
const appDir = resolve(targetDir, 'app');
|
|
104
132
|
await createDirectory(appDir);
|
|
105
|
-
await createEmulatorFiles(targetDir, appDir, manifestUrl, emulatorJson);
|
|
133
|
+
await createEmulatorFiles(targetDir, appDir, manifestUrl, emulatorJson, httpsAgent);
|
|
106
134
|
return { name: emulatorJson.name, path: targetDir };
|
|
107
135
|
}
|