piral-cli 1.5.0-beta.6658 → 1.5.0-beta.6685

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 (77) hide show
  1. package/lib/api.d.ts +1 -2
  2. package/lib/api.js +1 -18
  3. package/lib/api.js.map +1 -1
  4. package/lib/apps/build-pilet.js +14 -37
  5. package/lib/apps/build-pilet.js.map +1 -1
  6. package/lib/apps/build-piral.js +29 -104
  7. package/lib/apps/build-piral.js.map +1 -1
  8. package/lib/apps/debug-pilet.js +8 -2
  9. package/lib/apps/debug-pilet.js.map +1 -1
  10. package/lib/apps/debug-piral.js +5 -1
  11. package/lib/apps/debug-piral.js.map +1 -1
  12. package/lib/apps/publish-pilet.d.ts +11 -2
  13. package/lib/apps/publish-pilet.js +16 -43
  14. package/lib/apps/publish-pilet.js.map +1 -1
  15. package/lib/apps/publish-piral.d.ts +37 -7
  16. package/lib/apps/publish-piral.js +62 -47
  17. package/lib/apps/publish-piral.js.map +1 -1
  18. package/lib/build/bundler-calls.js +4 -1
  19. package/lib/build/bundler-calls.js.map +1 -1
  20. package/lib/commands.js +31 -12
  21. package/lib/commands.js.map +1 -1
  22. package/lib/common/constants.d.ts +7 -0
  23. package/lib/common/constants.js +8 -1
  24. package/lib/common/constants.js.map +1 -1
  25. package/lib/common/emulator.js +1 -1
  26. package/lib/common/emulator.js.map +1 -1
  27. package/lib/common/http.d.ts +3 -3
  28. package/lib/common/http.js.map +1 -1
  29. package/lib/common/index.d.ts +3 -0
  30. package/lib/common/index.js +3 -0
  31. package/lib/common/index.js.map +1 -1
  32. package/lib/common/interactive.d.ts +2 -2
  33. package/lib/common/pilet.d.ts +31 -0
  34. package/lib/common/pilet.js +79 -0
  35. package/lib/common/pilet.js.map +1 -0
  36. package/lib/common/piral.d.ts +35 -0
  37. package/lib/common/piral.js +125 -0
  38. package/lib/common/piral.js.map +1 -0
  39. package/lib/common/release.d.ts +4 -0
  40. package/lib/common/release.js +43 -0
  41. package/lib/common/release.js.map +1 -0
  42. package/lib/helpers.d.ts +2 -2
  43. package/lib/helpers.js.map +1 -1
  44. package/lib/messages.d.ts +19 -0
  45. package/lib/messages.js +23 -1
  46. package/lib/messages.js.map +1 -1
  47. package/lib/platforms/web.js +20 -7
  48. package/lib/platforms/web.js.map +1 -1
  49. package/lib/types/common.d.ts +8 -4
  50. package/lib/types/public.d.ts +2 -3
  51. package/package.json +2 -2
  52. package/src/api.ts +0 -17
  53. package/src/apps/build-pilet.ts +17 -59
  54. package/src/apps/build-piral.ts +37 -140
  55. package/src/apps/debug-pilet.ts +10 -3
  56. package/src/apps/debug-piral.ts +6 -2
  57. package/src/apps/publish-pilet.ts +35 -62
  58. package/src/apps/publish-piral.ts +150 -80
  59. package/src/build/bundler-calls.ts +4 -1
  60. package/src/commands.ts +34 -15
  61. package/src/common/constants.ts +7 -0
  62. package/src/common/emulator.ts +2 -2
  63. package/src/common/http.ts +3 -3
  64. package/src/common/index.ts +3 -0
  65. package/src/common/interactive.ts +2 -2
  66. package/src/common/pilet.ts +140 -0
  67. package/src/common/piral.ts +227 -0
  68. package/src/common/release.ts +62 -0
  69. package/src/helpers.ts +2 -2
  70. package/src/messages.ts +22 -0
  71. package/src/platforms/web.ts +25 -8
  72. package/src/types/common.ts +9 -4
  73. package/src/types/public.ts +2 -3
  74. package/lib/release.d.ts +0 -7
  75. package/lib/release.js +0 -67
  76. package/lib/release.js.map +0 -1
  77. package/src/release.ts +0 -91
