piral-cli 1.5.0-beta.6684 → 1.5.0-beta.6690

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 (66) 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 +3 -2
  9. package/lib/apps/debug-pilet.js.map +1 -1
  10. package/lib/apps/publish-pilet.d.ts +11 -2
  11. package/lib/apps/publish-pilet.js +16 -43
  12. package/lib/apps/publish-pilet.js.map +1 -1
  13. package/lib/apps/publish-piral.d.ts +37 -7
  14. package/lib/apps/publish-piral.js +62 -47
  15. package/lib/apps/publish-piral.js.map +1 -1
  16. package/lib/commands.js +31 -12
  17. package/lib/commands.js.map +1 -1
  18. package/lib/common/constants.d.ts +7 -0
  19. package/lib/common/constants.js +8 -1
  20. package/lib/common/constants.js.map +1 -1
  21. package/lib/common/emulator.js +1 -1
  22. package/lib/common/emulator.js.map +1 -1
  23. package/lib/common/http.d.ts +3 -3
  24. package/lib/common/http.js.map +1 -1
  25. package/lib/common/index.d.ts +3 -0
  26. package/lib/common/index.js +3 -0
  27. package/lib/common/index.js.map +1 -1
  28. package/lib/common/interactive.d.ts +2 -2
  29. package/lib/common/pilet.d.ts +31 -0
  30. package/lib/common/pilet.js +79 -0
  31. package/lib/common/pilet.js.map +1 -0
  32. package/lib/common/piral.d.ts +35 -0
  33. package/lib/common/piral.js +125 -0
  34. package/lib/common/piral.js.map +1 -0
  35. package/lib/common/release.d.ts +4 -0
  36. package/lib/common/release.js +43 -0
  37. package/lib/common/release.js.map +1 -0
  38. package/lib/helpers.d.ts +2 -2
  39. package/lib/helpers.js.map +1 -1
  40. package/lib/messages.d.ts +19 -0
  41. package/lib/messages.js +23 -1
  42. package/lib/messages.js.map +1 -1
  43. package/lib/types/public.d.ts +2 -3
  44. package/package.json +2 -2
  45. package/src/api.ts +0 -17
  46. package/src/apps/build-pilet.ts +17 -59
  47. package/src/apps/build-piral.ts +37 -140
  48. package/src/apps/debug-pilet.ts +5 -4
  49. package/src/apps/publish-pilet.ts +35 -62
  50. package/src/apps/publish-piral.ts +150 -80
  51. package/src/commands.ts +34 -15
  52. package/src/common/constants.ts +7 -0
  53. package/src/common/emulator.ts +2 -2
  54. package/src/common/http.ts +3 -3
  55. package/src/common/index.ts +3 -0
  56. package/src/common/interactive.ts +2 -2
  57. package/src/common/pilet.ts +140 -0
  58. package/src/common/piral.ts +227 -0
  59. package/src/common/release.ts +62 -0
  60. package/src/helpers.ts +2 -2
  61. package/src/messages.ts +22 -0
  62. package/src/types/public.ts +2 -3
  63. package/lib/release.d.ts +0 -7
  64. package/lib/release.js +0 -67
  65. package/lib/release.js.map +0 -1
  66. package/src/release.ts +0 -91
@@ -1,16 +1,26 @@
1
- import { resolve } from 'path';
2
- import { publishArtifacts } from '../release';
3
- import { LogLevels, PiralBuildType } from '../types';
1
+ import { basename, dirname, resolve } from 'path';
2
+ import { LogLevels, PublishScheme } from '../types';
4
3
  import {
5
4
  setLogLevel,
6
5
  progress,
7
6
  checkExists,
8
7
  fail,
9
8
  logDone,
10
- logReset,
11
- publishNpmPackage,
12
- matchFiles,
13
9
  log,
10
+ config,
11
+ readBinary,
12
+ emulatorName,
13
+ emulatorJson,
14
+ publishWebsiteEmulator,
15
+ matchFiles,
16
+ readJson,
17
+ triggerBuildEmulator,
18
+ logReset,
19
+ emulatorWebsiteName,
20
+ retrievePiralRoot,
21
+ emulatorPackageName,
22
+ retrievePiletsInfo,
23
+ validateSharedDependencies,
14
24
  } from '../common';
15
25
 
