@genesislcap/build-kit 14.162.2-alpha-a2fd6f2.0 → 14.162.3

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 (46) hide show
  1. package/dist/utils/index.d.ts +0 -1
  2. package/dist/utils/index.d.ts.map +1 -1
  3. package/dist/utils/index.js +0 -1
  4. package/dist/utils/prompts.js +1 -1
  5. package/dist/utils/seed.processing.d.ts.map +1 -1
  6. package/dist/utils/seed.processing.js +3 -3
  7. package/package.json +3 -3
  8. package/src/index.ts +2 -0
  9. package/src/types/build-context.ts +57 -0
  10. package/src/types/config.ts +269 -0
  11. package/src/types/index.ts +3 -0
  12. package/src/types/pwa.ts +67 -0
  13. package/src/utils/archive.ts +18 -0
  14. package/src/utils/args.ts +7 -0
  15. package/src/utils/build-context.ts +42 -0
  16. package/src/utils/child-process.ts +115 -0
  17. package/src/utils/config.ts +45 -0
  18. package/src/utils/console.ts +1 -0
  19. package/src/utils/env.ts +71 -0
  20. package/src/utils/federation.ts +40 -0
  21. package/src/utils/fs.ts +53 -0
  22. package/src/utils/handlebars.ts +61 -0
  23. package/src/utils/https.ts +29 -0
  24. package/src/utils/index.ts +21 -0
  25. package/src/utils/json.ts +12 -0
  26. package/src/utils/npm.ts +155 -0
  27. package/src/utils/object.ts +21 -0
  28. package/src/utils/prompts.ts +160 -0
  29. package/src/utils/proxy.ts +139 -0
  30. package/src/utils/seed.fetching.ts +257 -0
  31. package/src/utils/seed.meta.ts +34 -0
  32. package/src/utils/seed.processing.ts +100 -0
  33. package/src/utils/seed.setup.ts +101 -0
  34. package/src/utils/time.ts +1 -0
  35. package/test/utils/args.test.ts +17 -0
  36. package/test/utils/build-context.test.ts +68 -0
  37. package/test/utils/env.test.ts +212 -0
  38. package/test/utils/handlebars.test.ts +277 -0
  39. package/test/utils/https.test.ts +14 -0
  40. package/test/utils/proxy.test.ts +96 -0
  41. package/test/utils/seed.fetching.test.ts +145 -0
  42. package/test/utils/seed.meta.test.ts +33 -0
  43. package/tsconfig.json +18 -0
  44. package/dist/utils/seed.commands.d.ts +0 -19
  45. package/dist/utils/seed.commands.d.ts.map +0 -1
  46. package/dist/utils/seed.commands.js +0 -58
@@ -14,7 +14,6 @@ export * from './npm';
14
14
  export * from './prompts';
15
15
  export * from './proxy';
16
16
  export * from './object';
17
- export * from './seed.commands';
18
17
  export * from './seed.fetching';
19
18
  export * from './seed.meta';
20
19
  export * from './seed.processing';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,OAAO,CAAC;AACtB,cAAc,cAAc,CAAC;AAC7B,cAAc,MAAM,CAAC;AACrB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,OAAO,CAAC;AACtB,cAAc,cAAc,CAAC;AAC7B,cAAc,MAAM,CAAC;AACrB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC"}
@@ -17,7 +17,6 @@ tslib_1.__exportStar(require("./npm"), exports);
17
17
  tslib_1.__exportStar(require("./prompts"), exports);
18
18
  tslib_1.__exportStar(require("./proxy"), exports);
19
19
  tslib_1.__exportStar(require("./object"), exports);
20
- tslib_1.__exportStar(require("./seed.commands"), exports);
21
20
  tslib_1.__exportStar(require("./seed.fetching"), exports);
22
21
  tslib_1.__exportStar(require("./seed.meta"), exports);
23
22
  tslib_1.__exportStar(require("./seed.processing"), exports);
@@ -77,7 +77,7 @@ exports.getPromptValidators = getPromptValidators;
77
77
  // process CLI prompt params
