piral-cli 0.15.0-alpha.4122 → 0.15.0-alpha.4284

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.
Files changed (155) hide show
  1. package/README.md +7 -5
  2. package/lib/apps/debug-pilet.js +28 -42
  3. package/lib/apps/debug-pilet.js.map +1 -1
  4. package/lib/apps/debug-piral.js +20 -34
  5. package/lib/apps/debug-piral.js.map +1 -1
  6. package/lib/apps/new-pilet.js +5 -9
  7. package/lib/apps/new-pilet.js.map +1 -1
  8. package/lib/apps/new-piral.js +9 -3
  9. package/lib/apps/new-piral.js.map +1 -1
  10. package/lib/apps/publish-pilet.d.ts +4 -0
  11. package/lib/apps/publish-pilet.js +4 -3
  12. package/lib/apps/publish-pilet.js.map +1 -1
  13. package/lib/apps/publish-piral.d.ts +4 -0
  14. package/lib/apps/publish-piral.js +9 -7
  15. package/lib/apps/publish-piral.js.map +1 -1
  16. package/lib/apps/upgrade-pilet.js +2 -8
  17. package/lib/apps/upgrade-pilet.js.map +1 -1
  18. package/lib/apps/upgrade-piral.js +1 -1
  19. package/lib/apps/upgrade-piral.js.map +1 -1
  20. package/lib/bundler.js +1 -1
  21. package/lib/bundler.js.map +1 -1
  22. package/lib/commands.js +14 -6
  23. package/lib/commands.js.map +1 -1
  24. package/lib/common/browser.d.ts +1 -0
  25. package/lib/common/browser.js +16 -10
  26. package/lib/common/browser.js.map +1 -1
  27. package/lib/common/clients/index.d.ts +19 -0
  28. package/lib/common/clients/index.js +40 -0
  29. package/lib/common/clients/index.js.map +1 -0
  30. package/lib/common/clients/lerna.d.ts +6 -1
  31. package/lib/common/clients/lerna.js +67 -3
  32. package/lib/common/clients/lerna.js.map +1 -1
  33. package/lib/common/clients/npm.d.ts +4 -1
  34. package/lib/common/clients/npm.js +37 -16
  35. package/lib/common/clients/npm.js.map +1 -1
  36. package/lib/common/clients/pnpm.d.ts +4 -0
  37. package/lib/common/clients/pnpm.js +43 -9
  38. package/lib/common/clients/pnpm.js.map +1 -1
  39. package/lib/common/clients/rush.d.ts +6 -0
  40. package/lib/common/clients/rush.js +118 -0
  41. package/lib/common/clients/rush.js.map +1 -0
  42. package/lib/common/clients/yarn.d.ts +4 -0
  43. package/lib/common/clients/yarn.js +45 -11
  44. package/lib/common/clients/yarn.js.map +1 -1
  45. package/lib/common/declaration.js +12 -9
  46. package/lib/common/declaration.js.map +1 -1
  47. package/lib/common/emulator.js +2 -2
  48. package/lib/common/emulator.js.map +1 -1
  49. package/lib/common/http.d.ts +4 -2
  50. package/lib/common/http.js +35 -16
  51. package/lib/common/http.js.map +1 -1
  52. package/lib/common/info.d.ts +4 -0
  53. package/lib/common/info.js +6 -1
  54. package/lib/common/info.js.map +1 -1
  55. package/lib/common/injectors.d.ts +36 -7
  56. package/lib/common/injectors.js +39 -11
  57. package/lib/common/injectors.js.map +1 -1
  58. package/lib/common/inspect.js +2 -1
  59. package/lib/common/inspect.js.map +1 -1
  60. package/lib/common/interactive.d.ts +9 -0
  61. package/lib/common/interactive.js +33 -1
  62. package/lib/common/interactive.js.map +1 -1
  63. package/lib/common/io.js +1 -1
  64. package/lib/common/io.js.map +1 -1
  65. package/lib/common/log.d.ts +1 -0
  66. package/lib/common/log.js +9 -2
  67. package/lib/common/log.js.map +1 -1
  68. package/lib/common/npm.d.ts +9 -16
  69. package/lib/common/npm.js +110 -152
  70. package/lib/common/npm.js.map +1 -1
  71. package/lib/common/pack.js +1 -1
  72. package/lib/common/pack.js.map +1 -1
  73. package/lib/common/package.d.ts +6 -6
  74. package/lib/common/package.js +13 -4
  75. package/lib/common/package.js.map +1 -1
  76. package/lib/common/port.d.ts +1 -0
  77. package/lib/common/port.js +11 -1
  78. package/lib/common/port.js.map +1 -1
  79. package/lib/common/scaffold.js +5 -2
  80. package/lib/common/scaffold.js.map +1 -1
  81. package/lib/common/version.js +4 -4
  82. package/lib/common/version.js.map +1 -1
  83. package/lib/external/index.js +1982 -92
  84. package/lib/helpers.d.ts +3 -3
  85. package/lib/helpers.js +10 -10
  86. package/lib/helpers.js.map +1 -1
  87. package/lib/injectors/{pilet.d.ts → pilet-injector.d.ts} +1 -0
  88. package/lib/injectors/{pilet.js → pilet-injector.js} +29 -31
  89. package/lib/injectors/pilet-injector.js.map +1 -0
  90. package/lib/injectors/{piral.d.ts → piral-injector.d.ts} +1 -0
  91. package/lib/injectors/{piral.js → piral-injector.js} +20 -22
  92. package/lib/injectors/piral-injector.js.map +1 -0
  93. package/lib/messages.d.ts +79 -1
  94. package/lib/messages.js +89 -2
  95. package/lib/messages.js.map +1 -1
  96. package/lib/plugin.js +27 -2
  97. package/lib/plugin.js.map +1 -1
  98. package/lib/release.d.ts +1 -1
  99. package/lib/release.js +35 -3
  100. package/lib/release.js.map +1 -1
  101. package/lib/types/common.d.ts +1 -1
  102. package/lib/types/internal.d.ts +9 -1
  103. package/lib/types/public.d.ts +1 -1
  104. package/package.json +6 -4
  105. package/src/apps/debug-pilet.ts +28 -48
  106. package/src/apps/debug-piral.ts +22 -37
  107. package/src/apps/new-pilet.ts +9 -14
  108. package/src/apps/new-piral.ts +16 -5
  109. package/src/apps/publish-pilet.ts +10 -3
  110. package/src/apps/publish-piral.ts +21 -6
  111. package/src/apps/upgrade-pilet.ts +4 -12
  112. package/src/apps/upgrade-piral.ts +2 -2
  113. package/src/bundler.test.ts +1 -1
  114. package/src/bundler.ts +2 -2
  115. package/src/commands.ts +17 -9
  116. package/src/common/browser.ts +12 -8
  117. package/src/common/clients/index.ts +33 -0
  118. package/src/common/clients/lerna.ts +61 -1
  119. package/src/common/clients/npm.ts +32 -15
  120. package/src/common/clients/pnpm.ts +39 -10
  121. package/src/common/clients/rush.ts +111 -0
  122. package/src/common/clients/yarn.ts +41 -12
  123. package/src/common/declaration.ts +15 -9
  124. package/src/common/emulator.ts +3 -3
  125. package/src/common/http.ts +56 -19
  126. package/src/common/info.ts +6 -1
  127. package/src/common/injectors.ts +46 -17
  128. package/src/common/inspect.ts +2 -1
  129. package/src/common/interactive.test.ts +3 -0
  130. package/src/common/interactive.ts +49 -1
  131. package/src/common/io.ts +1 -1
  132. package/src/common/log.ts +9 -1
  133. package/src/common/npm.test.ts +109 -76
  134. package/src/common/npm.ts +119 -146
  135. package/src/common/pack.test.ts +1 -1
  136. package/src/common/pack.ts +2 -2
  137. package/src/common/package.ts +19 -10
  138. package/src/common/port.ts +10 -0
  139. package/src/common/scaffold.ts +6 -2
  140. package/src/common/version.ts +4 -4
  141. package/src/external/index.ts +2 -1
  142. package/src/helpers.test.ts +5 -5
  143. package/src/helpers.ts +7 -7
  144. package/src/injectors/{pilet.test.ts → pilet-injector.test.ts} +10 -1
  145. package/src/injectors/{pilet.ts → pilet-injector.ts} +36 -28
  146. package/src/injectors/{piral.test.ts → piral-injector.test.ts} +5 -1
  147. package/src/injectors/{piral.ts → piral-injector.ts} +24 -17
  148. package/src/messages.ts +88 -1
  149. package/src/plugin.ts +34 -5
  150. package/src/release.ts +47 -5
  151. package/src/types/common.ts +1 -1
  152. package/src/types/internal.ts +6 -1
  153. package/src/types/public.ts +1 -1
  154. package/lib/injectors/pilet.js.map +0 -1
  155. package/lib/injectors/piral.js.map +0 -1
