piral-cli 0.15.0-alpha.4041 → 0.15.0-alpha.4231
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/build-piral.js.map +1 -1
- package/lib/apps/debug-pilet.js.map +1 -1
- package/lib/apps/debug-piral.js.map +1 -1
- package/lib/apps/index.js +5 -1
- package/lib/apps/index.js.map +1 -1
- package/lib/apps/new-pilet.js +5 -9
- package/lib/apps/new-pilet.js.map +1 -1
- package/lib/apps/new-piral.js +5 -3
- package/lib/apps/new-piral.js.map +1 -1
- package/lib/apps/publish-pilet.d.ts +4 -0
- package/lib/apps/publish-pilet.js +4 -3
- package/lib/apps/publish-pilet.js.map +1 -1
- package/lib/apps/publish-piral.d.ts +4 -0
- package/lib/apps/publish-piral.js +9 -7
- package/lib/apps/publish-piral.js.map +1 -1
- package/lib/apps/upgrade-pilet.js +2 -8
- package/lib/apps/upgrade-pilet.js.map +1 -1
- package/lib/apps/upgrade-piral.js +1 -1
- package/lib/apps/upgrade-piral.js.map +1 -1
- package/lib/build/bundler-calls.d.ts +1 -1
- package/lib/build/run-build-pilet.js.map +1 -1
- package/lib/build/run-build-piral.js.map +1 -1
- package/lib/build/run-debug-mono-piral.js +1 -1
- package/lib/build/run-debug-mono-piral.js.map +1 -1
- package/lib/build/run-debug-pilet.js.map +1 -1
- package/lib/build/run-debug-piral.js.map +1 -1
- package/lib/bundler.js +1 -1
- package/lib/bundler.js.map +1 -1
- package/lib/commands.js +8 -0
- package/lib/commands.js.map +1 -1
- package/lib/common/browser.d.ts +1 -0
- package/lib/common/browser.js +16 -10
- package/lib/common/browser.js.map +1 -1
- package/lib/common/clients/index.d.ts +19 -0
- package/lib/common/clients/index.js +40 -0
- package/lib/common/clients/index.js.map +1 -0
- package/lib/common/clients/lerna.d.ts +6 -1
- package/lib/common/clients/lerna.js +67 -3
- package/lib/common/clients/lerna.js.map +1 -1
- package/lib/common/clients/npm.d.ts +4 -1
- package/lib/common/clients/npm.js +36 -9
- package/lib/common/clients/npm.js.map +1 -1
- package/lib/common/clients/pnpm.d.ts +4 -0
- package/lib/common/clients/pnpm.js +41 -1
- package/lib/common/clients/pnpm.js.map +1 -1
- package/lib/common/clients/rush.d.ts +6 -0
- package/lib/common/clients/rush.js +118 -0
- package/lib/common/clients/rush.js.map +1 -0
- package/lib/common/clients/yarn.d.ts +4 -0
- package/lib/common/clients/yarn.js +44 -4
- package/lib/common/clients/yarn.js.map +1 -1
- package/lib/common/config.js.map +1 -1
- package/lib/common/constants.d.ts +1 -1
- package/lib/common/constants.js +1 -1
- package/lib/common/constants.js.map +1 -1
- package/lib/common/declaration.js +14 -10
- package/lib/common/declaration.js.map +1 -1
- package/lib/common/emulator.js +2 -2
- package/lib/common/emulator.js.map +1 -1
- package/lib/common/http.d.ts +1 -1
- package/lib/common/http.js +12 -7
- package/lib/common/http.js.map +1 -1
- package/lib/common/importmap.js +7 -16
- package/lib/common/importmap.js.map +1 -1
- package/lib/common/index.js +5 -1
- package/lib/common/index.js.map +1 -1
- package/lib/common/info.d.ts +4 -0
- package/lib/common/info.js +6 -1
- package/lib/common/info.js.map +1 -1
- package/lib/common/inspect.js +2 -1
- package/lib/common/inspect.js.map +1 -1
- package/lib/common/interactive.d.ts +9 -0
- package/lib/common/interactive.js +31 -1
- package/lib/common/interactive.js.map +1 -1
- package/lib/common/io.js +1 -1
- package/lib/common/io.js.map +1 -1
- package/lib/common/npm.d.ts +11 -16
- package/lib/common/npm.js +165 -158
- package/lib/common/npm.js.map +1 -1
- package/lib/common/pack.js +1 -1
- package/lib/common/pack.js.map +1 -1
- package/lib/common/package.d.ts +6 -7
- package/lib/common/package.js +26 -28
- package/lib/common/package.js.map +1 -1
- package/lib/common/scaffold.js +5 -2
- package/lib/common/scaffold.js.map +1 -1
- package/lib/common/version.js +4 -4
- package/lib/common/version.js.map +1 -1
- package/lib/external/index.js +2380 -470
- package/lib/helpers.d.ts +1 -1
- package/lib/helpers.js +1 -1
- package/lib/helpers.js.map +1 -1
- package/lib/index.js +5 -1
- package/lib/index.js.map +1 -1
- package/lib/injectors/pilet.d.ts +1 -0
- package/lib/injectors/pilet.js +7 -7
- package/lib/injectors/pilet.js.map +1 -1
- package/lib/messages.d.ts +1 -1
- package/lib/messages.js +5 -1
- package/lib/messages.js.map +1 -1
- package/lib/plugin.js +27 -2
- package/lib/plugin.js.map +1 -1
- package/lib/release.d.ts +1 -1
- package/lib/release.js +7 -2
- package/lib/release.js.map +1 -1
- package/lib/types/common.d.ts +1 -1
- package/lib/types/index.js +5 -1
- package/lib/types/index.js.map +1 -1
- package/lib/types/internal.d.ts +9 -1
- package/lib/types/public.d.ts +2 -2
- package/package.json +5 -3
- package/src/apps/new-pilet.ts +9 -14
- package/src/apps/new-piral.ts +9 -5
- package/src/apps/publish-pilet.ts +10 -3
- package/src/apps/publish-piral.ts +21 -6
- package/src/apps/upgrade-pilet.ts +4 -12
- package/src/apps/upgrade-piral.ts +2 -2
- package/src/build/bundler-calls.ts +1 -1
- package/src/build/run-build-pilet.ts +1 -1
- package/src/build/run-build-piral.ts +1 -1
- package/src/build/run-debug-mono-piral.ts +2 -2
- package/src/build/run-debug-pilet.ts +1 -1
- package/src/build/run-debug-piral.ts +1 -1
- package/src/bundler.test.ts +1 -1
- package/src/bundler.ts +2 -2
- package/src/commands.ts +8 -0
- package/src/common/browser.ts +12 -8
- package/src/common/clients/index.ts +33 -0
- package/src/common/clients/lerna.ts +61 -1
- package/src/common/clients/npm.ts +31 -6
- package/src/common/clients/pnpm.ts +37 -0
- package/src/common/clients/rush.ts +111 -0
- package/src/common/clients/yarn.ts +40 -3
- package/src/common/config.ts +3 -3
- package/src/common/constants.ts +1 -1
- package/src/common/declaration.ts +17 -10
- package/src/common/emulator.ts +3 -3
- package/src/common/http.ts +20 -6
- package/src/common/importmap.ts +7 -15
- package/src/common/info.ts +6 -1
- package/src/common/inspect.ts +2 -1
- package/src/common/interactive.test.ts +3 -0
- package/src/common/interactive.ts +48 -1
- package/src/common/io.ts +1 -1
- package/src/common/npm.test.ts +122 -76
- package/src/common/npm.ts +177 -152
- package/src/common/pack.test.ts +1 -1
- package/src/common/pack.ts +2 -2
- package/src/common/package.test.ts +1 -14
- package/src/common/package.ts +31 -29
- package/src/common/scaffold.ts +7 -2
- package/src/common/version.ts +4 -4
- package/src/external/index.ts +2 -1
- package/src/helpers.ts +2 -2
- package/src/injectors/pilet.ts +9 -8
- package/src/messages.ts +6 -2
- package/src/plugin.ts +34 -5
- package/src/release.ts +10 -2
- package/src/types/common.ts +1 -1
- package/src/types/internal.ts +6 -1
- package/src/types/public.ts +2 -2
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { resolve } from 'path';
|
|
2
2
|
import { log } from '../log';
|
|
3
|
+
import { findFile } from '../io';
|
|
3
4
|
import { runCommand } from '../scripts';
|
|
4
5
|
import { MemoryStream } from '../MemoryStream';
|
|
5
6
|
|
|
7
|
+
// Helpers:
|
|
8
|
+
|
|
6
9
|
function runYarnProcess(args: Array<string>, target: string, output?: NodeJS.WritableStream) {
|
|
7
|
-
log('generalDebug_0003', 'Starting the Yarn process ...');
|
|
10
|
+
log('generalDebug_0003', 'Starting the Yarn@1 process ...');
|
|
8
11
|
const cwd = resolve(process.cwd(), target);
|
|
9
12
|
return runCommand('yarn', args, cwd, output);
|
|
10
13
|
}
|
|
@@ -25,16 +28,50 @@ function convert(flags: Array<string>) {
|
|
|
25
28
|
});
|
|
26
29
|
}
|
|
27
30
|
|
|
31
|
+
// Client interface functions:
|
|
32
|
+
|
|
28
33
|
export async function installDependencies(target = '.', ...flags: Array<string>) {
|
|
29
34
|
const ms = new MemoryStream();
|
|
30
35
|
await runYarnProcess(['install', ...convert(flags)], target, ms);
|
|
31
|
-
log('generalDebug_0003', `Yarn install dependencies result: ${ms.value}`);
|
|
36
|
+
log('generalDebug_0003', `Yarn@1 install dependencies result: ${ms.value}`);
|
|
32
37
|
return ms.value;
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
export async function installPackage(packageRef: string, target = '.', ...flags: Array<string>) {
|
|
36
41
|
const ms = new MemoryStream();
|
|
37
42
|
await runYarnProcess(['add', packageRef, ...convert(flags)], target, ms);
|
|
38
|
-
log('generalDebug_0003', `Yarn install package result: ${ms.value}`);
|
|
43
|
+
log('generalDebug_0003', `Yarn@1 install package result: ${ms.value}`);
|
|
39
44
|
return ms.value;
|
|
40
45
|
}
|
|
46
|
+
|
|
47
|
+
export async function detectClient(root: string) {
|
|
48
|
+
return !!(await findFile(root, 'yarn.lock'));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export async function initProject(projectName: string, target: string) {}
|
|
52
|
+
|
|
53
|
+
export async function isProject(root: string, packageRef: string) {
|
|
54
|
+
const details = await listProjects(root);
|
|
55
|
+
|
|
56
|
+
if (typeof details === 'object') {
|
|
57
|
+
return typeof details?.[packageRef]?.location === 'string';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Functions to exclusively use from yarn client:
|
|
64
|
+
|
|
65
|
+
export async function listProjects(target: string) {
|
|
66
|
+
const ms = new MemoryStream();
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
await runYarnProcess(['workspaces', 'info'], target, ms);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
log('generalDebug_0003', `yarn workspaces error: ${e}`);
|
|
72
|
+
return {};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
log('generalDebug_0003', `yarn workspaces result: ${ms.value}`);
|
|
76
|
+
return JSON.parse(ms.value);
|
|
77
|
+
}
|
package/src/common/config.ts
CHANGED
|
@@ -72,11 +72,11 @@ export const config: PiralCliConfig = rc(
|
|
|
72
72
|
apiKeys: {},
|
|
73
73
|
url: undefined,
|
|
74
74
|
cert: undefined,
|
|
75
|
-
npmClient: 'npm',
|
|
76
|
-
bundler: 'webpack5',
|
|
75
|
+
npmClient: 'npm' as const,
|
|
76
|
+
bundler: 'webpack5' as const,
|
|
77
77
|
piletApi: '/$pilet-api',
|
|
78
78
|
validators: {},
|
|
79
|
-
schemaVersion: 'v2',
|
|
79
|
+
schemaVersion: 'v2' as const,
|
|
80
80
|
openBrowser: false,
|
|
81
81
|
port: 1234,
|
|
82
82
|
language: SourceLanguage.ts,
|
package/src/common/constants.ts
CHANGED
|
@@ -2,7 +2,7 @@ export const defaultRegistry = 'https://registry.npmjs.org/';
|
|
|
2
2
|
export const filesTar = 'files';
|
|
3
3
|
export const filesOnceTar = 'files_once';
|
|
4
4
|
export const piralBaseRoot = 'piral-base/package.json';
|
|
5
|
-
export const frameworkLibs = ['piral' as const, 'piral-core' as const, 'piral-base' as const];
|
|
5
|
+
export const frameworkLibs = ['piral-native' as const, 'piral' as const, 'piral-core' as const, 'piral-base' as const];
|
|
6
6
|
export const entryModuleExtensions = ['.ts', '.tsx', '.js', '.jsx'];
|
|
7
7
|
export const bundlerNames = [
|
|
8
8
|
'esbuild' as const,
|
|
@@ -16,9 +16,16 @@ function findPiralBaseApi(root: string) {
|
|
|
16
16
|
const projectDir = dirname(packageJsonPath);
|
|
17
17
|
// By default support for piral-base < 0.15
|
|
18
18
|
const { piletApiTypings = 'lib/types.d.ts' } = project;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
|
|
20
|
+
return [
|
|
21
|
+
{
|
|
22
|
+
file: resolve(projectDir, piletApiTypings),
|
|
23
|
+
name: 'PiletApi',
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
} catch (err) {
|
|
27
|
+
log('generalError_0002', `Could not find the root API of "piral-base" from "${root}": ${err}`);
|
|
28
|
+
return [];
|
|
22
29
|
}
|
|
23
30
|
}
|
|
24
31
|
|
|
@@ -141,15 +148,15 @@ export async function createPiralDeclaration(
|
|
|
141
148
|
root,
|
|
142
149
|
files,
|
|
143
150
|
types: findDeclaredTypings(root),
|
|
144
|
-
apis:
|
|
145
|
-
{
|
|
146
|
-
file: findPiralBaseApi(root),
|
|
147
|
-
name: 'PiletApi',
|
|
148
|
-
},
|
|
149
|
-
],
|
|
151
|
+
apis: findPiralBaseApi(root),
|
|
150
152
|
imports: externals,
|
|
151
153
|
logLevel,
|
|
152
154
|
logger: createLogger(),
|
|
153
155
|
};
|
|
154
|
-
|
|
156
|
+
|
|
157
|
+
if (options.apis.length) {
|
|
158
|
+
return await createDeclarationFile(options, baseDir, target, forceOverwrite);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
log('declarationCouldNotBeGenerated_0076', baseDir, 'The main Pilet API interface could not be found.');
|
|
155
162
|
}
|
package/src/common/emulator.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { findDependencyVersion, copyScaffoldingFiles, isValidDependency } from '
|
|
|
3
3
|
import { createFileFromTemplateIfNotExists } from './template';
|
|
4
4
|
import { filesTar, filesOnceTar } from './constants';
|
|
5
5
|
import { cliVersion } from './info';
|
|
6
|
-
import {
|
|
6
|
+
import { createNpmPackage, makeExternals } from './npm';
|
|
7
7
|
import { createPiralDeclaration } from './declaration';
|
|
8
8
|
import { ForceOverwrite } from './enums';
|
|
9
9
|
import { createTarball } from './archive';
|
|
@@ -31,7 +31,7 @@ export async function createEmulatorSources(
|
|
|
31
31
|
...piralPkg.devDependencies,
|
|
32
32
|
...piralPkg.dependencies,
|
|
33
33
|
};
|
|
34
|
-
const allExternals = makeExternals(allDeps, piralPkg.pilets?.externals);
|
|
34
|
+
const allExternals = makeExternals(sourceDir, allDeps, piralPkg.pilets?.externals);
|
|
35
35
|
|
|
36
36
|
const externalPackages = await Promise.all(
|
|
37
37
|
allExternals.filter(isValidDependency).map(async (name) => ({
|
|
@@ -138,7 +138,7 @@ export async function createEmulatorSources(
|
|
|
138
138
|
|
|
139
139
|
export async function packageEmulator(rootDir: string) {
|
|
140
140
|
// finally package everything up
|
|
141
|
-
await
|
|
141
|
+
await createNpmPackage(rootDir);
|
|
142
142
|
|
|
143
143
|
// get all files
|
|
144
144
|
const names = await getFileNames(rootDir);
|
package/src/common/http.ts
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import { join } from 'path';
|
|
2
2
|
import { Agent } from 'https';
|
|
3
3
|
import { Stream } from 'stream';
|
|
4
|
-
import {
|
|
4
|
+
import { tmpdir } from 'os';
|
|
5
5
|
import { createWriteStream } from 'fs';
|
|
6
6
|
import { log } from './log';
|
|
7
|
+
import { standardHeaders } from './info';
|
|
8
|
+
import { getTokenInteractively } from './interactive';
|
|
7
9
|
import { axios, FormData } from '../external';
|
|
8
10
|
import { PiletPublishScheme } from '../types';
|
|
9
11
|
|
|
10
|
-
const os = platform();
|
|
11
|
-
const standardHeaders = {
|
|
12
|
-
'user-agent': `piral-cli/http.node-${os}`,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
12
|
function getMessage(body: string | { message?: string }) {
|
|
16
13
|
if (typeof body === 'string') {
|
|
17
14
|
try {
|
|
@@ -74,6 +71,7 @@ export function postFile(
|
|
|
74
71
|
customFields: Record<string, string> = {},
|
|
75
72
|
customHeaders: Record<string, string> = {},
|
|
76
73
|
ca?: Buffer,
|
|
74
|
+
interactive = false,
|
|
77
75
|
): Promise<PostFileResult> {
|
|
78
76
|
const form = new FormData();
|
|
79
77
|
const httpsAgent = ca ? new Agent({ ca }) : undefined;
|
|
@@ -124,6 +122,22 @@ export function postFile(
|
|
|
124
122
|
// The request was made and the server responded with a status code
|
|
125
123
|
// that falls out of the range of 2xx
|
|
126
124
|
const { data, statusText, status } = error.response;
|
|
125
|
+
|
|
126
|
+
if (interactive && 'interactiveAuth' in data) {
|
|
127
|
+
const { interactiveAuth } = data;
|
|
128
|
+
|
|
129
|
+
if (typeof interactiveAuth === 'string') {
|
|
130
|
+
log(
|
|
131
|
+
'generalDebug_0003',
|
|
132
|
+
`Received status "${status}" from HTTP - trying interactive log in to "${interactiveAuth}".`,
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
return getTokenInteractively(interactiveAuth, httpsAgent).then(({ mode, token }) =>
|
|
136
|
+
postFile(target, mode, token, file, customFields, customHeaders, ca, false),
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
127
141
|
const message = getMessage(data) || '';
|
|
128
142
|
log('unsuccessfulHttpPost_0066', statusText, status, message);
|
|
129
143
|
return {
|
package/src/common/importmap.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { log, fail } from './log';
|
|
|
3
3
|
import { satisfies, validate } from './version';
|
|
4
4
|
import { computeHash } from './hash';
|
|
5
5
|
import { getHash, readJson, findFile, checkExists, checkIsDirectory } from './io';
|
|
6
|
+
import { tryResolvePackage } from './npm';
|
|
6
7
|
import { SharedDependency } from '../types';
|
|
7
8
|
|
|
8
9
|
interface Importmap {
|
|
@@ -10,16 +11,7 @@ interface Importmap {
|
|
|
10
11
|
inherit: Array<string>;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
return require.resolve(name, {
|
|
16
|
-
paths: [baseDir],
|
|
17
|
-
});
|
|
18
|
-
} catch (ex) {
|
|
19
|
-
log('generalDebug_0003', `Could not resolve the package "${name}" in "${baseDir}": ${ex}`);
|
|
20
|
-
return undefined;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
14
|
+
const shorthandsUrls = ['', '.', '...'];
|
|
23
15
|
|
|
24
16
|
function getDependencyDetails(depName: string): [assetName: string, identifier: string, versionSpec: string] {
|
|
25
17
|
const sep = depName.indexOf('@', 1);
|
|
@@ -74,8 +66,8 @@ async function resolveImportmap(dir: string, importmap: Importmap) {
|
|
|
74
66
|
ref: url,
|
|
75
67
|
type: 'remote',
|
|
76
68
|
});
|
|
77
|
-
} else if (url === identifier) {
|
|
78
|
-
const entry =
|
|
69
|
+
} else if (url === identifier || shorthandsUrls.includes(url)) {
|
|
70
|
+
const entry = tryResolvePackage(identifier, dir);
|
|
79
71
|
|
|
80
72
|
if (entry) {
|
|
81
73
|
const packageJson = await findFile(dirname(entry), 'package.json');
|
|
@@ -90,7 +82,7 @@ async function resolveImportmap(dir: string, importmap: Importmap) {
|
|
|
90
82
|
type: 'local',
|
|
91
83
|
});
|
|
92
84
|
} else {
|
|
93
|
-
fail('importMapReferenceNotFound_0027', dir,
|
|
85
|
+
fail('importMapReferenceNotFound_0027', dir, identifier);
|
|
94
86
|
}
|
|
95
87
|
} else {
|
|
96
88
|
const entry = resolve(dir, url);
|
|
@@ -109,7 +101,7 @@ async function resolveImportmap(dir: string, importmap: Importmap) {
|
|
|
109
101
|
dependencies.push({
|
|
110
102
|
id: `${identifier}@${version}`,
|
|
111
103
|
requireId: `${identifier}@${requireVersion}`,
|
|
112
|
-
entry: isDirectory ?
|
|
104
|
+
entry: isDirectory ? tryResolvePackage(entry, dir) : entry,
|
|
113
105
|
name: identifier,
|
|
114
106
|
ref: `${assetName}.js`,
|
|
115
107
|
type: 'local',
|
|
@@ -137,7 +129,7 @@ async function resolveImportmap(dir: string, importmap: Importmap) {
|
|
|
137
129
|
|
|
138
130
|
if (Array.isArray(inheritedImports)) {
|
|
139
131
|
for (const inheritedImport of inheritedImports) {
|
|
140
|
-
const packageJson =
|
|
132
|
+
const packageJson = tryResolvePackage(`${inheritedImport}/package.json`, dir);
|
|
141
133
|
|
|
142
134
|
if (packageJson) {
|
|
143
135
|
const packageDir = dirname(packageJson);
|
package/src/common/info.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { cpus } from 'os';
|
|
1
|
+
import { cpus, platform } from 'os';
|
|
2
2
|
|
|
3
3
|
const info = require('../../package.json');
|
|
4
|
+
const os = platform();
|
|
4
5
|
|
|
5
6
|
export function findCompatVersion(version: string) {
|
|
6
7
|
// we only care about major and minor
|
|
@@ -15,9 +16,13 @@ export function findCompatVersion(version: string) {
|
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
export const nodeVersion = process.version.substring(1);
|
|
19
|
+
export const cliName = info.name;
|
|
18
20
|
export const cliVersion = info.version;
|
|
19
21
|
export const compatVersion = findCompatVersion(cliVersion);
|
|
20
22
|
export const repositoryUrl = info.repository.url;
|
|
21
23
|
export const isWindows = process.platform === 'win32';
|
|
22
24
|
export const pathSeparator = isWindows ? ';' : ':';
|
|
23
25
|
export const cpuCount = cpus().length;
|
|
26
|
+
export const standardHeaders = {
|
|
27
|
+
'user-agent': `piral-cli/http.node-${os}`,
|
|
28
|
+
};
|
package/src/common/inspect.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { dirname, basename } from 'path';
|
|
2
2
|
import { unpackGzTar } from './archive';
|
|
3
|
+
import { jju } from '../external';
|
|
3
4
|
import { PackageData, PackageFiles } from '../types';
|
|
4
5
|
|
|
5
6
|
const packageRoot = 'package/';
|
|
@@ -8,7 +9,7 @@ function getPackageJson(files: PackageFiles): PackageData {
|
|
|
8
9
|
const fileName = `${packageRoot}package.json`;
|
|
9
10
|
const fileContent = files[fileName];
|
|
10
11
|
const content = fileContent.toString('utf8');
|
|
11
|
-
return
|
|
12
|
+
return jju.parse(content);
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
function getPiletMainPath(data: PackageData, files: PackageFiles) {
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Agent } from 'https';
|
|
2
|
+
import { openBrowserAt } from './browser';
|
|
3
|
+
import { standardHeaders } from './info';
|
|
4
|
+
import { axios, inquirer } from '../external';
|
|
5
|
+
import { PiletPublishScheme } from '../types';
|
|
2
6
|
|
|
3
7
|
export function promptSelect(message: string, values: Array<string>, defaultValue: string): Promise<string> {
|
|
4
8
|
const questions = [
|
|
@@ -24,3 +28,46 @@ export function promptConfirm(message: string, defaultValue: boolean): Promise<b
|
|
|
24
28
|
];
|
|
25
29
|
return inquirer.prompt(questions).then((answers: any) => answers.q);
|
|
26
30
|
}
|
|
31
|
+
|
|
32
|
+
type TokenResult = Promise<{ mode: PiletPublishScheme; token: string }>;
|
|
33
|
+
|
|
34
|
+
const tokenRetrievers: Record<string, TokenResult> = {};
|
|
35
|
+
|
|
36
|
+
export function getTokenInteractively(url: string, httpsAgent: Agent): TokenResult {
|
|
37
|
+
if (!(url in tokenRetrievers)) {
|
|
38
|
+
tokenRetrievers[url] = axios.default
|
|
39
|
+
.post(
|
|
40
|
+
url,
|
|
41
|
+
{
|
|
42
|
+
clientId: 'piral-cli',
|
|
43
|
+
clientName: 'Piral CLI',
|
|
44
|
+
description: 'Authorize the Piral CLI temporarily to perform actions in your name.',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
headers: {
|
|
48
|
+
...standardHeaders,
|
|
49
|
+
'content-type': 'application/json',
|
|
50
|
+
},
|
|
51
|
+
httpsAgent,
|
|
52
|
+
},
|
|
53
|
+
)
|
|
54
|
+
.then((res) => {
|
|
55
|
+
const { loginUrl, callbackUrl, expires } = res.data;
|
|
56
|
+
console.log(`Use the URL below to complete the login. The link expires at ${new Date(expires)}.`);
|
|
57
|
+
console.log('===');
|
|
58
|
+
console.log(loginUrl);
|
|
59
|
+
console.log('===');
|
|
60
|
+
|
|
61
|
+
openBrowserAt(loginUrl);
|
|
62
|
+
|
|
63
|
+
return axios.default.get(callbackUrl).then(({ data }) => {
|
|
64
|
+
console.log('Logged in successfully.');
|
|
65
|
+
return {
|
|
66
|
+
...data,
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return tokenRetrievers[url];
|
|
73
|
+
}
|
package/src/common/io.ts
CHANGED
|
@@ -239,7 +239,7 @@ export async function matchAnyPilet(baseDir: string, patterns: Array<string>) {
|
|
|
239
239
|
const allPatterns = patterns.reduce<Array<AnyPattern>>((agg, curr) => {
|
|
240
240
|
const patterns = [];
|
|
241
241
|
|
|
242
|
-
if (/[a-zA-Z0-9\-\*]
|
|
242
|
+
if (/[a-zA-Z0-9\-\*]$/.test(curr) && !preferences.find((ext) => curr.endsWith(ext))) {
|
|
243
243
|
patterns.push(curr, `${curr}.{${exts}}`, `${curr}/${nameOfPackageJson}`);
|
|
244
244
|
} else if (curr.endsWith('/')) {
|
|
245
245
|
patterns.push(`${curr}index.{${exts}}`, `${curr}${nameOfPackageJson}`);
|