piral-cli 0.15.0-alpha.3933 → 0.15.0-alpha.3975
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.d.ts +4 -0
- package/lib/apps/build-pilet.js +4 -3
- package/lib/apps/build-pilet.js.map +1 -1
- package/lib/apps/debug-pilet.d.ts +4 -0
- package/lib/apps/debug-pilet.js +4 -3
- package/lib/apps/debug-pilet.js.map +1 -1
- package/lib/apps/publish-pilet.d.ts +9 -1
- package/lib/apps/publish-pilet.js +4 -2
- package/lib/apps/publish-pilet.js.map +1 -1
- package/lib/commands.js +16 -0
- package/lib/commands.js.map +1 -1
- package/lib/common/http.d.ts +2 -1
- package/lib/common/http.js +18 -4
- package/lib/common/http.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/info.d.ts +1 -0
- package/lib/common/info.js +3 -1
- package/lib/common/info.js.map +1 -1
- package/lib/common/parallel.d.ts +1 -0
- package/lib/common/parallel.js +29 -0
- package/lib/common/parallel.js.map +1 -0
- package/lib/helpers.d.ts +2 -1
- package/lib/helpers.js +2 -1
- package/lib/helpers.js.map +1 -1
- package/lib/types/public.d.ts +1 -0
- package/package.json +2 -2
- package/src/apps/build-pilet.ts +105 -99
- package/src/apps/debug-pilet.ts +61 -54
- package/src/apps/publish-pilet.ts +16 -2
- package/src/commands.ts +18 -0
- package/src/common/http.test.ts +7 -7
- package/src/common/http.ts +21 -3
- package/src/common/index.ts +1 -0
- package/src/common/info.ts +3 -0
- package/src/common/parallel.test.ts +28 -0
- package/src/common/parallel.ts +21 -0
- package/src/helpers.ts +2 -0
- package/src/types/public.ts +2 -0
package/src/common/http.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { platform, tmpdir } from 'os';
|
|
|
5
5
|
import { createWriteStream } from 'fs';
|
|
6
6
|
import { log } from './log';
|
|
7
7
|
import { axios, FormData } from '../external';
|
|
8
|
+
import { PiletPublishScheme } from '../types';
|
|
8
9
|
|
|
9
10
|
const os = platform();
|
|
10
11
|
const standardHeaders = {
|
|
@@ -67,25 +68,42 @@ export interface PostFileResult {
|
|
|
67
68
|
|
|
68
69
|
export function postFile(
|
|
69
70
|
target: string,
|
|
71
|
+
scheme: PiletPublishScheme,
|
|
70
72
|
key: string,
|
|
71
73
|
file: Buffer,
|
|
72
|
-
|
|
74
|
+
customFields: Record<string, string> = {},
|
|
75
|
+
customHeaders: Record<string, string> = {},
|
|
73
76
|
ca?: Buffer,
|
|
74
77
|
): Promise<PostFileResult> {
|
|
75
78
|
const form = new FormData();
|
|
76
79
|
const httpsAgent = ca ? new Agent({ ca }) : undefined;
|
|
77
80
|
|
|
78
|
-
Object.keys(
|
|
81
|
+
Object.keys(customFields).forEach((key) => form.append(key, customFields[key]));
|
|
79
82
|
|
|
80
83
|
form.append('file', file, 'pilet.tgz');
|
|
81
84
|
|
|
82
85
|
const headers: Record<string, string> = {
|
|
83
86
|
...form.getHeaders(),
|
|
84
87
|
...standardHeaders,
|
|
88
|
+
...customHeaders,
|
|
85
89
|
};
|
|
86
90
|
|
|
87
91
|
if (key) {
|
|
88
|
-
|
|
92
|
+
switch (scheme) {
|
|
93
|
+
case 'basic':
|
|
94
|
+
headers.authorization = `Basic ${key}`;
|
|
95
|
+
break;
|
|
96
|
+
case 'bearer':
|
|
97
|
+
headers.authorization = `Bearer ${key}`;
|
|
98
|
+
break;
|
|
99
|
+
case 'digest':
|
|
100
|
+
headers.authorization = `Digest ${key}`;
|
|
101
|
+
break;
|
|
102
|
+
case 'none':
|
|
103
|
+
default:
|
|
104
|
+
headers.authorization = key;
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
89
107
|
}
|
|
90
108
|
|
|
91
109
|
return axios.default
|
package/src/common/index.ts
CHANGED
package/src/common/info.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { cpus } from 'os';
|
|
2
|
+
|
|
1
3
|
const info = require('../../package.json');
|
|
2
4
|
|
|
3
5
|
export function findCompatVersion(version: string) {
|
|
@@ -18,3 +20,4 @@ export const compatVersion = findCompatVersion(cliVersion);
|
|
|
18
20
|
export const repositoryUrl = info.repository.url;
|
|
19
21
|
export const isWindows = process.platform === 'win32';
|
|
20
22
|
export const pathSeparator = isWindows ? ';' : ':';
|
|
23
|
+
export const cpuCount = cpus().length;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { concurrentWorkers } from './parallel';
|
|
2
|
+
|
|
3
|
+
describe('Concurrent Workers', () => {
|
|
4
|
+
it('Can run against no entries', async () => {
|
|
5
|
+
const result = await concurrentWorkers([], 10, () => Promise.resolve('foo'));
|
|
6
|
+
expect(result).toEqual([]);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('Can run against single entry', async () => {
|
|
10
|
+
const result = await concurrentWorkers(['bar'], 10, (item) => Promise.resolve('foo' + item));
|
|
11
|
+
expect(result).toEqual(['foobar']);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('Can run against less entries than concurrency', async () => {
|
|
15
|
+
const result = await concurrentWorkers(['bar', 'rba', 'abr', 'rab', 'arb', 'bra'], 10, (item) => Promise.resolve('foo' + item));
|
|
16
|
+
expect(result).toEqual(['foobar', 'foorba', 'fooabr', 'foorab', 'fooarb', 'foobra']);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('Can run against more entries than concurrency', async () => {
|
|
20
|
+
const result = await concurrentWorkers(['bar', 'rba', 'abr', 'rab', 'arb', 'bra'], 2, (item) => Promise.resolve('foo' + item));
|
|
21
|
+
expect(result).toEqual(['foobar', 'foorba', 'fooabr', 'foorab', 'fooarb', 'foobra']);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('Can run against equal entries than concurrency', async () => {
|
|
25
|
+
const result = await concurrentWorkers(['bar', 'rba', 'abr', 'rab', 'arb', 'bra'], 6, (item) => Promise.resolve('foo' + item));
|
|
26
|
+
expect(result).toEqual(['foobar', 'foorba', 'fooabr', 'foorab', 'fooarb', 'foobra']);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export async function concurrentWorkers<T, R>(
|
|
2
|
+
items: Array<T>,
|
|
3
|
+
concurrency: number,
|
|
4
|
+
worker: (item: T) => Promise<R>,
|
|
5
|
+
): Promise<Array<R>> {
|
|
6
|
+
const maxItems = items.length;
|
|
7
|
+
const results: Array<R> = new Array(maxItems);
|
|
8
|
+
let offset = 0;
|
|
9
|
+
|
|
10
|
+
await Promise.all(
|
|
11
|
+
items.slice(0, concurrency).map(async () => {
|
|
12
|
+
while (offset < maxItems) {
|
|
13
|
+
const i = offset++;
|
|
14
|
+
const item = items[i];
|
|
15
|
+
results[i] = await worker(item);
|
|
16
|
+
}
|
|
17
|
+
}),
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
return results;
|
|
21
|
+
}
|
package/src/helpers.ts
CHANGED
|
@@ -7,9 +7,11 @@ import {
|
|
|
7
7
|
PiletPublishSource,
|
|
8
8
|
PiralBuildType,
|
|
9
9
|
PiletBuildType,
|
|
10
|
+
PiletPublishScheme,
|
|
10
11
|
} from './types';
|
|
11
12
|
|
|
12
13
|
export const schemaKeys: Array<PiletSchemaVersion> = ['v0', 'v1', 'v2', 'none'];
|
|
14
|
+
export const publishModeKeys: Array<PiletPublishScheme> = ['none', 'basic', 'bearer', 'digest'];
|
|
13
15
|
export const fromKeys: Array<PiletPublishSource> = ['local', 'remote', 'npm'];
|
|
14
16
|
export const piralBuildTypeKeys: Array<PiralBuildType> = ['all', 'release', 'emulator', 'emulator-sources'];
|
|
15
17
|
export const piletBuildTypeKeys: Array<PiletBuildType> = ['default', 'standalone', 'manifest'];
|
package/src/types/public.ts
CHANGED
|
@@ -218,6 +218,8 @@ export interface BundlerDefinition {
|
|
|
218
218
|
|
|
219
219
|
export type PiletSchemaVersion = 'none' | 'v0' | 'v1' | 'v2';
|
|
220
220
|
|
|
221
|
+
export type PiletPublishScheme = 'none' | 'digest' | 'bearer' | 'basic';
|
|
222
|
+
|
|
221
223
|
export type PiletPublishSource = 'local' | 'npm' | 'remote';
|
|
222
224
|
|
|
223
225
|
export type PiralBuildType = 'all' | 'release' | 'emulator' | 'emulator-sources';
|