@@ -0,0 +1,140 @@
1
+ import { basename, dirname, isAbsolute, relative, resolve } from 'path';
2
+ import { config } from './config';
3
+ import { removeDirectory } from './io';
4
+ import { ForceOverwrite } from './enums';
5
+ import { logInfo, progress } from './log';
6
+ import { callPiletBuild } from '../bundler';
7
+ import { defaultSchemaVersion } from './constants';
8
+ import { createPiletDeclaration } from './declaration';
9
+ import { combinePiletExternals, retrievePiletData, validateSharedDependencies } from './package';
10
+ import { LogLevels, PiletSchemaVersion } from '../types';
11
+
12
+ const defaultOutput = 'dist/index.js';
13
+
14
+ function isSubDir(parent: string, dir: string) {
15
+ const rel = relative(parent, dir);
16
+ return rel && !rel.startsWith('..') && !isAbsolute(rel);
17
+ }
18
+
19
+ function getTarget(root: string, main: string, source: string, target?: string) {
20
+ if (typeof target === 'undefined') {
21
+ const propDest = resolve(root, main);
22
+ const propDestDir = dirname(propDest);
23
+ const usePropDest = propDestDir !== root && propDestDir !== source && isSubDir(root, propDest);
24
+ return usePropDest ? propDest : resolve(root, defaultOutput);
25
+ }
26
+
27
+ return resolve(root, target);
28
+ }
29
+
30
+ export interface BuildPiletOptions {
31
+ entryModule: string;
32
+ app?: string;
33
+ originalSchemaVersion: PiletSchemaVersion;
34
+ target?: string;
35
+ fresh: boolean;
36
+ logLevel: LogLevels;
37
+ bundlerName: string;
38
+ optimizeModules: boolean;
39
+ sourceMaps: boolean;
40
+ watch: boolean;
41
+ contentHash: boolean;
42
+ minify: boolean;
43
+ declaration: boolean;
44
+ hooks?: {
45
+ beforeBuild?(e: any): Promise<void>;
46
+ afterBuild?(e: any): Promise<void>;
47
+ beforeDeclaration?(e: any): Promise<void>;
48
+ afterDeclaration?(e: any): Promise<void>;
49
+ };
50
+ _: Record<string, any>;
51
+ }
52
+
53
+ export async function triggerBuildPilet({
54
+ target,
55
+ app,
56
+ originalSchemaVersion,
57
+ fresh,
58
+ entryModule,
59
+ logLevel,
60
+ optimizeModules,
61
+ sourceMaps,
62
+ watch,
63
+ contentHash,
64
+ declaration,
65
+ minify,
66
+ hooks,
67
+ bundlerName,
68
+ _,
69
+ }: BuildPiletOptions) {
70
+ const targetDir = dirname(entryModule);
71
+ const { peerDependencies, peerModules, root, apps, piletPackage, ignored, importmap, schema } =
72
+ await retrievePiletData(targetDir, app);
73
+ const schemaVersion = originalSchemaVersion || schema || config.schemaVersion || defaultSchemaVersion;
74
+ const piralInstances = apps.map((m) => m.appPackage.name);
75
+ const externals = combinePiletExternals(piralInstances, peerDependencies, peerModules, importmap);
76
+ const { main = defaultOutput, name = 'pilet' } = piletPackage;
77
+ const dest = getTarget(root, main, targetDir, target);
78
+ const outDir = dirname(dest);
79
+ const outFile = basename(dest);
80
+
81
+ validateSharedDependencies(importmap);
82
+
83
+ if (fresh) {
84
+ progress('Removing output directory ...');
85
+ await removeDirectory(outDir);
86
+ }
87
+
88
+ logInfo('Bundle pilet ...');
89
+
90
+ await hooks.beforeBuild?.({ root, outDir, importmap, entryModule, schemaVersion, piletPackage });
91
+
92
+ await callPiletBuild(
93
+ {
94
+ root,
95
+ piralInstances,
96
+ optimizeModules,
97
+ sourceMaps,
98
+ watch,
99
+ contentHash,
100
+ minify,
101
+ externals,
102
+ targetDir,
103
+ importmap,
104
+ outFile,
105
+ outDir,
106
+ entryModule: `./${relative(root, entryModule)}`,
107
+ logLevel,
108
+ version: schemaVersion,
109
+ ignored,
110
+ _,
111
+ },
112
+ bundlerName,
113
+ );
114
+
115
+ await hooks.afterBuild?.({ root, outDir, importmap, entryModule, schemaVersion, piletPackage });
116
+
117
+ if (declaration) {
118
+ await hooks.beforeDeclaration?.({ root, outDir, entryModule, piletPackage });
119
+ await createPiletDeclaration(
120
+ name,
121
+ piralInstances,
122
+ root,
123
+ entryModule,
124
+ externals,
125
+ outDir,
126
+ ForceOverwrite.yes,
127
+ logLevel,
128
+ );
129
+ await hooks.afterDeclaration?.({ root, outDir, entryModule, piletPackage });
130
+ }
131
+
132
+ return {
133
+ piletPackage,
134
+ root,
135
+ outDir,
136
+ apps,
137
+ outFile,
138
+ dest,
139
+ };
140
+ }
@@ -0,0 +1,227 @@
1
+ import { join } from 'path';
2
+ import { runScript } from './scripts';
3
+ import { removeDirectory } from './io';
4
+ import { flattenExternals } from './package';
5
+ import { log, logDone, logInfo, progress } from './log';
6
+ import { createEmulatorSources, createEmulatorWebsite, packageEmulator } from './emulator';
7
+ import { emulatorName, emulatorPackageName, emulatorSourcesName, emulatorWebsiteName, releaseName } from './constants';
8
+ import { callPiralBuild } from '../bundler';
9
+ import { LogLevels, SharedDependency } from '../types';
10
+
11
+ async function runLifecycle(root: string, scripts: Record<string, string>, type: string) {
12
+ const script = scripts?.[type];
13
+
14
+ if (script) {
15
+ log('generalDebug_0003', `Running "${type}" ("${script}") ...`);
16
+ await runScript(script, root);
17
+ log('generalDebug_0003', `Finished running "${type}".`);
18
+ } else {
19
+ log('generalDebug_0003', `No script for "${type}" found ...`);
20
+ }
21
+ }
22
+
23
+ export interface BaseBuildPiralOptions {
24
+ root: string;
25
+ targetDir: string;
26
+ logLevel: LogLevels;
27
+ bundlerName: string;
28
+ externals: Array<SharedDependency>;
29
+ ignored: Array<string>;
30
+ outFile: string;
31
+ entryFiles: string;
32
+ optimizeModules: boolean;
33
+ sourceMaps: boolean;
34
+ watch: boolean;
35
+ contentHash: boolean;
36
+ piralInstances: Array<string>;
37
+ scripts?: Record<string, string>;
38
+ hooks?: {
39
+ beforeBuild?(e: any): Promise<void>;
40
+ afterBuild?(e: any): Promise<void>;
41
+ beforeEmulator?(e: any): Promise<void>;
42
+ afterEmulator?(e: any): Promise<void>;
43
+ beforePackage?(e: any): Promise<void>;
44
+ afterPackage?(e: any): Promise<void>;
45
+ };
46
+ _: Record<string, any>;
47
+ }
48
+
49
+ export interface BuildEmulatorOptions extends BaseBuildPiralOptions {
50
+ emulatorType: string;
51
+ }
52
+
53
+ export async function triggerBuildEmulator({
54
+ root,
55
+ logLevel,
56
+ externals,
57
+ emulatorType,
58
+ bundlerName,
59
+ optimizeModules,
60
+ sourceMaps,
61
+ watch,
62
+ ignored,
63
+ contentHash,
64
+ targetDir,
65
+ outFile,
66
+ scripts,
67
+ entryFiles,
68
+ piralInstances,
69
+ hooks,
70
+ _,
71
+ }: BuildEmulatorOptions) {
72
+ progress('Starting emulator build ...');
73
+
74
+ const emulatorPublicUrl = '/';
75
+ const appDir = emulatorType !== emulatorWebsiteName ? join(targetDir, 'app') : targetDir;
76
+
77
+ // since we create this anyway let's just pretend we want to have it clean!
78
+ await removeDirectory(targetDir);
79
+
80
+ await hooks.beforeBuild?.({ root, publicUrl: emulatorPublicUrl, externals, entryFiles, targetDir, piralInstances });
81
+
82
+ logInfo(`Bundle ${emulatorName} ...`);
83
+
84
+ const {
85
+ dir: outDir,
86
+ name,
87
+ hash,
88
+ } = await callPiralBuild(
89
+ {
90
+ root,
91
+ piralInstances,
92
+ emulator: true,
93
+ standalone: false,
94
+ optimizeModules,
95
+ sourceMaps,
96
+ watch,
97
+ contentHash,
98
+ minify: false,
99
+ externals: flattenExternals(externals),
100
+ publicUrl: emulatorPublicUrl,
101
+ entryFiles,
102
+ logLevel,
103
+ ignored,
104
+ outDir: appDir,
105
+ outFile,
106
+ _,
107
+ },
108
+ bundlerName,
109
+ );
110
+
111
+ await hooks.afterBuild?.({
112
+ root,
113
+ publicUrl: emulatorPublicUrl,
114
+ externals,
115
+ entryFiles,
116
+ targetDir,
117
+ piralInstances,
118
+ hash,
119
+ outDir,
120
+ outFile: name,
121
+ });
122
+
123
+ await runLifecycle(root, scripts, 'piral:postbuild');
124
+ await runLifecycle(root, scripts, `piral:postbuild-${emulatorName}`);
125
+
126
+ await hooks.beforeEmulator?.({ root, externals, targetDir, outDir });
127
+
128
+ let rootDir = root;
129
+
130
+ switch (emulatorType) {
131
+ case emulatorPackageName:
132
+ rootDir = await createEmulatorSources(root, externals, outDir, outFile, logLevel);
133
+ await hooks.beforePackage?.({ root, externals, targetDir, outDir, rootDir });
134
+ await packageEmulator(rootDir);
135
+ await hooks.afterPackage?.({ root, externals, targetDir, outDir, rootDir });
136
+ break;
137
+ case emulatorSourcesName:
138
+ rootDir = await createEmulatorSources(root, externals, outDir, outFile, logLevel);
139
+ logDone(`Emulator package sources available in "${rootDir}".`);
140
+ break;
141
+ case emulatorWebsiteName:
142
+ rootDir = await createEmulatorWebsite(root, externals, outDir, outFile, logLevel);
143
+ logDone(`Emulator website available in "${rootDir}".`);
144
+ break;
145
+ }
146
+
147
+ await hooks.afterEmulator?.({ root, externals, targetDir, outDir, rootDir });
148
+ }
149
+
150
+ export interface BuildShellOptions extends BaseBuildPiralOptions {
151
+ minify: boolean;
152
+ publicUrl: string;
153
+ }
154
+
155
+ export async function triggerBuildShell({
156
+ root,
157
+ targetDir,
158
+ bundlerName,
159
+ minify,
160
+ optimizeModules,
161
+ entryFiles,
162
+ piralInstances,
163
+ sourceMaps,
164
+ logLevel,
165
+ ignored,
166
+ watch,
167
+ outFile,
168
+ publicUrl,
169
+ contentHash,
170
+ externals,
171
+ hooks,
172
+ scripts,
173
+ _,
174
+ }: BuildShellOptions) {
175
+ progress('Starting release build ...');
176
+
177
+ // since we create this anyway let's just pretend we want to have it clean!
178
+ await removeDirectory(targetDir);
179
+
180
+ logInfo(`Bundle ${releaseName} ...`);
181
+
182
+ await hooks.beforeBuild?.({ root, publicUrl, externals, entryFiles, targetDir, piralInstances });
183
+
184
+ const {
185
+ dir: outDir,
186
+ name,
187
+ hash,
188
+ } = await callPiralBuild(
189
+ {
190
+ root,
191
+ piralInstances,
192
+ emulator: false,
193
+ standalone: false,
194
+ optimizeModules,
195
+ sourceMaps,
196
+ watch,
197
+ contentHash,
198
+ minify,
199
+ externals: flattenExternals(externals),
200
+ publicUrl,
201
+ outFile,
202
+ outDir: targetDir,
203
+ entryFiles,
204
+ logLevel,
205
+ ignored,
206
+ _,
207
+ },
208
+ bundlerName,
209
+ );
210
+
211
+ await hooks.afterBuild?.({
212
+ root,
213
+ publicUrl,
214
+ externals,
215
+ entryFiles,
216
+ targetDir,
217
+ piralInstances,
218
+ outDir,
219
+ outFile: name,
220
+ hash,
221
+ });
222
+
223
+ await runLifecycle(root, scripts, 'piral:postbuild');
224
+ await runLifecycle(root, scripts, `piral:postbuild-${releaseName}`);
225
+
226
+ logDone(`Files for publication available in "${outDir}".`);
227
+ }
@@ -0,0 +1,62 @@
1
+ import { basename, dirname, relative, resolve } from 'path';
2
+ import { fail, log } from './log';
3
+ import { publishNpmPackage } from './npm';
4
+ import { FormDataObj, postForm } from './http';
5
+ import { checkExists, matchFiles, readBinary } from './io';
6
+ import { PublishScheme } from '../types';
7
+
8
+ export async function publishPackageEmulator(
9
+ baseDir: string,
10
+ source: string,
11
+ args: Record<string, string> = {},
12
+ interactive = false,
13
+ ) {
14
+ const type = 'emulator';
15
+ const directory = resolve(baseDir, source, type);
16
+ const exists = await checkExists(directory);
17
+
18
+ if (!exists) {
19
+ fail('publishDirectoryMissing_0110', directory);
20
+ }
21
+
22
+ const files = await matchFiles(directory, '*.tgz');
23
+ log('generalDebug_0003', `Found ${files.length} in "${directory}": ${files.join(', ')}`);
24
+
25
+ if (files.length !== 1) {
26
+ fail('publishEmulatorFilesUnexpected_0111', directory);
27
+ }
28
+
29
+ const [file] = files;
30
+ const flags = Object.keys(args).reduce((p, c) => {
31
+ p.push(`--${c}`, args[c]);
32
+ return p;
33
+ }, [] as Array<string>);
34
+
35
+ await publishNpmPackage(directory, file, flags, interactive);
36
+ }
37
+
38
+ export async function publishWebsiteEmulator(
39
+ version: string,
40
+ url: string,
41
+ apiKey: string,
42
+ mode: PublishScheme,
43
+ directory: string,
44
+ files: Array<string>,
45
+ interactive: boolean,
46
+ headers?: Record<string, string>,
47
+ ca?: Buffer,
48
+ ) {
49
+ const data: FormDataObj = {
50
+ version,
51
+ type: 'custom',
52
+ };
53
+
54
+ for (const file of files) {
55
+ const relPath = relative(directory, file);
56
+ const fileName = basename(file);
57
+ const content = await readBinary(dirname(file), fileName);
58
+ data[relPath] = [content, fileName];
59
+ }
60
+
61
+ return await postForm(url, mode, apiKey, data, headers, ca, interactive);
62
+ }
package/src/helpers.ts CHANGED
@@ -7,12 +7,12 @@ import type {
7
7
  PiletPublishSource,
8
8
  PiralBuildType,
9
9
  PiletBuildType,
10
- PiletPublishScheme,
10
+ PublishScheme,
11
11
  SourceLanguage,
12
12
  } from './types';