@@ -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,24 +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>) {
41
+ const ms = new MemoryStream();
42
+ await runYarnProcess(['add', packageRef, ...convert(flags)], target, ms);
43
+ log('generalDebug_0003', `Yarn@1 install package result: ${ms.value}`);
44
+ return ms.value;
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
+
36
68
  try {
37
- const ms = new MemoryStream();
38
- await runYarnProcess(['add', packageRef, ...convert(flags)], target, ms);
39
- log('generalDebug_0003', `Yarn install package result: ${ms.value}`);
40
- return ms.value;
41
- } catch (ex) {
42
- log(
43
- 'generalError_0002',
44
- `Could not install the package "${packageRef}" using Yarn. Make sure Yarn@1 is correctly installed and accessible: ${ex}`,
45
- );
46
- throw ex;
69
+ await runYarnProcess(['workspaces', 'info'], target, ms);
70
+ } catch (e) {
71
+ log('generalDebug_0003', `yarn workspaces error: ${e}`);
72
+ return {};
47
73
  }
74
+
75
+ log('generalDebug_0003', `yarn workspaces result: ${ms.value}`);
76
+ return JSON.parse(ms.value);
48
77
  }
@@ -16,10 +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
- return resolve(projectDir, piletApiTypings);
19
+
20
+ return [
21
+ {
22
+ file: resolve(projectDir, piletApiTypings),
23
+ name: 'PiletApi',
24
+ },
25
+ ];
20
26
  } catch (err) {
21
27
  log('generalError_0002', `Could not find the root API of "piral-base" from "${root}": ${err}`);
22
- return undefined;
28
+ return [];
23
29
  }