16
26
  export interface PublishPiralOptions {
@@ -19,15 +29,36 @@ export interface PublishPiralOptions {
19
29
  */
20
30
  source?: string;
21
31
 
32
+ /**
33
+ * Sets the URL of the feed service to deploy to.
34
+ */
35
+ url?: string;
36
+
37
+ /**
38
+ * Sets the API key to use.
39
+ */
40
+ apiKey?: string;
41
+
22
42
  /**
23
43
  * Sets the log level to use (1-5).
24
44
  */
25
45
  logLevel?: LogLevels;
26
46
 
27
47
  /**
28
- * The options to supply for the provider.
48
+ * Specifies if the Piral instance should be built before publishing.
49
+ * If yes, then the tarball is created from fresh build artifacts.
50
+ */
51
+ fresh?: boolean;
52
+
53
+ /**
54
+ * Defines a custom certificate for the feed service.
29
55
  */
30
- opts?: Record<string, string>;
56
+ cert?: string;
57
+
58
+ /**
59
+ * Places additional headers that should be posted to the feed service.
60
+ */
61
+ headers?: Record<string, string>;
31
62
 
32
63
  /**
33
64
  * Defines if authorization tokens can be retrieved interactively.
@@ -35,104 +66,143 @@ export interface PublishPiralOptions {
35
66
  interactive?: boolean;
36
67
 
37
68
  /**
38
- * The provider to use for publishing the release artifacts.
69
+ * Sets the bundler to use for building, if any specific.
39
70
  */
40
- provider?: string;
71
+ bundlerName?: string;
41
72
 
42
73
  /**
43
- * The type of publish.
74
+ * Sets the authorization scheme to use.
44
75
  */
45
- type?: PiralBuildType;
76
+ mode?: PublishScheme;
77
+
78
+ /**
79
+ * Additional arguments for a specific bundler.
80
+ */
81
+ _?: Record<string, any>;
82
+
83
+ /**
84
+ * Hooks to be triggered at various stages.
85
+ */
86
+ hooks?: {
87
+ beforeEmulator?(e: any): Promise<void>;
88
+ afterEmulator?(e: any): Promise<void>;
89
+ beforePackage?(e: any): Promise<void>;
90
+ afterPackage?(e: any): Promise<void>;
91
+ };
46
92
  }
47
93
 
48
94
  export const publishPiralDefaults: PublishPiralOptions = {
49
95
  source: './dist',
50
96
  logLevel: LogLevels.info,
51
- type: 'all',
52
- provider: 'none',
53
- opts: {},
97
+ url: undefined,
54
98
  interactive: false,
99
+ apiKey: undefined,
100
+ fresh: false,
101
+ cert: undefined,
102
+ mode: 'basic',
103
+ headers: {},
55
104
  };
56
105
 
57
- async function publishEmulator(
58
- baseDir: string,
59
- source: string,
60
- args: Record<string, string> = {},
61
- interactive = false,
62
- ) {
63
- const type = 'emulator';
64
- const directory = resolve(baseDir, source, type);
65
- const exists = await checkExists(directory);
66
-
67
- if (!exists) {
68
- fail('publishDirectoryMissing_0110', directory);
69
- }
70
-
71
- const files = await matchFiles(directory, '*.tgz');
72
- log('generalDebug_0003', `Found ${files.length} in "${directory}": ${files.join(', ')}`);
73
-
74
- if (files.length !== 1) {
75
- fail('publishEmulatorFilesUnexpected_0111', directory);
76
- }
77
-
78
- const [file] = files;
79
- const flags = Object.keys(args).reduce((p, c) => {
80
- p.push(`--${c}`, args[c]);
81
- return p;
82
- }, [] as Array<string>);
83
-
84
- await publishNpmPackage(directory, file, flags, interactive);
85
- }
86
-
87
- async function publishRelease(
88
- baseDir: string,
89
- source: string,
90
- providerName: string,
91
- args: Record<string, string> = {},
92
- interactive = false,
93
- ) {
94
- const type = 'release';
95
- const directory = resolve(baseDir, source, type);
96
- const exists = await checkExists(directory);
97
-
98
- if (!exists) {
99
- fail('publishDirectoryMissing_0110', directory);
100
- }
101
-
102
- const files = await matchFiles(directory, '**/*');
103
- log('generalDebug_0003', `Found ${files.length} in "${directory}": ${files.join(', ')}`);
104
- await publishArtifacts(providerName, directory, files, args, interactive);
105
- }
106
-
107
106
  export async function publishPiral(baseDir = process.cwd(), options: PublishPiralOptions = {}) {
108
107
  const {
109
108
  source = publishPiralDefaults.source,
110
- type = publishPiralDefaults.type,
111
109
  logLevel = publishPiralDefaults.logLevel,
112
- opts = publishPiralDefaults.opts,
113
- provider = publishPiralDefaults.provider,
114
110
  interactive = publishPiralDefaults.interactive,
111
+ fresh = publishPiralDefaults.fresh,
112
+ url = config.url ?? publishPiralDefaults.url,
113
+ apiKey = config.apiKeys?.[url] ?? config.apiKey ?? publishPiralDefaults.apiKey,
114
+ cert = config.cert ?? publishPiralDefaults.cert,
115
+ headers = publishPiralDefaults.headers,
116
+ mode = publishPiralDefaults.mode,
117
+ _ = {},
118
+ hooks = {},
119
+ bundlerName,
115
120
  } = options;
116
121
  const fullBase = resolve(process.cwd(), baseDir);
117
122
  setLogLevel(logLevel);
123
+ progress('Reading configuration ...');
118
124
 
119
- if (type === 'emulator-sources') {
120
- fail('publishEmulatorSourcesInvalid_0114');
125
+ if (!url) {
126
+ fail('missingPiletFeedUrl_0060');
121
127
  }
122
128
 
123
- progress('Reading configuration ...');
129
+ log('generalDebug_0003', 'Checking if certificate exists.');
130
+ let ca: Buffer = undefined;
124
131
 
125
- if (type !== 'release') {
126
- progress('Publishing emulator package ...');
127
- await publishEmulator(fullBase, source, opts, interactive);
128
- logDone(`Successfully published emulator.`);
129
- logReset();
132
+ if (await checkExists(cert)) {
133
+ const dir = dirname(cert);
134
+ const file = basename(cert);
135
+ log('generalDebug_0003', `Reading certificate file "${file}" from "${dir}".`);
136
+ ca = await readBinary(dir, file);
137
+ }
138
+
139
+ log('generalDebug_0003', 'Getting the files ...');
140
+ const entryFiles = await retrievePiralRoot(fullBase, './');
141
+ const {
142
+ name,
143
+ root,
144
+ ignored,
145
+ externals,
146
+ scripts,
147
+ emulator = emulatorPackageName,
148
+ } = await retrievePiletsInfo(entryFiles);
149
+
150
+ if (emulator !== emulatorWebsiteName) {
151
+ fail('generalError_0002', `Currently only the "${emulatorWebsiteName}" option is supported.`);
130
152
  }
153
+
154
+ const emulatorDir = resolve(fullBase, source, emulatorName);
155
+
156
+ if (fresh) {
157
+ const piralInstances = [name];
158
+
159
+ validateSharedDependencies(externals);
160
+
161
+ await triggerBuildEmulator({
162
+ root,
163
+ logLevel,
164
+ bundlerName,
165
+ emulatorType: emulatorWebsiteName,
166
+ hooks,
167
+ targetDir: emulatorDir,
168
+ ignored,
169
+ externals,
170
+ entryFiles,
171
+ piralInstances,
172
+ optimizeModules: true,
173
+ sourceMaps: true,
174
+ watch: false,
175
+ scripts,
176
+ contentHash: true,
177
+ outFile: 'index.html',
178
+ _,
179
+ });
131
180
 
132
- if (type !== 'emulator') {
133
- progress('Publishing release files ...');
134
- await publishRelease(fullBase, source, provider, opts, interactive);
135
- logDone(`Successfully published release.`);
136
181
  logReset();
137
182
  }
183
+
184
+ const { version } = await readJson(emulatorDir, emulatorJson);
185
+
186
+ if (!version) {
187
+ fail('missingEmulatorWebsite_0130', emulatorDir);
188
+ }
189
+
190
+ log('generalInfo_0000', `Using feed service "${url}".`);
191
+
192
+ const files = await matchFiles(emulatorDir, '**/*');
193
+
194
+ progress(`Publishing emulator to "%s" ...`, url);
195
+ const result = await publishWebsiteEmulator(version, url, apiKey, mode, emulatorDir, files, interactive, headers, ca);
196
+
197
+ if (!result.success) {
198
+ fail('failedUploading_0064');
199
+ }
200
+
201
+ if (result.response) {
202
+ log('httpPostResponse_0067', result);
203
+ }
204
+
205
+ progress(`Published successfully!`);
206
+
207
+ logDone(`Emulator published successfully!`);
138
208
  }
package/src/commands.ts CHANGED
@@ -24,7 +24,7 @@ import {
24
24
  PiletPublishSource,
25
25
  PiletSchemaVersion,
26
26
  PiletBuildType,
27
- PiletPublishScheme,
27
+ PublishScheme,
28
28
  SourceLanguage,
29
29
  } from './types';
30
30
 
@@ -196,25 +196,39 @@ const allCommands: Array<ToolCommand<any>> = [
196
196
  alias: ['release-piral', 'release'],
197
197
  description: 'Publishes Piral instance build artifacts.',
198
198
  arguments: ['[source]'],
199
- flags(argv) {
199
+ // "any" due to https://github.com/microsoft/TypeScript/issues/28663 [artifical N = 50]
200
+ flags(argv: any) {
200
201
  return argv
201
202
  .positional('source', {
202
203
  type: 'string',
203
204
  describe: 'Sets the previously used output directory to publish.',
204
205
  default: apps.publishPiralDefaults.source,
205
206
  })
207
+ .string('url')
208
+ .describe('url', 'Sets the explicit URL where to publish the emulator to.')
209
+ .default('url', apps.publishPiralDefaults.url)
210
+ .string('api-key')
211
+ .describe('api-key', 'Sets the potential API key to send to the service.')
212
+ .default('api-key', apps.publishPiralDefaults.apiKey)
213
+ .string('ca-cert')
214
+ .describe('ca-cert', 'Sets a custom certificate authority to use, if any.')
215
+ .default('ca-cert', apps.publishPiralDefaults.cert)
206
216
  .number('log-level')
207
217
  .describe('log-level', 'Sets the log level to use (1-5).')
208
218
  .default('log-level', apps.publishPiralDefaults.logLevel)
209
- .choices('type', piralBuildTypeKeys)
210
- .describe('type', 'Selects the target type to publish. "all" publishes all target types.')
211
- .default('type', apps.publishPiralDefaults.type)
212
- .choices('provider', availableReleaseProviders)
213
- .describe('provider', 'Sets the provider for publishing the release assets.')
214
- .default('provider', apps.publishPiralDefaults.provider)
215
- .option('opts', undefined)
216
- .describe('opts', 'Sets the options to forward to the chosen provider.')
217
- .default('opts', apps.publishPiralDefaults.opts)
219
+ .boolean('fresh')
220
+ .describe('fresh', 'Performs a fresh build of the emulator website.')
221
+ .default('fresh', apps.publishPiralDefaults.fresh)
222
+ .choices('mode', publishModeKeys)
223
+ .describe('mode', 'Sets the authorization mode to use.')
224
+ .default('mode', apps.publishPiralDefaults.mode)
225
+ .alias('mode', 'auth-mode')
226
+ .choices('bundler', availableBundlers)
227
+ .describe('bundler', 'Sets the bundler to use.')
228
+ .default('bundler', availableBundlers[0])
229
+ .option('headers', undefined)
230
+ .describe('headers', 'Sets additional headers to be included in the feed service request.')
231
+ .default('headers', apps.publishPiralDefaults.headers)
218
232
  .boolean('interactive')
219
233
  .describe('interactive', 'Defines if authorization tokens can be retrieved interactively.')
220
234
  .default('interactive', apps.publishPiralDefaults.interactive)
@@ -226,10 +240,15 @@ const allCommands: Array<ToolCommand<any>> = [
226
240
  return apps.publishPiral(args.base as string, {
227
241
  source: args.source as string,
228
242
  logLevel: args['log-level'] as LogLevels,
229
- type: args.type as PiralBuildType,
230
- provider: args.provider as string,
231
- opts: args.opts as Record<string, string>,
243
+ apiKey: args['api-key'] as string,
244
+ cert: args['ca-cert'] as string,
245
+ url: args.url as string,
232
246
  interactive: args.interactive as boolean,
247
+ mode: args.mode as PublishScheme,
248
+ bundlerName: args.bundler as string,
249
+ fresh: args.fresh as boolean,
250
+ headers: args.headers as Record<string, string>,
251
+ _: args,
233
252
  });
234
253
  },
235
254
  },
@@ -671,7 +690,7 @@ const allCommands: Array<ToolCommand<any>> = [
671
690
  schemaVersion: args.schema as PiletSchemaVersion,
672
691
  fields: args.fields as Record<string, string>,
673
692
  headers: args.headers as Record<string, string>,
674
- mode: args.mode as PiletPublishScheme,
693
+ mode: args.mode as PublishScheme,
675
694
  interactive: args.interactive as boolean,
676
695
  _: args,
677
696
  });
@@ -6,6 +6,13 @@ export const piletJson = 'pilet.json';
6
6
  export const filesOnceTar = 'files_once';
7
7
  export const piralBaseRoot = 'piral-base/package.json';
8
8
  export const defaultSchemaVersion = 'v2';
9
+ export const allName = 'all';
10
+ export const releaseName = 'release';
11
+ export const emulatorJson = 'emulator.json';
12
+ export const emulatorName = 'emulator';
13
+ export const emulatorPackageName = 'package';
14
+ export const emulatorSourcesName = 'sources';
15
+ export const emulatorWebsiteName = 'website';
9
16
  export const frameworkLibs = ['piral' as const, 'piral-core' as const, 'piral-base' as const];
10
17
  export const piletJsonSchemaUrl = 'https://docs.piral.io/schemas/pilet-v0.json';
11
18
  export const piralJsonSchemaUrl = 'https://docs.piral.io/schemas/piral-v0.json';
@@ -1,7 +1,7 @@
1
1
  import { join, resolve, relative, basename } from 'path';
2
2
  import { findDependencyVersion, copyScaffoldingFiles, isValidDependency, flattenExternals } from './package';
3
3
  import { createPiralStubIndexIfNotExists } from './template';
4
- import { filesTar, filesOnceTar, packageJson, piralJson } from './constants';
4
+ import { filesTar, filesOnceTar, packageJson, piralJson, emulatorJson } from './constants';
5
5
  import { cliVersion } from './info';
6
6
  import { createNpmPackage } from './npm';
7
7
  import { createPiralDeclaration } from './declaration';
@@ -238,7 +238,7 @@ export async function createEmulatorWebsite(
238
238
  },
239
239
  };
240
240
 
241
- await writeJson(targetDir, 'emulator.json', data, true);
241
+ await writeJson(targetDir, emulatorJson, data, true);
242
242
 
243
243
  // generate the associated index.d.ts
244
244
  await createPiralDeclaration(sourceDir, piralPkg.app ?? `./src/index.html`, targetDir, ForceOverwrite.yes, logLevel);
@@ -7,7 +7,7 @@ import { log } from './log';
7
7
  import { standardHeaders } from './info';
8
8
  import { getTokenInteractively } from './interactive';
9
9
  import { axios, FormData } from '../external';
10
- import { PiletPublishScheme } from '../types';
10
+ import { PublishScheme } from '../types';
11
11
 
12
12
  function getMessage(body: string | { message?: string }) {
13
13
  if (typeof body === 'string') {
@@ -67,7 +67,7 @@ export type FormDataObj = Record<string, string | number | boolean | [Buffer, st
67
67
 
68
68
  export function postForm(
69
69
  target: string,
70
- scheme: PiletPublishScheme,
70
+ scheme: PublishScheme,
71
71
  key: string,
72
72
  formData: FormDataObj,
73
73
  customHeaders: Record<string, string> = {},
@@ -192,7 +192,7 @@ export function postForm(
192
192
 
193
193
  export function postFile(
194
194
  target: string,
195
- scheme: PiletPublishScheme,
195
+ scheme: PublishScheme,
196
196
  key: string,
197
197
  file: Buffer,
198
198
  customFields: Record<string, string> = {},
@@ -25,8 +25,11 @@ export * from './package';
25
25
  export * from './parallel';
26
26
  export * from './patcher';
27
27
  export * from './patches';
28
+ export * from './pilet';
29
+ export * from './piral';
28
30
  export * from './platform';
29
31
  export * from './port';
32
+ export * from './release';
30
33
  export * from './rules';
31
34
  export * from './scaffold';
32
35
  export * from './scripts';
@@ -3,7 +3,7 @@ import { openBrowserAt } from './browser';
3
3
  import { standardHeaders } from './info';
4
4
  import { logSuspend, logInfo } from './log';
5
5
  import { axios, inquirer } from '../external';
6
- import { PiletPublishScheme } from '../types';
6
+ import { PublishScheme } from '../types';
7
7
 
8
8
  export function promptSelect(message: string, values: Array<string>, defaultValue: string): Promise<string> {
9
9
  const questions = [
@@ -30,7 +30,7 @@ export function promptConfirm(message: string, defaultValue: boolean): Promise<b
30
30
  return inquirer.prompt(questions).then((answers: any) => answers.q);
31
31
  }
32
32
 
33
- type TokenResult = Promise<{ mode: PiletPublishScheme; token: string }>;
33
+ type TokenResult = Promise<{ mode: PublishScheme; token: string }>;
34
34
 
35
35
  const tokenRetrievers: Record<string, TokenResult> = {};
36
36
 
@@ -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
+ }