piral-cli 0.15.0-alpha.4231 → 0.15.0-alpha.4311

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 (94) 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 +3 -3
  7. package/lib/apps/new-pilet.js.map +1 -1
  8. package/lib/apps/new-piral.js +7 -3
  9. package/lib/apps/new-piral.js.map +1 -1
  10. package/lib/apps/publish-piral.d.ts +2 -2
  11. package/lib/apps/publish-piral.js +9 -8
  12. package/lib/apps/publish-piral.js.map +1 -1
  13. package/lib/apps/upgrade-pilet.js +2 -2
  14. package/lib/apps/upgrade-pilet.js.map +1 -1
  15. package/lib/apps/upgrade-piral.js +2 -2
  16. package/lib/apps/upgrade-piral.js.map +1 -1
  17. package/lib/commands.js +10 -10
  18. package/lib/commands.js.map +1 -1
  19. package/lib/common/clients/index.d.ts +3 -1
  20. package/lib/common/clients/index.js +3 -1
  21. package/lib/common/clients/index.js.map +1 -1
  22. package/lib/common/clients/npm.d.ts +1 -0
  23. package/lib/common/clients/npm.js +7 -1
  24. package/lib/common/clients/npm.js.map +1 -1
  25. package/lib/common/clients/pnp.d.ts +6 -0
  26. package/lib/common/clients/pnp.js +95 -0
  27. package/lib/common/clients/pnp.js.map +1 -0
  28. package/lib/common/clients/yarn.js +3 -3
  29. package/lib/common/clients/yarn.js.map +1 -1
  30. package/lib/common/http.d.ts +4 -2
  31. package/lib/common/http.js +25 -11
  32. package/lib/common/http.js.map +1 -1
  33. package/lib/common/injectors.d.ts +36 -7
  34. package/lib/common/injectors.js +39 -11
  35. package/lib/common/injectors.js.map +1 -1
  36. package/lib/common/interactive.js +10 -5
  37. package/lib/common/interactive.js.map +1 -1
  38. package/lib/common/log.d.ts +1 -0
  39. package/lib/common/log.js +9 -2
  40. package/lib/common/log.js.map +1 -1
  41. package/lib/common/npm.d.ts +1 -1
  42. package/lib/common/npm.js +13 -5
  43. package/lib/common/npm.js.map +1 -1
  44. package/lib/common/port.d.ts +1 -0
  45. package/lib/common/port.js +11 -1
  46. package/lib/common/port.js.map +1 -1
  47. package/lib/helpers.d.ts +3 -3
  48. package/lib/helpers.js +10 -10
  49. package/lib/helpers.js.map +1 -1
  50. package/lib/injectors/{pilet.d.ts → pilet-injector.d.ts} +1 -0
  51. package/lib/injectors/{pilet.js → pilet-injector.js} +27 -29
  52. package/lib/injectors/pilet-injector.js.map +1 -0
  53. package/lib/injectors/{piral.d.ts → piral-injector.d.ts} +1 -0
  54. package/lib/injectors/{piral.js → piral-injector.js} +20 -22
  55. package/lib/injectors/piral-injector.js.map +1 -0
  56. package/lib/messages.d.ts +83 -5
  57. package/lib/messages.js +95 -8
  58. package/lib/messages.js.map +1 -1
  59. package/lib/release.d.ts +1 -1
  60. package/lib/release.js +32 -5
  61. package/lib/release.js.map +1 -1
  62. package/lib/types/common.d.ts +1 -1
  63. package/lib/types/public.d.ts +1 -1
  64. package/package.json +3 -3
  65. package/src/apps/debug-pilet.ts +28 -48
  66. package/src/apps/debug-piral.ts +22 -37
  67. package/src/apps/new-pilet.ts +3 -2
  68. package/src/apps/new-piral.ts +9 -2
  69. package/src/apps/publish-piral.ts +21 -10
  70. package/src/apps/upgrade-pilet.ts +2 -1
  71. package/src/apps/upgrade-piral.ts +2 -1
  72. package/src/commands.ts +13 -13
  73. package/src/common/clients/index.ts +3 -1
  74. package/src/common/clients/npm.ts +4 -0
  75. package/src/common/clients/pnp.ts +77 -0
  76. package/src/common/clients/yarn.ts +3 -3
  77. package/src/common/http.ts +37 -14
  78. package/src/common/injectors.ts +46 -17
  79. package/src/common/interactive.ts +12 -7
  80. package/src/common/log.ts +9 -1
  81. package/src/common/npm.ts +21 -6
  82. package/src/common/port.ts +10 -0
  83. package/src/helpers.test.ts +5 -5
  84. package/src/helpers.ts +7 -7
  85. package/src/injectors/{pilet.test.ts → pilet-injector.test.ts} +10 -1
  86. package/src/injectors/{pilet.ts → pilet-injector.ts} +33 -25
  87. package/src/injectors/{piral.test.ts → piral-injector.test.ts} +5 -1
  88. package/src/injectors/{piral.ts → piral-injector.ts} +24 -17
  89. package/src/messages.ts +93 -6
  90. package/src/release.ts +40 -6
  91. package/src/types/common.ts +1 -1
  92. package/src/types/public.ts +1 -1
  93. package/lib/injectors/pilet.js.map +0 -1
  94. package/lib/injectors/piral.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import { dirname, join, resolve } from 'path';