24
30
  }
25
31
 
@@ -142,15 +148,15 @@ export async function createPiralDeclaration(
142
148
  root,
143
149
  files,
144
150
  types: findDeclaredTypings(root),
145
- apis: [
146
- {
147
- file: findPiralBaseApi(root),
148
- name: 'PiletApi',
149
- },
150
- ],
151
+ apis: findPiralBaseApi(root),
151
152
  imports: externals,
152
153
  logLevel,
153
154
  logger: createLogger(),
154
155
  };
155
- return await createDeclarationFile(options, baseDir, target, forceOverwrite);
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.');
156
162
  }
@@ -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 { createPackage, makeExternals } from './npm';
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 createPackage(rootDir);
141
+ await createNpmPackage(rootDir);
142
142
 
143
143
  // get all files
144
144
  const names = await getFileNames(rootDir);
@@ -1,17 +1,14 @@
1
1
  import { join } from 'path';
2
2
  import { Agent } from 'https';
3
3
  import { Stream } from 'stream';
4
- import { platform, tmpdir } from 'os';
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 {
@@ -60,27 +57,35 @@ export function downloadFile(target: string, ca?: Buffer): Promise<Array<string>
60
57
  });
61
58
  }
62
59
 
63
- export interface PostFileResult {
60
+ export interface PostFormResult {
64
61
  status: number;
65
62
  success: boolean;
66
63
  response?: object;
67
64
  }
68
65
 
69
- export function postFile(
66
+ export type FormDataObj = Record<string, string | [Buffer, string]>;
67
+
68
+ export function postForm(
70
69
  target: string,
71
70
  scheme: PiletPublishScheme,
72
71
  key: string,
73
- file: Buffer,
74
- customFields: Record<string, string> = {},
72
+ formData: FormDataObj,
75
73
  customHeaders: Record<string, string> = {},
76
74
  ca?: Buffer,
77
- ): Promise<PostFileResult> {
78
- const form = new FormData();
75
+ interactive = false,
76
+ ): Promise<PostFormResult> {
79
77
  const httpsAgent = ca ? new Agent({ ca }) : undefined;
78
+ const form = new FormData();
80
79
 
81
- Object.keys(customFields).forEach((key) => form.append(key, customFields[key]));
80
+ Object.keys(formData).forEach((key) => {
81
+ const value = formData[key];
82
82
 
83
- form.append('file', file, 'pilet.tgz');
83
+ if (typeof value === 'string') {
84
+ form.append(key, value);
85
+ } else {
86
+ form.append(key, value[0], value[1]);
87
+ }
88
+ });
84
89
 
85
90
  const headers: Record<string, string> = {
86
91
  ...form.getHeaders(),
@@ -114,16 +119,34 @@ export function postFile(
114
119
  maxBodyLength: Infinity,
115
120
  })
116
121
  .then(
117
- (res) => ({
118
- status: res.status,
119
- success: true,
120
- response: res.data,
121
- }),
122
+ (res) => {
123
+ return {
124
+ status: res.status,
125
+ success: true,
126
+ response: res.data,
127
+ };
128
+ },
122
129
  (error) => {
123
130
  if (error.response) {
124
131
  // The request was made and the server responded with a status code
125
132
  // that falls out of the range of 2xx
126
133
  const { data, statusText, status } = error.response;
134
+
135
+ if (interactive && 'interactiveAuth' in data) {
136
+ const { interactiveAuth } = data;
137
+
138
+ if (typeof interactiveAuth === 'string') {
139
+ log(
140
+ 'generalDebug_0003',
141
+ `Received status "${status}" from HTTP - trying interactive log in to "${interactiveAuth}".`,
142
+ );
143
+
144
+ return getTokenInteractively(interactiveAuth, httpsAgent).then(({ mode, token }) =>
145
+ postForm(target, mode, token, formData, customHeaders, ca, false),
146
+ );
147
+ }
148
+ }
149
+
127
150
  const message = getMessage(data) || '';
128
151
  log('unsuccessfulHttpPost_0066', statusText, status, message);
129
152
  return {
@@ -164,3 +187,17 @@ export function postFile(
164
187
  },
165
188
  );
166
189
  }
190
+
191
+ export function postFile(
192
+ target: string,
193
+ scheme: PiletPublishScheme,
194
+ key: string,
195
+ file: Buffer,
196
+ customFields: Record<string, string> = {},
197
+ customHeaders: Record<string, string> = {},
198
+ ca?: Buffer,
199
+ interactive = false,
200
+ ): Promise<PostFormResult> {
201
+ const data: FormDataObj = { ...customFields, file: [file, 'pilet.tgz'] };
202
+ return postForm(target, scheme, key, data, customHeaders, ca, interactive);
203
+ }
@@ -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
+ };
@@ -1,25 +1,9 @@
1
1
  import chalk from 'chalk';
2
- import { KrasConfigurationInjectors } from 'kras';
2
+ import { resolve } from 'path';
3
3
  import { liveIcon, settingsIcon } from './emoji';
4
4
  import { logInfo, log, logReset } from './log';
5
5
  import { Bundler } from '../types';
6
6
 
7
- export function reorderInjectors(injectorName: string, injectorConfig: any, injectors: KrasConfigurationInjectors) {
8
- return {
9
- script: injectors.script || {
10
- active: true,
11
- },
12
- har: injectors.har || {
13
- active: true,
14
- },
15
- json: injectors.json || {
16
- active: true,
17
- },
18
- [injectorName]: injectorConfig,
19
- ...injectors,
20
- };
21
- }
22
-
23
7
  export function notifyServerOnline(bundlers: Array<Bundler>, path: string, api: string | false) {
24
8
  return (svc: any) => {
25
9
  log('generalDebug_0003', `The kras server for debugging is online!`);
@@ -30,3 +14,48 @@ export function notifyServerOnline(bundlers: Array<Bundler>, path: string, api:
30
14
  bundlers.forEach((bundler) => bundler.start());
31
15
  };
32
16
  }
17
+
18
+ export function createInitialKrasConfig(
19
+ directory: string,
20
+ map: Record<string, string> = {},
21
+ sources: Array<string> = [],
22
+ feed: string | Array<string> = [],
23
+ ) {
24
+ return {
25
+ api: '/manage-mock-server',
26
+ directory,
27
+ map: {
28
+ '/': '',
29
+ ...map,
30
+ },
31
+ ssl: undefined,
32
+ sources,
33
+ injectorDirs: [resolve(__dirname, '../injectors')],
34
+ injectors: {
35
+ script: {
36
+ active: true,
37
+ },
38
+ har: {
39
+ active: true,
40
+ delay: false,
41
+ },
42
+ json: {
43
+ active: true,
44
+ randomize: true,
45
+ },
46
+ piral: {
47
+ active: true,
48
+ headers: {},
49
+ },
50
+ pilet: {
51
+ active: true,
52
+ meta: 'debug-meta.json',
53
+ headers: {},
54
+ feed,
55
+ },
56
+ proxy: {
57
+ active: true,
58
+ },
59
+ },
60
+ };
61
+ }
@@ -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 JSON.parse(content);
12
+ return jju.parse(content);
12
13
  }
13
14
 
14
15
  function getPiletMainPath(data: PackageData, files: PackageFiles) {
@@ -3,6 +3,9 @@ import { promptConfirm, promptSelect } from './interactive';
3
3
  const answer = 'Yes, really';
4
4
 
5
5
  jest.mock('../external', () => ({
6
+ rc(_, cfg) {
7
+ return cfg;
8
+ },
6
9
  inquirer: {
7
10
  prompt: (...any) => {
8
11
  return Promise.resolve({ q: answer });
@@ -1,4 +1,9 @@
1
- import { inquirer } from '../external';
1
+ import { Agent } from 'https';
2
+ import { openBrowserAt } from './browser';
3
+ import { standardHeaders } from './info';
4
+ import { logSuspend } from './log';
5
+ import { axios, inquirer } from '../external';
6
+ import { PiletPublishScheme } from '../types';
2
7
 
3
8
  export function promptSelect(message: string, values: Array<string>, defaultValue: string): Promise<string> {
4
9
  const questions = [
@@ -24,3 +29,46 @@ export function promptConfirm(message: string, defaultValue: boolean): Promise<b
24
29
  ];
25
30
  return inquirer.prompt(questions).then((answers: any) => answers.q);
26
31
  }
32
+
33
+ type TokenResult = Promise<{ mode: PiletPublishScheme; token: string }>;
34
+
35
+ const tokenRetrievers: Record<string, TokenResult> = {};
36
+
37
+ export function getTokenInteractively(url: string, httpsAgent: Agent): TokenResult {
38
+ if (!(url in tokenRetrievers)) {
39
+ const logResume = logSuspend();
40
+
41
+ tokenRetrievers[url] = axios.default
42
+ .post(
43
+ url,
44
+ {
45
+ clientId: 'piral-cli',
46
+ clientName: 'Piral CLI',
47
+ description: 'Authorize the Piral CLI temporarily to perform actions in your name.',
48
+ },
49
+ {
50
+ headers: {
51
+ ...standardHeaders,
52
+ 'content-type': 'application/json',
53
+ },
54
+ httpsAgent,
55
+ },
56
+ )
57
+ .then((res) => {
58
+ const { loginUrl, callbackUrl, expires } = res.data;
59
+ console.log(`Use the URL below to complete the login. The link expires at ${new Date(expires)}.`);
60
+ console.log('===');
61
+ console.log(loginUrl);
62
+ console.log('===');
63
+
64
+ openBrowserAt(loginUrl);
65
+
66
+ return axios.default
67
+ .get(callbackUrl)
68
+ .then(({ data }) => ({ ...data }))
69
+ .finally(logResume);
70
+ });
71
+ }
72
+
73
+ return tokenRetrievers[url];
74
+ }
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\-\*]+$/.test(curr) && !preferences.find((ext) => curr.endsWith(ext))) {
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}`);
package/src/common/log.ts CHANGED
@@ -8,6 +8,7 @@ import { LogLevels, QuickMessage } from '../types';
8
8
 
9
9
  type Messages = typeof messages;
10
10
  type MessageTypes = keyof Messages;
11
+ let currentProgress: string = undefined;
11
12
 
12
13
  const logger = (() => {
13
14
  try {
@@ -92,7 +93,8 @@ export function logFail(message: string, ...args: Array<string | number | boolea
92
93
  }
93
94
 
94
95
  export function progress(message: string, ...args: Array<string | number | boolean>) {
95
- logger.progress(format(message, ...args));
96
+ currentProgress = format(message, ...args)
97
+ logger.progress(currentProgress);
96
98
  }
97
99
 
98
100
  export function logReset() {
@@ -100,6 +102,12 @@ export function logReset() {
100
102
  logger.stopSpinner();
101
103
  }
102
104
 
105
+ export function logSuspend() {
106
+ logReset();
107
+
108
+ return () => logger.progress(currentProgress);
109
+ }
110
+
103
111
  export function fail<T extends MessageTypes>(type: T, ...args: Parameters<Messages[T]>): never {
104
112
  const message = log(type, ...args);
105
113
  const error = new Error(message);