78
78
  const getCLIParams = (persistedAnswers, params, defaults, dir, subdir, skipOptionalPrompts, seedMeta, details, validate) => {
79
79
  const base = skipOptionalPrompts ? defaults : {};
80
- const cliParams = Object.assign(Object.assign(Object.assign(Object.assign({}, base), persistedAnswers), params), { appName: (0, node_path_1.basename)(dir), pkgName: (0, node_path_1.basename)(dir), directory: dir, appSeed: {
80
+ const cliParams = Object.assign(Object.assign(Object.assign(Object.assign({}, base), persistedAnswers), params), { appName: (0, node_path_1.basename)(dir), pkgName: (0, node_path_1.basename)(dir), directory: (0, node_path_1.basename)(dir), appSeed: {
81
81
  type: seedMeta.local ? 'local' : 'remote',
82
82
  name: seedMeta.seed,
83
83
  description: details.description,
@@ -1 +1 @@
1
- {"version":3,"file":"seed.processing.d.ts","sourceRoot":"","sources":["../../src/utils/seed.processing.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,gBAAgB,iBAAiB,CAAC;AAE/C,eAAO,MAAM,gBAAgB,yBAA2B,MAAM,EAAE,kBAkB/D,CAAC;AAmCF,eAAO,MAAM,cAAc,yFAsC1B,CAAC"}
1
+ {"version":3,"file":"seed.processing.d.ts","sourceRoot":"","sources":["../../src/utils/seed.processing.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,gBAAgB,iBAAiB,CAAC;AAE/C,eAAO,MAAM,gBAAgB,yBAA2B,MAAM,EAAE,kBAkB/D,CAAC;AAmCF,eAAO,MAAM,cAAc,yFAmC1B,CAAC"}
@@ -9,7 +9,6 @@ const console_1 = require("./console");
9
9
  const fs_1 = require("./fs");
10
10
  const handlebars_1 = require("./handlebars");
11
11
  const json_1 = require("./json");
12
- const formatPersistedData = (data) => (Object.assign(Object.assign({}, data), { directory: (0, node_path_1.basename)(data.directory) }));
13
12
  exports.PROMPT_DATA_FILE = 'answers.json';
14
13
  const removeExclusions = (dir, exclusions) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
15
14
  try {
@@ -79,8 +78,9 @@ const processOptions = (fetchSeedResult, dir, data, isInit, persistedAnswers) =>
79
78
  if (options.persistAnswers) {
80
79
  const jsonPath = (0, node_path_1.resolve)(fetchSeedResult.genxDir, exports.PROMPT_DATA_FILE);
81
80
  const additions = persistedAnswers.additions || [];
82
- const addData = Object.assign(Object.assign({}, data), { appSeed: persistedAnswers.appSeed, additions: [...additions, data.appSeed] });
83
- const json = isInit ? formatPersistedData(data) : formatPersistedData(addData);
81
+ const json = isInit
82
+ ? data
83
+ : Object.assign(Object.assign({}, data), { appSeed: persistedAnswers.appSeed, additions: [...additions, data.appSeed] });
84
84
  (0, json_1.writeJSON)(jsonPath, json);
85
85
  }
86
86
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@genesislcap/build-kit",
3
3
  "description": "Build utilities & types",
4
- "version": "14.162.2-alpha-a2fd6f2.0",
4
+ "version": "14.162.3",
5
5
  "license": "SEE LICENSE IN license.txt",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "devDependencies": {
38
38
  "@esbuild-kit/cjs-loader": "2.4.2",
39
- "@genesislcap/foundation-testing": "14.162.2-alpha-a2fd6f2.0",
39
+ "@genesislcap/foundation-testing": "14.162.3",
40
40
  "@types/http-proxy": "^1.17.8",
41
41
  "@types/node": "^20.8.7",
42
42
  "tsm": "^2.2.1",
@@ -51,5 +51,5 @@
51
51
  "publishConfig": {
52
52
  "access": "public"
53
53
  },
54
- "gitHead": "98e0b9eab3be45356523abc1ebbed8c958dd931b"
54
+ "gitHead": "ec9c4e02d46ba766a3760bbe85a77ffb40c6c55c"
55
55
  }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './utils';
2
+ export * from './types';
@@ -0,0 +1,57 @@
1
+ import type { PackageJson } from 'pkg-types';
2
+ import { Config } from './config';
3
+
4
+ export enum ENV {
5
+ PROD = 'production',
6
+ DEV = 'development',
7
+ TEST = 'test',
8
+ }
9
+
10
+ export enum COMMAND {
11
+ BUILD = 'build',
12
+ DEV = 'dev',
13
+ TEST = 'test',
14
+ ANALYZE = 'analyze',
15
+ RUN = 'run',
16
+ UPGRADE = 'upgrade',
17
+ LINT = 'lint',
18
+ INIT = 'init',
19
+ ADD = 'add',
20
+ }
21
+
22
+ export interface BuildContext {
23
+ cli: {
24
+ command: COMMAND;
25
+ isDev: boolean;
26
+ isBuild: boolean;
27
+ isTest: boolean;
28
+ isAnalyze: boolean;
29
+ isRun: boolean;
30
+ isLint: boolean;
31
+ // CLI options
32
+ options: { [index: string]: any };
33
+ };
34
+ env: {
35
+ isCI: boolean;
36
+ };
37
+ // resolved options from genx.config.{js,json,ts} or genx key in package.json
38
+ config: Config;
39
+ // package.json of current project
40
+ pkg: PackageJson;
41
+ dirs: {
42
+ // working directory
43
+ cwd: string;
44
+ // monorepo root directory
45
+ workspace?: string;
46
+ };
47
+ resolve: {
48
+ alias: {
49
+ [index: string]: string;
50
+ };
51
+ };
52
+ enable: {
53
+ apiExtractor?: object;
54
+ cemAnalyzer?: object;
55
+ mft?: object;
56
+ };
57
+ }
@@ -0,0 +1,269 @@
1
+ import { COMMAND } from './build-context';
2
+ import { PWAManifest } from './pwa';
3
+
4
+ export interface WebpackFilenames {
5
+ chunk?: ({ isDev }: { isDev: boolean }) => string;
6
+ file?: ({ isDev }: { isDev: boolean }) => string;
7
+ sourceMap?: ({ isDev }: { isDev: boolean }) => string;
8
+ }
9
+
10
+ /**
11
+ * GENX CLI configuration
12
+ * Loaded from genx.config.{js,json,ts} or genx key in package.json in working directory
13
+ */
14
+ export interface Config {
15
+ app?: {
16
+ /**
17
+ * Root application element name (must include hyphen)
18
+ */
19
+ rootElement?: string;
20
+ };
21
+ /**
22
+ * Override default builder for a given CLI command (dev/build/analyze/test).
23
+ * A given builder typically supports a subset of all possible commands (e.g. a test runner won't handle analyze command).
24
+ * If you use an incompatible builder, you'll get an unrecognized command error.
25
+ * @defaultValue
26
+ * ```
27
+ * {
28
+ * default: 'webpack',
29
+ * dev: 'vite',
30
+ * lint: 'eslint-stylelint',
31
+ * test: 'uvu-playwright',
32
+ * }
33
+ * ```
34
+ * @example
35
+ * ```
36
+ * "builder": {
37
+ * "build": "ts",
38
+ * "dev": "ts"
39
+ * }
40
+ * ```
41
+ */
42
+ builder?: {
43
+ [index in COMMAND | 'default']: string;
44
+ };
45
+ /**
46
+ * Controls whether dist folder should be cleared out before the build.
47
+ * Can be overriden using `GENX_NO_CLEAN` environment variable.
48
+ * @defaultValue true
49
+ */
50
+ clean?: boolean;
51
+ /**
52
+ * Static assets to copy during the build.
53
+ * @defaultValue ['src/**\/*.{css,jpg,png,svg,mp4,ogg,webm}']
54
+ */
55
+ copyAssets?: string[];
56
+ /**
57
+ * Override default entry point
58
+ * Paths are resolved relative to src folder
59
+ * @example
60
+ * ```
61
+ * "entry": {
62
+ * "electron": "electron.main.ts"
63
+ * }
64
+ * ```
65
+ */
66
+ entry?: string | { [index: string]: string };
67
+ /**
68
+ * Environment variables to expose in UI code. Regex patterns allowed.
69
+ * @defaultValue `['API_HOST', 'DEFAULT_ORGANISATION', 'DEFAULT_USER', 'DEFAULT_PASSWORD', 'ENABLE_SSO', 'GENX.*', 'GENX_*', 'FORCE_HTTP', 'SOCKET_EXT']
70
+ */
71
+ env?: string[];
72
+ /**
73
+ * Exclude modules from the output bundle.
74
+ * @remark This setting has no effect on `ts-builder`
75
+ * @defaultValue `index.ts`
76
+ * @example
77
+ * ```
78
+ * "externals": {
79
+ * "@ag-grid-community/core": "agGrid"
80
+ * }
81
+ * ```
82
+ */
83
+ externals?: {
84
+ [index: string]: string;
85
+ };
86
+ /**
87
+ * Module federation options.
88
+ */
89
+ federation?: {
90
+ /**
91
+ * Federation dashboard URL
92
+ */
93
+ dashboardURL?: string;
94
+ /**
95
+ * Federation publish version
96
+ * Defaults to version in package.json.
97
+ */
98
+ publishVersion?: string;
99
+ /**
100
+ * Remote federated modules
101
+ * @example
102
+ * ```
103
+ * remotes: ["@genesislcap/foundation-zero"]
104
+ * ```
105
+ */
106
+ remotes?: {
107
+ [index: string]: string;
108
+ };
109
+ /**
110
+ * Shared federated modules
111
+ * @example
112
+ * ```
113
+ * shared: ["@microsoft/fast-components", "@microsoft/fast-element", "@microsoft/fast-foundation"]
114
+ * ```
115
+ */
116
+ shared?: {
117
+ [index: string]: string | { singleton: boolean; requiredVersion: string };
118
+ };
119
+ /**
120
+ * Exposed entry points
121
+ * @example
122
+ * ```
123
+ * exposes: {
124
+ * "./index": "./src/index.federated.ts",
125
+ * "./utils": "./src/utils/index.ts"
126
+ * }
127
+ * ```
128
+ */
129
+ exposes?: {
130
+ [index: string]: string;
131
+ };
132
+ };
133
+ /**
134
+ * HTTP polling configuration.
135
+ * @example
136
+ * ```
137
+ * http: {
138
+ * "POLLING_MAP": {
139
+ * "EVENT_AMEND_USER": {
140
+ * "TEMP_FREQUENCY": 400,
141
+ * "AMOUNT_OF_POLLS": 5,
142
+ * "QUERIES": [
143
+ * "ALL_USERS"
144
+ * ]
145
+ * }
146
+ * },
147
+ * "POLLING_INTERVAL_MAP": {
148
+ * "ALL_TRADES": 4000,
149
+ * "ALL_USERS": 4000,
150
+ * "ALL_PROCESSES_STATUS": 5000
151
+ * },
152
+ * "POLLING_FREQUENCY": 4000
153
+ * }
154
+ * ```
155
+ */
156
+ http?: object;
157
+ /*
158
+ * Web application manifest
159
+ * @remarks
160
+ * Keys are specified using camel case notation
161
+ *
162
+ * @see https://developer.mozilla.org/en-US/docs/Web/Manifest
163
+ * @example
164
+ * ```
165
+ * pwa: {
166
+ * name: 'SampleApp',
167
+ * shortName: 'SampleApp',
168
+ * startUrl: '.',
169
+ * display: 'standalone',
170
+ * backgroundColor: '#FFF',
171
+ * description: 'Application manifest example.',
172
+ * icons: [{
173
+ * src: 'images/touch/homescreen48.png',
174
+ * sizes: [48]
175
+ * }]
176
+ * }
177
+ * ```
178
+ */
179
+ pwa?: PWAManifest;
180
+ /*
181
+ * Server worker configuration
182
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
183
+ */
184
+ serviceWorker?: {
185
+ /*
186
+ * Service worker file
187
+ */
188
+ worker: string;
189
+ /*
190
+ * Service worker registration file
191
+ */
192
+ registration: string;
193
+ /*
194
+ * Generated service worker asset filename
195
+ * @defaultValue `service-worker.js`
196
+ */
197
+ assetName?: string;
198
+ /*
199
+ * Exclude from from the precache manifest
200
+ * @defaultValue `[/\.map$/, /^manifest.*\.js$]`
201
+ */
202
+ exclude?: Array<string | RegExp | ((arg0: any) => boolean)>;
203
+ /*
204
+ * Maximum size of files to precache, in bytes. This prevents you from inadvertently precaching very large files that might have accidentally matched one of your patterns.
205
+ * @defaultValue `2097152`
206
+ */
207
+ maximumFileSizeToCache?: number;
208
+ };
209
+ /*
210
+ * Webpack specific configuration
211
+ */
212
+ webpack?: {
213
+ /*
214
+ * Whether to polyfill or mock certain Node.js globals
215
+ * @see https://webpack.js.org/configuration/node/
216
+ */
217
+ node?:
218
+ | false
219
+ | {
220
+ [index: string]: boolean | string;
221
+ };
222
+ /**
223
+ * Customize bundle filenames.
224
+ *
225
+ * @note Be careful when using non-hashed based filenames in production
226
+ * as most browsers will cache the asset and not detect the changes on first load.
227
+ *
228
+ * @see https://webpack.js.org/configuration/output/#outputfilename
229
+ * @example
230
+ * ```js
231
+ * filenames: {
232
+ * chunk: ({ isDev }) => (isDev ? '[name].js' : '[id].[contenthash].js')
233
+ * }
234
+ * ```
235
+ */
236
+ filenames?: WebpackFilenames;
237
+ /**
238
+ * Customize Webpack optimization settings.
239
+ *
240
+ * @see https://webpack.js.org/configuration/optimization/
241
+ */
242
+ optimization?: ({ isDev }: { isDev: boolean }) => unknown;
243
+ /**
244
+ * Set Webpack deployment target.
245
+ *
246
+ * @see https://webpack.js.org/concepts/targets/
247
+ */
248
+ target?: string | false | string[];
249
+ /**
250
+ * Dev server middleware writeToDisk toggle.
251
+ *
252
+ * @remarks
253
+ * Useful during development when watching packages for changes that are bundled with webpack.
254
+ *
255
+ * @example
256
+ * ```json
257
+ * "genx": {
258
+ * "app": {...},
259
+ * "webpack": {
260
+ * "writeToDisk": true
261
+ * }
262
+ * },
263
+ * ```
264
+ *
265
+ * @see https://webpack.js.org/configuration/dev-server/#devserverdevmiddleware
266
+ */
267
+ writeToDisk?: boolean;
268
+ };
269
+ }
@@ -0,0 +1,3 @@
1
+ export * from './build-context';
2
+ export * from './config';
3
+ export * from './pwa';
@@ -0,0 +1,67 @@
1
+ export type PWADirection = 'ltr' | 'rtl' | 'auto';
2
+ export type PWADisplay = 'fullscreen' | 'standalone' | 'minimal-ui' | 'browser';
3
+ export type PWAOrientation =
4
+ | 'any'
5
+ | 'natural'
6
+ | 'landscape'
7
+ | 'landscape-primary'
8
+ | 'landscape-secondary'
9
+ | 'portrait'
10
+ | 'portrait-primary'
11
+ | 'portrait-secondary';
12
+ export type PWACrossOrigin = 'use-credentials' | 'anonymous';
13
+
14
+ export interface PWARelatedApplications {
15
+ platform?: string;
16
+ url: string;
17
+ id?: string;
18
+ }
19
+ export interface PWAIosOptions {
20
+ 'apple-touch-icon'?: string | PWAIosAppleTouchIcon;
21
+ 'apple-touch-startup-image'?: string;
22
+ 'apple-mobile-web-app-title'?: string;
23
+ 'apple-mobile-web-app-capable'?: 'yes' | 'no' | boolean;
24
+ 'apple-mobile-web-app-status-bar-style'?: 'default' | 'black' | 'black-translucent';
25
+ }
26
+ export interface PWAIosAppleTouchIcon {
27
+ sizes?: string | number;
28
+ href: string;
29
+ }
30
+ export interface PWAIcon {
31
+ src: string;
32
+ size?: string | number;
33
+ sizes?: number[];
34
+ destination?: string;
35
+ ios?: boolean | 'default' | 'startup';
36
+ purpose?: string;
37
+ type?: string;
38
+ }
39
+
40
+ // Only listing the officially supported keys here https://developer.mozilla.org/en-US/docs/Web/Manifest
41
+ // Bundler-specific keys can still be passed in because of the index type below
42
+ export interface PWAManifest {
43
+ backgroundColor?: string;
44
+ categories?: string[];
45
+ crossorigin?: PWACrossOrigin;
46
+ description?: string;
47
+ dir?: PWADirection;
48
+ display?: PWADisplay;
49
+ displayOverride?: string[];
50
+ fileHandlers?: object[];
51
+ icons?: PWAIcon | PWAIcon[];
52
+ id?: string;
53
+ ios?: boolean | PWAIosOptions;
54
+ lang?: string;
55
+ launchHandler?: object;
56
+ name: string;
57
+ orientation?: PWAOrientation;
58
+ preferRelatedApplications?: boolean;
59
+ relatedApplications?: PWARelatedApplications[];
60
+ scope?: string;
61
+ screenshots?: object[];
62
+ shareTarget?: string;
63
+ shortName?: string;
64
+ startUrl?: string;
65
+ themeColor?: string;
66
+ [index: string]: string | object | boolean;
67
+ }
@@ -0,0 +1,18 @@
1
+ import { cpSync } from 'node:fs';
2
+ import consola from 'consola';
3
+ import download from 'download-tarball';
4
+ import tmp from 'tmp';
5
+
6
+ export const downloadTarball = async (url: string, destination: string, subPath = '') => {
7
+ const tmpDir = tmp.dirSync();
8
+
9
+ consola.debug({
10
+ tmp: tmpDir.name,
11
+ destination,
12
+ url,
13
+ });
14
+
15
+ await download({ url, dir: tmpDir.name });
16
+ const source = `${tmpDir.name}${subPath}`;
17
+ cpSync(`${source}`, destination, { recursive: true });
18
+ };
@@ -0,0 +1,7 @@
1
+ import unparse from 'unparse-args';
2
+
3
+ export const unparseArgs = (args: object): string => {
4
+ const clone = { ...args };
5
+ delete clone['--']; // always included in cac parsed options
6
+ return unparse(clone).command_string;
7
+ };
@@ -0,0 +1,42 @@
1
+ import { resolve } from 'node:path';
2
+ import { findWorkspaceDir } from 'pkg-types';
3
+ import { BuildContext, COMMAND } from '../types';
4
+ import { loadConfig } from './config';
5
+ import { loadPackageJSON, tryRequire } from './npm';
6
+
7
+ export const loadBuildContext = async (cwd, command: COMMAND, options): Promise<BuildContext> => {
8
+ const pkg = await loadPackageJSON();
9
+ const workspace = await findWorkspaceDir();
10
+ const config = await loadConfig(pkg);
11
+ return {
12
+ cli: {
13
+ command,
14
+ isDev: command === COMMAND.DEV,
15
+ isAnalyze: command === COMMAND.ANALYZE,
16
+ isBuild: command === COMMAND.BUILD,
17
+ isTest: command === COMMAND.TEST,
18
+ isRun: command === COMMAND.RUN,
19
+ isLint: command === COMMAND.LINT,
20
+ options,
21
+ },
22
+ env: {
23
+ isCI: !!process.env.CI,
24
+ },
25
+ dirs: {
26
+ cwd,
27
+ workspace,
28
+ },
29
+ resolve: {
30
+ alias: {
31
+ pbc: resolve(cwd, './src/pbc'),
32
+ },
33
+ },
34
+ pkg,
35
+ config,
36
+ enable: {
37
+ apiExtractor: tryRequire('./api-extractor', cwd),
38
+ cemAnalyzer: tryRequire('./custom-elements-manifest.config', cwd),
39
+ mft: tryRequire('./federation.config'),
40
+ },
41
+ };
42
+ };
@@ -0,0 +1,115 @@
1
+ import { spawnSync, spawn } from 'node:child_process';
2
+ import { resolve as resolvePath, relative } from 'node:path';
3
+ import consola from 'consola';
4
+
5
+ export interface RunOptions {
6
+ exitOnError?: boolean;
7
+ prefixCommandWithNode?: boolean;
8
+ verbose?: boolean;
9
+ env?: Record<string, string>;
10
+ nodeArgs?: string;
11
+ }
12
+
13
+ export const run = (cwd, command, options: RunOptions = {}) => {
14
+ const {
15
+ exitOnError = true,
16
+ // defaulting to true for Windows support
17
+ prefixCommandWithNode = true,
18
+ env = { ...process.env },
19
+ nodeArgs = '',
20
+ verbose = true,
21
+ } = options;
22
+
23
+ const fullCommand = prefixCommandWithNode ? `node ${nodeArgs} ${command}` : command;
24
+
25
+ const result = spawnSync(fullCommand, {
26
+ shell: true,
27
+ cwd,
28
+ stdio: verbose ? 'inherit' : 'ignore',
29
+ env,
30
+ });
31
+
32
+ if (result.status === 1 && exitOnError) {
33
+ process.exit(result.status);
34
+ }
35
+
36
+ return result;
37
+ };
38
+
39
+ const normaliseNPMCLI = (cli: string): string => {
40
+ if (cli.toLowerCase() === 'npm') {
41
+ return process.platform.match(/^win/) ? 'npm.cmd' : 'npm';
42
+ }
43
+ return cli;
44
+ };
45
+
46
+ export const runAsync = async (cwd, command, options: RunOptions = {}): Promise<Error | null> => {
47
+ const {
48
+ exitOnError = true,
49
+ prefixCommandWithNode = true,
50
+ env = { ...process.env },
51
+ nodeArgs = '',
52
+ verbose = true,
53
+ } = options;
54
+
55
+ return new Promise((resolve, reject) => {
56
+ const chunks = command.trim().split(' ');
57
+ const fullCommand = prefixCommandWithNode
58
+ ? `node ${nodeArgs} ${chunks.shift()}`
59
+ : chunks.shift();
60
+ const crossPlatformCommand = normaliseNPMCLI(fullCommand);
61
+ const child = spawn(crossPlatformCommand, chunks, {
62
+ cwd,
63
+ stdio: verbose ? 'inherit' : 'ignore',
64
+ env,
65
+ });
66
+ child.on('close', (code) => {
67
+ if (code === 0) {
68
+ resolve(null);
69
+ } else {
70
+ const err = new Error(`Unexpected error executing ${command}`);
71
+ if (exitOnError) {
72
+ consola.error(err);
73
+ return process.exit(code);
74
+ }
75
+ reject(err);
76
+ }
77
+ });
78
+ child.on('error', (err) => {
79
+ if (exitOnError) {
80
+ consola.error(err);
81
+ return process.exit(1);
82
+ }
83
+ reject(err);
84
+ });
85
+ });
86
+ };
87
+
88
+ // Based on https://github.com/unjs/giget/blob/main/src/_utils.ts#L110
89
+
90
+ const currentShell = () => {
91
+ if (process.env.SHELL) {
92
+ return process.env.SHELL;
93
+ }
94
+ if (process.platform === 'win32') {
95
+ return 'cmd.exe';
96
+ }
97
+ return '/bin/bash';
98
+ };
99
+
100
+ export const startShell = (cwd: string) => {
101
+ cwd = resolvePath(cwd);
102
+ const shell = currentShell();
103
+ consola.info(`(experimental) Opening shell in ${relative(process.cwd(), cwd)}...`);
104
+ // spawnSync command is quoted to support paths with spaces on Windows (C:/Program Files etc.)
105
+ spawnSync(`"${shell}"`, [], {
106
+ cwd,
107
+ shell: true,
108
+ stdio: 'inherit',
109
+ env: {
110
+ ...process.env,
111
+ // DEBUG (set via log-level) messes up zsh
112
+ DEBUG: undefined,
113
+ },
114
+ });
115
+ };