2
- import { readKrasConfig, krasrc, buildKrasWithCli, defaultConfig } from 'kras';
2
+ import { readKrasConfig, krasrc, buildKrasWithCli } from 'kras';
3
3
  import { callPiralDebug } from '../bundler';
4
4
  import { LogLevels } from '../types';
5
5
  import {
@@ -7,7 +7,6 @@ import {
7
7
  retrievePiralRoot,
8
8
  openBrowser,
9
9
  checkCliCompatibility,
10
- reorderInjectors,
11
10
  notifyServerOnline,
12
11
  setLogLevel,
13
12
  progress,
@@ -16,6 +15,8 @@ import {
16
15
  normalizePublicUrl,
17
16
  logDone,
18
17
  getDestination,
18
+ createInitialKrasConfig,
19
+ getAvailablePort,
19
20
  } from '../common';
20
21
 
21
22
  export interface DebugPiralOptions {
@@ -99,15 +100,13 @@ export const debugPiralDefaults: DebugPiralOptions = {
99
100
  optimizeModules: false,
100
101
  };
101
102
 
102
- const injectorName = resolve(__dirname, '../injectors/piral.js');
103
-
104
103
  export async function debugPiral(baseDir = process.cwd(), options: DebugPiralOptions = {}) {
105
104
  const {
106
105
  entry = debugPiralDefaults.entry,
107
106
  target = debugPiralDefaults.target,
108
- port = debugPiralDefaults.port,
109
107
  open = debugPiralDefaults.open,
110
108
  hmr = debugPiralDefaults.hmr,
109
+ port: originalPort = debugPiralDefaults.port,
111
110
  publicUrl: originalPublicUrl = debugPiralDefaults.publicUrl,
112
111
  logLevel = debugPiralDefaults.logLevel,
113
112
  optimizeModules = debugPiralDefaults.optimizeModules,
@@ -125,30 +124,9 @@ export async function debugPiral(baseDir = process.cwd(), options: DebugPiralOpt
125
124
  const entryFiles = await retrievePiralRoot(fullBase, entry);
126
125
  const { externals, name, root, ignored } = await retrievePiletsInfo(entryFiles);
127
126
  const dest = getDestination(entryFiles, resolve(fullBase, target));
128
- const krasConfig = readKrasConfig({ port }, krasrc);
129
127
 
130
128
  await checkCliCompatibility(root);
131
129
 
132
- if (krasConfig.directory === undefined) {
133
- krasConfig.directory = join(dirname(entryFiles), 'mocks');
134
- }
135
-
136
- if (krasConfig.ssl === undefined) {
137
- krasConfig.ssl = undefined;
138
- }
139
-
140
- if (krasConfig.map === undefined) {
141
- krasConfig.map = {};
142
- }
143
-
144
- if (krasConfig.api === undefined) {
145
- krasConfig.api = '/manage-mock-server';
146
- }
147
-
148
- if (krasConfig.injectors === undefined) {
149
- krasConfig.injectors = defaultConfig.injectors;
150
- }
151
-
152
130
  await hooks.beforeBuild?.({ root, publicUrl, externals, entryFiles, name });
153
131
 
154
132
  const bundler = await callPiralDebug(
@@ -174,18 +152,25 @@ export async function debugPiral(baseDir = process.cwd(), options: DebugPiralOpt
174
152
  hooks.afterBuild?.({ ...args, root, publicUrl, externals, entryFiles, name, bundler, ...dest });
175
153
  });
176
154
 
177
- const { piral: piralInjector, ...otherInjectors } = krasConfig.injectors;
178
- const injectorConfig = {
179
- ...piralInjector,
180
- feed,
181
- active: true,
182
- handle: ['/'],
183
- publicUrl,
184
- bundler,
155
+ const krasBaseConfig = resolve(fullBase, krasrc);
156
+ const krasRootConfig = resolve(root, krasrc);
157
+ const initial = createInitialKrasConfig(join(dirname(entryFiles), 'mocks'));
158
+ const required = {
159
+ injectors: {
160
+ piral: {
161
+ active: true,
162
+ handle: ['/'],
163
+ feed,
164
+ publicUrl,
165
+ bundler,
166
+ },
167
+ pilet: {
168
+ active: false,
169
+ },
170
+ },
185
171
  };
186
-
187
- krasConfig.map['/'] = '';
188
- krasConfig.injectors = reorderInjectors(injectorName, injectorConfig, otherInjectors);
172
+ const port = await getAvailablePort(originalPort);
173
+ const krasConfig = readKrasConfig({ port, initial, required }, krasBaseConfig, krasRootConfig);
189
174
 
190
175
  log('generalVerbose_0004', `Using kras with configuration: ${JSON.stringify(krasConfig, undefined, 2)}`);
191
176
 
@@ -102,7 +102,7 @@ export const newPiletDefaults: NewPiletOptions = {
102
102
  install: true,
103
103
  template: undefined,
104
104
  logLevel: LogLevels.info,
105
- npmClient: config.npmClient,
105
+ npmClient: undefined,
106
106
  bundlerName: 'none',
107
107
  variables: {},
108
108
  };
@@ -119,6 +119,7 @@ export async function newPilet(baseDir = process.cwd(), options: NewPiletOptions
119
119
  logLevel = newPiletDefaults.logLevel,
120
120
  bundlerName = newPiletDefaults.bundlerName,
121
121
  variables = newPiletDefaults.variables,
122
+ npmClient: defaultNpmClient = newPiletDefaults.npmClient,
122
123
  } = options;
123
124
  const fullBase = resolve(process.cwd(), baseDir);
124
125
  const root = resolve(fullBase, target);
@@ -128,7 +129,7 @@ export async function newPilet(baseDir = process.cwd(), options: NewPiletOptions
128
129
  const success = await createDirectory(root);
129
130
 
130
131
  if (success) {
131
- const npmClient = await determineNpmClient(root, options.npmClient);
132
+ const npmClient = await determineNpmClient(root, defaultNpmClient);
132
133
  const projectName = basename(root);
133
134
 
134
135
  progress(`Scaffolding new pilet in %s ...`, root);
@@ -1,4 +1,5 @@
1
1
  import { resolve, basename } from 'path';
2
+ import { frameworkKeys } from '../helpers';
2
3
  import { LogLevels, Framework, NpmClientType } from '../types';
3
4
  import {
4
5
  ForceOverwrite,
@@ -100,7 +101,7 @@ export const newPiralDefaults: NewPiralOptions = {
100
101
  install: true,
101
102
  template: 'default',
102
103
  logLevel: LogLevels.info,
103
- npmClient: config.npmClient,
104
+ npmClient: undefined,
104
105
  bundlerName: 'none',
105
106
  variables: {},
106
107
  };
@@ -119,15 +120,21 @@ export async function newPiral(baseDir = process.cwd(), options: NewPiralOptions
119
120
  logLevel = newPiralDefaults.logLevel,
120
121
  bundlerName = newPiralDefaults.bundlerName,
121
122
  variables = newPiralDefaults.variables,
123
+ npmClient: defaultNpmClient = newPiralDefaults.npmClient,
122
124
  } = options;
123
125
  const fullBase = resolve(process.cwd(), baseDir);
124
126
  const root = resolve(fullBase, target);
127
+
128
+ if (!frameworkKeys.includes(framework)) {
129
+ fail('generalError_0002', `The "framework" value must be one of: ${frameworkKeys.join(', ')}`);
130
+ }
131
+
125
132
  setLogLevel(logLevel);
126
133
  progress('Preparing source and target ...');
127
134
  const success = await createDirectory(root);
128
135
 
129
136
  if (success) {
130
- const npmClient = await determineNpmClient(root, options.npmClient);
137
+ const npmClient = await determineNpmClient(root, defaultNpmClient);
131
138
  const packageRef = combinePackageRef(framework, version, 'registry');
132
139
  const projectName = basename(root);
133
140
 
@@ -1,7 +1,17 @@
1
1
  import { resolve } from 'path';
2
2
  import { publishArtifacts } from '../release';
3
+ import {
4
+ setLogLevel,
5
+ progress,
6
+ checkExists,
7
+ fail,
8
+ logDone,
9
+ logReset,
10
+ publishNpmPackage,
11
+ matchFiles,
12
+ log,
13
+ } from '../common';
3
14
  import { LogLevels, PiralBuildType } from '../types';
4
- import { setLogLevel, progress, checkExists, fail, logDone, logReset, publishNpmPackage, matchFiles } from '../common';
5
15
 
6
16
  export interface PublishPiralOptions {
7
17
  /**
@@ -15,9 +25,9 @@ export interface PublishPiralOptions {
15
25
  logLevel?: LogLevels;
16
26
 
17
27
  /**
18
- * The additional fields to supply for the provider.
28
+ * The options to supply for the provider.
19
29
  */
20
- fields?: Record<string, string>;
30
+ opts?: Record<string, string>;
21
31
 
22
32
  /**
23
33
  * Defines if authorization tokens can be retrieved interactively.
@@ -40,7 +50,7 @@ export const publishPiralDefaults: PublishPiralOptions = {
40
50
  logLevel: LogLevels.info,
41
51
  type: 'all',
42
52
  provider: 'none',
43
- fields: {},
53
+ opts: {},
44
54
  interactive: false,
45
55
  };
46
56
 
@@ -59,6 +69,7 @@ async function publishEmulator(
59
69
  }
60
70
 
61
71
  const files = await matchFiles(directory, '*.tgz');
72
+ log('generalDebug_0003', `Found ${files.length} in "${directory}": ${files.join(', ')}`);
62
73
 
63
74
  if (files.length !== 1) {
64
75
  fail('publishEmulatorFilesUnexpected_0111', directory);
@@ -70,8 +81,7 @@ async function publishEmulator(
70
81
  return p;
71
82
  }, [] as Array<string>);
72
83
 
73
- //TODO support interactive here, too?
74
- await publishNpmPackage(directory, file, flags);
84
+ await publishNpmPackage(directory, file, flags, interactive);
75
85
  }
76
86
 
77
87
  async function publishRelease(
@@ -90,7 +100,8 @@ async function publishRelease(
90
100
  }
91
101
 
92
102
  const files = await matchFiles(directory, '**/*');
93
- await publishArtifacts(providerName, files, args, interactive);
103
+ log('generalDebug_0003', `Found ${files.length} in "${directory}": ${files.join(', ')}`);
104
+ await publishArtifacts(providerName, directory, files, args, interactive);
94
105
  }
95
106
 
96
107
  export async function publishPiral(baseDir = process.cwd(), options: PublishPiralOptions = {}) {
@@ -98,7 +109,7 @@ export async function publishPiral(baseDir = process.cwd(), options: PublishPira
98
109
  source = publishPiralDefaults.source,
99
110
  type = publishPiralDefaults.type,
100
111
  logLevel = publishPiralDefaults.logLevel,
101
- fields = publishPiralDefaults.fields,
112
+ opts = publishPiralDefaults.opts,
102
113
  provider = publishPiralDefaults.provider,
103
114
  interactive = publishPiralDefaults.interactive,
104
115
  } = options;
@@ -113,14 +124,14 @@ export async function publishPiral(baseDir = process.cwd(), options: PublishPira
113
124
 
114
125
  if (type !== 'release') {
115
126
  progress('Publishing emulator package ...');
116
- await publishEmulator(fullBase, source, fields, interactive);
127
+ await publishEmulator(fullBase, source, opts, interactive);
117
128
  logDone(`Successfully published emulator.`);
118
129
  logReset();
119
130
  }
120
131
 
121
132
  if (type !== 'emulator') {
122
133
  progress('Publishing release files ...');
123
- await publishRelease(fullBase, source, provider, fields, interactive);
134
+ await publishRelease(fullBase, source, provider, opts, interactive);
124
135
  logDone(`Successfully published release.`);
125
136
  logReset();
126
137
  }
@@ -88,6 +88,7 @@ export async function upgradePilet(baseDir = process.cwd(), options: UpgradePile
88
88
  logLevel = upgradePiletDefaults.logLevel,
89
89
  install = upgradePiletDefaults.install,
90
90
  variables = upgradePiletDefaults.variables,
91
+ npmClient: defaultNpmClient = upgradePiletDefaults.npmClient,
91
92
  } = options;
92
93
  const fullBase = resolve(process.cwd(), baseDir);
93
94
  const root = resolve(fullBase, target);
@@ -98,7 +99,7 @@ export async function upgradePilet(baseDir = process.cwd(), options: UpgradePile
98
99
  fail('invalidPiletTarget_0040');
99
100
  }
100
101
 
101
- const npmClient = await determineNpmClient(root, options.npmClient);
102
+ const npmClient = await determineNpmClient(root, defaultNpmClient);
102
103
  const pckg = await readJson(root, 'package.json');
103
104
  const { devDependencies = {}, dependencies = {}, piral, source } = pckg;
104
105
 
@@ -80,6 +80,7 @@ export async function upgradePiral(baseDir = process.cwd(), options: UpgradePira
80
80
  target = upgradePiralDefaults.target,
81
81
  logLevel = upgradePiralDefaults.logLevel,
82
82
  install = upgradePiralDefaults.install,
83
+ npmClient: defaultNpmClient = upgradePiralDefaults.npmClient,
83
84
  } = options;
84
85
  const fullBase = resolve(process.cwd(), baseDir);
85
86
  const root = resolve(fullBase, target);
@@ -91,7 +92,7 @@ export async function upgradePiral(baseDir = process.cwd(), options: UpgradePira
91
92
  fail('packageJsonNotFound_0020');
92
93
  }
93
94
 
94
- const npmClient = await determineNpmClient(root, options.npmClient);
95
+ const npmClient = await determineNpmClient(root, defaultNpmClient);
95
96
 
96
97
  progress(`Checking provided version ...`);
97
98
  const realVersion = await findSpecificVersion('piral-cli', version);
package/src/commands.ts CHANGED
@@ -6,9 +6,9 @@ import {
6
6
  forceOverwriteKeys,
7
7
  keyOfForceOverwrite,
8
8
  valueOfForceOverwrite,
9
- keyOfPiletLanguage,
10
- piletLanguageKeys,
11
- valueOfPiletLanguage,
9
+ keyOfSourceLanguage,
10
+ sourceLanguageKeys,
11
+ valueOfSourceLanguage,
12
12
  frameworkKeys,
13
13
  clientTypeKeys,
14
14
  schemaKeys,
@@ -205,9 +205,9 @@ const allCommands: Array<ToolCommand<any>> = [
205
205
  .choices('provider', availableReleaseProviders)
206
206
  .describe('provider', 'Sets the provider for publishing the release assets.')
207
207
  .default('provider', apps.publishPiralDefaults.provider)
208
- .option('fields', undefined)
209
- .describe('fields', 'Sets additional fields to be included in the feed service request.')
210
- .default('fields', apps.publishPiralDefaults.fields)
208
+ .option('opts', undefined)
209
+ .describe('opts', 'Sets the options to forward to the chosen provider.')
210
+ .default('opts', apps.publishPiralDefaults.opts)
211
211
  .boolean('interactive')
212
212
  .describe('interactive', 'Defines if authorization tokens can be retrieved interactively.')
213
213
  .default('interactive', apps.publishPiralDefaults.interactive)
@@ -221,7 +221,7 @@ const allCommands: Array<ToolCommand<any>> = [
221
221
  logLevel: args['log-level'] as LogLevels,
222
222
  type: args.type as PiralBuildType,
223
223
  provider: args.provider as string,
224
- fields: args.fields as Record<string, string>,
224
+ opts: args.opts as Record<string, string>,
225
225
  interactive: args.interactive as boolean,
226
226
  });
227
227
  },
@@ -297,9 +297,9 @@ const allCommands: Array<ToolCommand<any>> = [
297
297
  .choices('force-overwrite', forceOverwriteKeys)
298
298
  .describe('force-overwrite', 'Determines if files should be overwritten by the installation.')
299
299
  .default('force-overwrite', keyOfForceOverwrite(apps.newPiralDefaults.forceOverwrite))
300
- .choices('language', piletLanguageKeys)
300
+ .choices('language', sourceLanguageKeys)
301
301
  .describe('language', 'Determines the programming language for the new Piral instance.')
302
- .default('language', keyOfPiletLanguage(apps.newPiralDefaults.language))
302
+ .default('language', keyOfSourceLanguage(apps.newPiralDefaults.language))
303
303
  .string('template')
304
304
  .describe('template', 'Sets the boilerplate template package to be used when scaffolding.')
305
305
  .default('template', apps.newPiralDefaults.template)
@@ -324,7 +324,7 @@ const allCommands: Array<ToolCommand<any>> = [
324
324
  version: args.tag as string,
325
325
  registry: args.registry as string,
326
326
  forceOverwrite: valueOfForceOverwrite(args['force-overwrite'] as string),
327
- language: valueOfPiletLanguage(args.language as string),
327
+ language: valueOfSourceLanguage(args.language as string),
328
328
  install: args.install as boolean,
329
329
  template: args.template as string,
330
330
  logLevel: args['log-level'] as LogLevels,
@@ -682,9 +682,9 @@ const allCommands: Array<ToolCommand<any>> = [
682
682
  .number('log-level')
683
683
  .describe('log-level', 'Sets the log level to use (1-5).')
684
684
  .default('log-level', apps.newPiletDefaults.logLevel)
685
- .choices('language', piletLanguageKeys)
685
+ .choices('language', sourceLanguageKeys)
686
686
  .describe('language', 'Determines the programming language for the new pilet.')
687
- .default('language', keyOfPiletLanguage(apps.newPiletDefaults.language))
687
+ .default('language', keyOfSourceLanguage(apps.newPiletDefaults.language))
688
688
  .string('template')
689
689
  .describe('template', 'Sets the boilerplate template package to be used when scaffolding.')
690
690
  .default('template', apps.newPiletDefaults.template)
@@ -707,7 +707,7 @@ const allCommands: Array<ToolCommand<any>> = [
707
707
  source: args.source as string,
708
708
  registry: args.registry as string,
709
709
  forceOverwrite: valueOfForceOverwrite(args['force-overwrite'] as string),
710
- language: valueOfPiletLanguage(args.language as string),
710
+ language: valueOfSourceLanguage(args.language as string),
711
711
  logLevel: args['log-level'] as LogLevels,
712
712
  install: args.install as boolean,
713
713
  template: args.template as string,
@@ -1,5 +1,6 @@
1
1
  import * as lerna from './lerna';
2
2
  import * as npm from './npm';
3
+ import * as pnp from './pnp';
3
4
  import * as pnpm from './pnpm';
4
5
  import * as rush from './rush';
5
6
  import * as yarn from './yarn';
@@ -7,6 +8,7 @@ import * as yarn from './yarn';
7
8
  export const clients = {
8
9
  lerna,
9
10
  npm,
11
+ pnp,
10
12
  pnpm,
11
13
  rush,
12
14
  yarn,
@@ -14,7 +16,7 @@ export const clients = {
14
16
 
15
17
  type ClientName = keyof typeof clients;
16
18
 
17
- const directClients = ['npm', 'yarn', 'pnpm'];
19
+ const directClients = ['npm', 'pnp', 'yarn', 'pnpm'];
18
20
 
19
21
  export function isWrapperClient(client: ClientName) {
20
22
  return !directClients.includes(client);
@@ -47,6 +47,10 @@ export async function initProject(projectName: string, target: string) {}
47
47
 
48
48
  // Functions to exclusively use from npm client:
49
49
 
50
+ export async function loginUser() {
51
+ await runNpmProcess(['login'], '.');
52
+ }
53
+
50
54
  export async function unpackPackage(packageRef: string, target = '.', ...flags: Array<string>) {
51
55
  const ms = new MemoryStream();
52
56
  await runNpmProcess(['pack', packageRef, ...flags], target, ms);
@@ -0,0 +1,77 @@
1
+ import { resolve } from 'path';
2
+ import { log } from '../log';
3
+ import { findFile } from '../io';
4
+ import { runCommand } from '../scripts';
5
+ import { MemoryStream } from '../MemoryStream';
6
+
7
+ // Helpers:
8
+
9
+ function runYarnProcess(args: Array<string>, target: string, output?: NodeJS.WritableStream) {
10
+ log('generalDebug_0003', 'Starting the Yarn PnP process ...');
11
+ const cwd = resolve(process.cwd(), target);
12
+ return runCommand('yarn', args, cwd, output);
13
+ }
14
+
15
+ function convert(flags: Array<string>) {
16
+ return flags.map((flag) => {
17
+ switch (flag) {
18
+ case '--save-exact':
19
+ return '--exact';
20
+ case '--save-dev':
21
+ return '--dev';
22
+ case '--no-save':
23
+ // unfortunately no (https://github.com/yarnpkg/yarn/issues/1743)
24
+ return '';
25
+ default:
26
+ return flag;
27
+ }
28
+ });
29
+ }
30
+
31
+ // Client interface functions:
32
+
33
+ export async function installDependencies(target = '.', ...flags: Array<string>) {
34
+ const ms = new MemoryStream();
35
+ await runYarnProcess(['install', ...convert(flags)], target, ms);
36
+ log('generalDebug_0003', `Yarn PnP install dependencies result: ${ms.value}`);
37
+ return ms.value;
38
+ }
39
+
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 PnP install package result: ${ms.value}`);
44
+ return ms.value;
45
+ }
46
+
47
+ export async function detectClient(root: string) {
48
+ return !!(await findFile(root, '.pnp.cjs'));
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
+ }
@@ -7,7 +7,7 @@ import { MemoryStream } from '../MemoryStream';
7
7
  // Helpers:
8
8
 
9
9
  function runYarnProcess(args: Array<string>, target: string, output?: NodeJS.WritableStream) {
10
- log('generalDebug_0003', 'Starting the Yarn@1 process ...');
10
+ log('generalDebug_0003', 'Starting the Yarn Classic process ...');
11
11
  const cwd = resolve(process.cwd(), target);
12
12
  return runCommand('yarn', args, cwd, output);
13
13
  }
@@ -33,14 +33,14 @@ function convert(flags: Array<string>) {
33
33
  export async function installDependencies(target = '.', ...flags: Array<string>) {
34
34
  const ms = new MemoryStream();
35
35
  await runYarnProcess(['install', ...convert(flags)], target, ms);
36
- log('generalDebug_0003', `Yarn@1 install dependencies result: ${ms.value}`);
36
+ log('generalDebug_0003', `Yarn Classic install dependencies result: ${ms.value}`);
37
37
  return ms.value;
38
38
  }
39
39
 
40
40
  export async function installPackage(packageRef: string, target = '.', ...flags: Array<string>) {
41
41
  const ms = new MemoryStream();
42
42
  await runYarnProcess(['add', packageRef, ...convert(flags)], target, ms);
43
- log('generalDebug_0003', `Yarn@1 install package result: ${ms.value}`);
43
+ log('generalDebug_0003', `Yarn Classic install package result: ${ms.value}`);
44
44
  return ms.value;
45
45
  }
46
46
 
@@ -57,28 +57,35 @@ export function downloadFile(target: string, ca?: Buffer): Promise<Array<string>
57
57
  });
58
58
  }
59
59
 
60
- export interface PostFileResult {
60
+ export interface PostFormResult {
61
61
  status: number;
62
62
  success: boolean;
63
63
  response?: object;
64
64
  }
65
65
 
66
- export function postFile(
66
+ export type FormDataObj = Record<string, string | [Buffer, string]>;
67
+
68
+ export function postForm(
67
69
  target: string,
68
70
  scheme: PiletPublishScheme,
69
71
  key: string,
70
- file: Buffer,
71
- customFields: Record<string, string> = {},
72
+ formData: FormDataObj,
72
73
  customHeaders: Record<string, string> = {},
73
74
  ca?: Buffer,
74
75
  interactive = false,
75
- ): Promise<PostFileResult> {
76
- const form = new FormData();
76
+ ): Promise<PostFormResult> {
77
77
  const httpsAgent = ca ? new Agent({ ca }) : undefined;
78
+ const form = new FormData();
78
79
 
79
- Object.keys(customFields).forEach((key) => form.append(key, customFields[key]));
80
+ Object.keys(formData).forEach((key) => {
81
+ const value = formData[key];
80
82
 
81
- 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
+ });
82
89
 
83
90
  const headers: Record<string, string> = {
84
91
  ...form.getHeaders(),
@@ -112,11 +119,13 @@ export function postFile(
112
119
  maxBodyLength: Infinity,
113
120
  })
114
121
  .then(
115
- (res) => ({
116
- status: res.status,
117
- success: true,
118
- response: res.data,
119
- }),
122
+ (res) => {
123
+ return {
124
+ status: res.status,
125
+ success: true,
126
+ response: res.data,
127
+ };
128
+ },
120
129
  (error) => {
121
130
  if (error.response) {
122
131
  // The request was made and the server responded with a status code
@@ -133,7 +142,7 @@ export function postFile(
133
142
  );
134
143
 
135
144
  return getTokenInteractively(interactiveAuth, httpsAgent).then(({ mode, token }) =>
136
- postFile(target, mode, token, file, customFields, customHeaders, ca, false),
145
+ postForm(target, mode, token, formData, customHeaders, ca, false),
137
146
  );
138
147
  }
139
148
  }
@@ -178,3 +187,17 @@ export function postFile(
178
187
  },
179
188
  );
180
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,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
+ }