13
13
 
14
14
  export const schemaKeys: Array<PiletSchemaVersion> = ['v0', 'v1', 'v2', 'v3', 'mf', 'none'];
15
- export const publishModeKeys: Array<PiletPublishScheme> = ['none', 'basic', 'bearer', 'digest'];
15
+ export const publishModeKeys: Array<PublishScheme> = ['none', 'basic', 'bearer', 'digest'];
16
16
  export const fromKeys: Array<PiletPublishSource> = ['local', 'remote', 'npm'];
17
17
  export const piralBuildTypeKeys: Array<PiralBuildType> = [
18
18
  'all',
package/src/messages.ts CHANGED
@@ -2585,6 +2585,28 @@ export function requiredEmulatorAssetDownloadSkipped_0123(url: string): QuickMes
2585
2585
  return [LogLevels.warning, '0123', `Could not download asset file at "${url}".`];
2586
2586
  }
2587
2587
 
2588
+ /**
2589
+ * @kind Error
2590
+ *
2591
+ * @summary
2592
+ * The emulator.json and associated files could not be found in the source directory.
2593
+ *
2594
+ * @abstract
2595
+ * Only an emulator website can be published using `piral publish`. Other artifacts such as
2596
+ * standard release artifacts or the package emulator (tgz) need to be published using other
2597
+ * mechanisms such as `npm publish`.
2598
+ *
2599
+ * If no emulator website exists you can either build one using the `--fresh` flag with
2600
+ * `piral publish` (i.e., `piral publish --fresh`) or preparing the build using `piral build`
2601
+ * with the `--type emulator-website` flag.
2602
+ *
2603
+ * @see
2604
+ * - [Emulator](https://docs.piral.io/concepts/T01-emulator)
2605
+ */
2606
+ export function missingEmulatorWebsite_0130(path: string): QuickMessage {
2607
+ return [LogLevels.error, '0130', `Could not find the files for an emulator website at "${path}".`];
2608
+ }
2609
+
2588
2610
  /**
2589
2611
  * @kind Warning
2590
2612
  *
@@ -6,7 +6,16 @@ import { config } from '../common/config';
6
6
  import { openBrowser } from '../common/browser';
7
7
  import { checkExistingDirectory, findFile } from '../common/io';
8
8
  import { getAvailablePort } from '../common/port';
9
- import { PlatformStartShellOptions, PlatformStartModuleOptions } from '../types';
9
+ import { PlatformStartShellOptions, PlatformStartModuleOptions, NetworkSpec } from '../types';
10
+
11
+ async function getPort(network: NetworkSpec) {
12
+ if (network.type === 'proposed') {
13
+ network.port = await getAvailablePort(network.port);
14
+ network.type = 'fixed';
15
+ }
16
+
17
+ return network.port;
18
+ }
10
19
 
11
20
  async function startModule(options: PlatformStartModuleOptions) {
12
21
  const {
@@ -16,7 +25,7 @@ async function startModule(options: PlatformStartModuleOptions) {
16
25
  feed,
17
26
  publicUrl,
18
27
  customkrasrc,
19
- originalPort,
28
+ network,
20
29
  hooks,
21
30
  registerWatcher,
22
31
  registerEnd,
@@ -60,7 +69,8 @@ async function startModule(options: PlatformStartModuleOptions) {
60
69
 
61
70
  configs.forEach(registerWatcher);
62
71
 
63
- const port = await getAvailablePort(originalPort);
72
+ const shouldNotify = network.type === 'proposed';
73
+ const port = await getPort(network);
64
74
  const krasConfig = readKrasConfig({ port, initial, required }, ...configs);
65
75
 
66
76
  log('generalVerbose_0004', `Using kras with configuration: ${JSON.stringify(krasConfig, undefined, 2)}`);
@@ -68,7 +78,10 @@ async function startModule(options: PlatformStartModuleOptions) {
68
78
  const krasServer = buildKrasWithCli(krasConfig);
69
79
  krasServer.setMaxListeners(maxListeners);
70
80
  krasServer.removeAllListeners('open');
71
- krasServer.on('open', notifyServerOnline(publicUrl, krasConfig.api));
81
+
82
+ if (shouldNotify) {
83
+ krasServer.on('open', notifyServerOnline(publicUrl, krasConfig.api));
84
+ }
72
85
 
73
86
  await hooks.beforeOnline?.({ krasServer, krasConfig, open, port, api, feed, pilets, publicUrl });
74
87
  await krasServer.start();
@@ -88,7 +101,7 @@ async function startShell(options: PlatformStartShellOptions) {
88
101
  publicUrl,
89
102
  bundler,
90
103
  customkrasrc,
91
- originalPort,
104
+ network,
92
105
  hooks,
93
106
  registerWatcher,
94
107
  registerEnd,
@@ -123,21 +136,25 @@ async function startShell(options: PlatformStartShellOptions) {
123
136
 
124
137
  configs.forEach(registerWatcher);
125
138
 
126
- const port = await getAvailablePort(originalPort);
139
+ const shouldNotify = network.type === 'proposed';
140
+ const port = await getPort(network);
127
141
  const krasConfig = readKrasConfig({ port, initial, required }, ...configs);
128
142
  log('generalVerbose_0004', `Using kras with configuration: ${JSON.stringify(krasConfig, undefined, 2)}`);
129
143
 
130
144
  const krasServer = buildKrasWithCli(krasConfig);
131
145
  krasServer.setMaxListeners(16);
132
146
  krasServer.removeAllListeners('open');
133
- krasServer.on('open', notifyServerOnline(publicUrl, krasConfig.api));
147
+
148
+ if (shouldNotify) {
149
+ krasServer.on('open', notifyServerOnline(publicUrl, krasConfig.api));
150
+ }
134
151
 
135
152
  await hooks.beforeOnline?.({ krasServer, krasConfig, open, port, publicUrl });
136
153
  await krasServer.start();
137
154
  openBrowser(open, port, publicUrl, !!krasConfig.ssl);
138
155
  await hooks.afterOnline?.({ krasServer, krasConfig, open, port, publicUrl });
139
156
 
140
- registerEnd(() => krasServer.stop());
157
+ registerEnd(async () => krasServer.stop());
141
158
  }
142
159
 
143
160
  export function setup() {
@@ -112,12 +112,17 @@ export interface BundleDetails {
112
112
  export interface Bundler {
113
113
  readonly bundle: BundleDetails;
114
114
  start(): void;
115
- stop(): void;
115
+ stop(): Promise<void>;
116
116
  on(cb: (args: any) => void): void;
117
117
  off(cb: (args: any) => void): void;
118
118
  ready(): Promise<void>;
119
119
  }
120
120
 
121
+ export interface NetworkSpec {
122
+ port: number;
123
+ type: 'proposed' | 'fixed';
124
+ }
125
+
121
126
  export interface PlatformStartModuleOptions {
122
127
  appDir?: string;
123
128
  open: boolean;
@@ -125,7 +130,7 @@ export interface PlatformStartModuleOptions {
125
130
  feed: string | Array<string>;
126
131
  publicUrl: string;
127
132
  customkrasrc: string;
128
- originalPort: number;
133
+ network: NetworkSpec;
129
134
  hooks: Record<string, Function>;
130
135
  registerWatcher(file: string): void;
131
136
  registerEnd(cb: () => void): void;
@@ -143,10 +148,10 @@ export interface PlatformStartShellOptions {
143
148
  publicUrl: string;
144
149
  bundler: Bundler;
145
150
  customkrasrc: string;
146
- originalPort: number;
151
+ network: NetworkSpec;
147
152
  hooks: Record<string, Function>;
148
153
  registerWatcher(file: string): void;
149
- registerEnd(cb: () => void): void;
154
+ registerEnd(cb: () => void | Promise<void>): void;
150
155
  }
151
156
 
152
157
  export interface ReleaseProvider {
@@ -1,5 +1,5 @@
1
1
  import { Argv, Arguments } from 'yargs';
2
- import { RuleRunner, PiletRuleContext, PiralRuleContext, LogLevels, SharedDependency, ReleaseProvider } from './common';
2
+ import { RuleRunner, PiletRuleContext, PiralRuleContext, LogLevels, SharedDependency } from './common';
3
3
 
4
4
  export interface ToolCommandRunner<U = {}> {
5
5
  (args: Arguments<U>): void | Promise<void>;
@@ -44,7 +44,6 @@ export interface CliPluginApi {
44
44
  withPiletRule(ruleName: string, runner: RuleRunner<PiletRuleContext>): CliPluginApi;
45
45
  withPatcher(packageName: string, patch: PackagePatcher): CliPluginApi;
46
46
  withBundler(bundlerName: string, bundler: BundlerDefinition): CliPluginApi;
47
- withReleaseProvider(providerName: string, provider: ReleaseProvider): CliPluginApi;
48
47
  }
49
48
 
50
49
  export interface CliPlugin {
@@ -242,7 +241,7 @@ export type AuthConfig = HeaderAuthConfig | HttpAuthConfig;
242
241
 
243
242
  export type SourceLanguage = 'js' | 'ts';
244
243
 
245
- export type PiletPublishScheme = 'none' | 'digest' | 'bearer' | 'basic';
244
+ export type PublishScheme = 'none' | 'digest' | 'bearer' | 'basic';
246
245
 
247
246
  export type PiletPublishSource = 'local' | 'npm' | 'remote';
248
247
 
package/lib/release.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import { ReleaseProvider } from './types';
2
- export interface QualifiedReleaseProvider {
3
- name: string;
4
- action: ReleaseProvider;
5
- }
6
- export declare function setReleaseProvider(provider: QualifiedReleaseProvider): void;
7
- export declare function publishArtifacts(providerName: string, directory: string, files: Array<string>, args: Record<string, string>, interactive: boolean): Promise<void>;
package/lib/release.js DELETED
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.publishArtifacts = exports.setReleaseProvider = void 0;
4
- const path_1 = require("path");
5
- const common_1 = require("./common");
6
- const helpers_1 = require("./helpers");
7
- async function getVersion(directory) {
8
- const data = await (0, common_1.findFile)(directory, 'package.json');
9
- if (!data) {
10
- (0, common_1.fail)('packageJsonNotFound_0020');
11
- }
12
- const { version } = require(data);
13
- return version;
14
- }
15
- const providers = {
16
- none() {
17
- return Promise.resolve();
18
- },
19
- async xcopy(_, files, args) {
20
- const { target } = args;
21
- if (!target) {
22
- (0, common_1.fail)('publishXcopyMissingTarget_0112');
23
- }
24
- await Promise.all(files.map(async (file) => (0, common_1.copy)(file, (0, path_1.resolve)(target, (0, path_1.basename)(file)))));
25
- },
26
- async feed(directory, files, args, interactive) {
27
- const { url, apiKey, scheme = 'basic', version = await getVersion(directory) } = args;
28
- if (!url) {
29
- (0, common_1.fail)('publishFeedMissingUrl_0115');
30
- }
31
- if (!version) {
32
- (0, common_1.fail)('publishFeedMissingVersion_0116');
33
- }
34
- const data = {
35
- version,
36
- type: 'custom',
37
- };
38
- for (const file of files) {
39
- const relPath = (0, path_1.relative)(directory, file);
40
- const fileName = (0, path_1.basename)(file);
41
- const content = await (0, common_1.readBinary)((0, path_1.dirname)(file), fileName);
42
- data[relPath] = [content, fileName];
43
- }
44
- await (0, common_1.postForm)(url, scheme, apiKey, data, {}, undefined, interactive);
45
- },
46
- };
47
- function findReleaseProvider(providerName) {
48
- const provider = providers[providerName];
49
- if (typeof provider !== 'function') {
50
- (0, common_1.fail)('publishProviderMissing_0113', providerName, helpers_1.availableReleaseProviders);
51
- }
52
- return provider;
53
- }
54
- helpers_1.availableReleaseProviders.push(...Object.keys(providers));
55
- function setReleaseProvider(provider) {
56
- providers[provider.name] = provider.action;
57
- if (!helpers_1.availableReleaseProviders.includes(provider.name)) {
58
- helpers_1.availableReleaseProviders.push(provider.name);
59
- }
60
- }
61
- exports.setReleaseProvider = setReleaseProvider;
62
- function publishArtifacts(providerName, directory, files, args, interactive) {
63
- const runRelease = findReleaseProvider(providerName);
64
- return runRelease(directory, files, args, interactive);
65
- }
66
- exports.publishArtifacts = publishArtifacts;
67
- //# sourceMappingURL=release.js.map