@genesislcap/build-kit 14.142.1-alpha-2787e5d.0 → 14.143.1

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 (42) hide show
  1. package/dist/utils/archive.d.ts +2 -0
  2. package/dist/utils/archive.d.ts.map +1 -0
  3. package/dist/utils/archive.js +20 -0
  4. package/dist/utils/index.d.ts +5 -1
  5. package/dist/utils/index.d.ts.map +1 -1
  6. package/dist/utils/index.js +5 -1
  7. package/dist/utils/npm.d.ts +1 -1
  8. package/dist/utils/npm.d.ts.map +1 -1
  9. package/dist/utils/npm.js +4 -2
  10. package/dist/utils/prompts.d.ts.map +1 -1
  11. package/dist/utils/prompts.js +7 -5
  12. package/dist/utils/seed.fetching.d.ts +36 -0
  13. package/dist/utils/seed.fetching.d.ts.map +1 -0
  14. package/dist/utils/seed.fetching.js +157 -0
  15. package/dist/utils/seed.meta.d.ts +10 -0
  16. package/dist/utils/seed.meta.d.ts.map +1 -0
  17. package/dist/utils/seed.meta.js +38 -0
  18. package/dist/utils/seed.processing.d.ts +4 -0
  19. package/dist/utils/seed.processing.d.ts.map +1 -0
  20. package/dist/utils/seed.processing.js +87 -0
  21. package/dist/utils/seed.setup.d.ts +3 -0
  22. package/dist/utils/seed.setup.d.ts.map +1 -0
  23. package/dist/utils/seed.setup.js +73 -0
  24. package/package.json +6 -3
  25. package/src/utils/archive.ts +18 -0
  26. package/src/utils/index.ts +5 -1
  27. package/src/utils/npm.ts +4 -2
  28. package/src/utils/prompts.ts +8 -5
  29. package/src/utils/seed.fetching.ts +256 -0
  30. package/src/utils/seed.meta.ts +34 -0
  31. package/src/utils/seed.processing.ts +100 -0
  32. package/src/utils/seed.setup.ts +98 -0
  33. package/test/fixtures/mock-seed/.genx/.genxrc.js +7 -0
  34. package/test/fixtures/mock-seed/.genx/configure.js +3 -0
  35. package/test/fixtures/mock-seed/.genx/package.json +17 -0
  36. package/test/fixtures/mock-seed/test.md +44 -0
  37. package/test/utils/seed.fetching.test.ts +145 -0
  38. package/test/utils/seed.meta.test.ts +33 -0
  39. package/dist/utils/seed.d.ts +0 -31
  40. package/dist/utils/seed.d.ts.map +0 -1
  41. package/dist/utils/seed.js +0 -264
  42. package/src/utils/seed.ts +0 -351
@@ -0,0 +1,2 @@
1
+ export declare const downloadTarball: (url: string, destination: string, subPath?: string) => Promise<void>;
2
+ //# sourceMappingURL=archive.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"archive.d.ts","sourceRoot":"","sources":["../../src/utils/archive.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,eAAe,QAAe,MAAM,eAAe,MAAM,oCAYrE,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.downloadTarball = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const consola_1 = tslib_1.__importDefault(require("consola"));
6
+ const download_tarball_1 = tslib_1.__importDefault(require("download-tarball"));
7
+ const tmp_1 = tslib_1.__importDefault(require("tmp"));
8
+ const fs_1 = require("./fs");
9
+ const downloadTarball = (url, destination, subPath = '') => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
10
+ const tmpDir = tmp_1.default.dirSync();
11
+ consola_1.default.debug({
12
+ tmp: tmpDir.name,
13
+ destination,
14
+ url,
15
+ });
16
+ yield (0, download_tarball_1.default)({ url, dir: tmpDir.name });
17
+ const source = `${tmpDir.name}${subPath}`;
18
+ (0, fs_1.rename)(`${source}`, destination);
19
+ });
20
+ exports.downloadTarball = downloadTarball;
@@ -1,4 +1,5 @@
1
1
  export * from './args';
2
+ export * from './archive';
2
3
  export * from './build-context';
3
4
  export * from './child-process';
4
5
  export * from './config';
@@ -11,6 +12,9 @@ export * from './json';
11
12
  export * from './npm';
12
13
  export * from './prompts';
13
14
  export * from './object';
14
- export * from './seed';
15
+ export * from './seed.fetching';
16
+ export * from './seed.meta';
17
+ export * from './seed.processing';
18
+ export * from './seed.setup';
15
19
  export * from './time';
16
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,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,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,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,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC"}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./args"), exports);
5
+ tslib_1.__exportStar(require("./archive"), exports);
5
6
  tslib_1.__exportStar(require("./build-context"), exports);
6
7
  tslib_1.__exportStar(require("./child-process"), exports);
7
8
  tslib_1.__exportStar(require("./config"), exports);
@@ -14,5 +15,8 @@ tslib_1.__exportStar(require("./json"), exports);
14
15
  tslib_1.__exportStar(require("./npm"), exports);
15
16
  tslib_1.__exportStar(require("./prompts"), exports);
16
17
  tslib_1.__exportStar(require("./object"), exports);
17
- tslib_1.__exportStar(require("./seed"), exports);
18
+ tslib_1.__exportStar(require("./seed.fetching"), exports);
19
+ tslib_1.__exportStar(require("./seed.meta"), exports);
20
+ tslib_1.__exportStar(require("./seed.processing"), exports);
21
+ tslib_1.__exportStar(require("./seed.setup"), exports);
18
22
  tslib_1.__exportStar(require("./time"), exports);
@@ -4,7 +4,7 @@ export declare const tryRequire: (id: any, rootDir?: string) => any;
4
4
  export declare const resolveBin: (bin: string, module?: string) => Promise<string>;
5
5
  export declare const loadPackageJSON: (dir?: string) => Promise<PackageJson>;
6
6
  export declare const loadPackageJSONFiles: (packages?: any[]) => Promise<PackageJson[]>;
7
- export declare const getLatestVersion: (name: any, range?: string) => any;
7
+ export declare const getLatestVersion: (name: any, range?: string, verbose?: boolean) => any;
8
8
  export declare const getRangeSpecifier: (version: any) => any;
9
9
  export declare const getRawPkg: (ctx: BuildContext) => {
10
10
  [key: string]: any;
@@ -1 +1 @@
1
- {"version":3,"file":"npm.d.ts","sourceRoot":"","sources":["../../src/utils/npm.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAG7C,eAAO,MAAM,UAAU,oCAUtB,CAAC;AAEF,eAAO,MAAM,UAAU,QAAe,MAAM,WAAU,MAAM,oBAS3D,CAAC;AAEF,eAAO,MAAM,eAAe,SAAgB,MAAM,KAAG,QAAQ,WAAW,CAUvE,CAAC;AAEF,eAAO,MAAM,oBAAoB,wBAA0B,QAAQ,WAAW,EAAE,CAM7E,CAAC;AAeJ,eAAO,MAAM,gBAAgB,oCAmB5B,CAAC;AAGF,eAAO,MAAM,iBAAiB,uBAG7B,CAAC;AAGF,eAAO,MAAM,SAAS,QAAS,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAG1C,CAAC;AAEF,eAAO,MAAM,iBAAiB,QAAe,WAAW,kBAOvD,CAAC;AAoCF,eAAO,MAAM,cAAc,QACpB,WAAW,cACJ,MAAM,WACT,MAAM,EAAE,YACR,MAAM,EAAE;UAjCR,MAAM;QAAM,MAAM;UAAQ,MAAM;GAuC1C,CAAC"}
1
+ {"version":3,"file":"npm.d.ts","sourceRoot":"","sources":["../../src/utils/npm.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAG7C,eAAO,MAAM,UAAU,oCAUtB,CAAC;AAEF,eAAO,MAAM,UAAU,QAAe,MAAM,WAAU,MAAM,oBAS3D,CAAC;AAEF,eAAO,MAAM,eAAe,SAAgB,MAAM,KAAG,QAAQ,WAAW,CAUvE,CAAC;AAEF,eAAO,MAAM,oBAAoB,wBAA0B,QAAQ,WAAW,EAAE,CAM7E,CAAC;AAeJ,eAAO,MAAM,gBAAgB,uDAqB5B,CAAC;AAGF,eAAO,MAAM,iBAAiB,uBAG7B,CAAC;AAGF,eAAO,MAAM,SAAS,QAAS,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAG1C,CAAC;AAEF,eAAO,MAAM,iBAAiB,QAAe,WAAW,kBAOvD,CAAC;AAoCF,eAAO,MAAM,cAAc,QACpB,WAAW,cACJ,MAAM,WACT,MAAM,EAAE,YACR,MAAM,EAAE;UAjCR,MAAM;QAAM,MAAM;UAAQ,MAAM;GAuC1C,CAAC"}
package/dist/utils/npm.js CHANGED
@@ -65,7 +65,7 @@ Response if multiple versions available:
65
65
  @genesislcap/genx@14.41.0 '14.41.0'
66
66
  @genesislcap/genx@14.41.1 '14.41.1'
67
67
  */
68
- const getLatestVersion = (name, range = 'latest') => {
68
+ const getLatestVersion = (name, range = 'latest', verbose = true) => {
69
69
  let result;
70
70
  try {
71
71
  result = (0, node_child_process_1.execSync)(`npm info ${name}@${range} version`, {
@@ -80,7 +80,9 @@ const getLatestVersion = (name, range = 'latest') => {
80
80
  .replace(/'/g, '');
81
81
  }
82
82
  catch (e) {
83
- consola_1.default.error(`Could not fetch ${name} version ${range} information from the registry`);
83
+ if (verbose) {
84
+ consola_1.default.error(`Could not fetch ${name} version ${range} information from the registry`);
85
+ }
84
86
  }
85
87
  return result;
86
88
  };
@@ -1 +1 @@
1
- {"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../src/utils/prompts.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAIhC,eAAO,MAAM,UAAU,YAAmB,GAAG,YAAW,GAAG,iBAAoC,CAAC;AAEhG,eAAO,MAAM,gBAAgB,uCAkB5B,CAAC;AAwBF,eAAO,MAAM,iBAAiB,gEAqB7B,CAAC;AAEF,eAAO,MAAM,mBAAmB,gEAS/B,CAAC;AA2CF,eAAO,MAAM,OAAO,mKA+BnB,CAAC"}
1
+ {"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../src/utils/prompts.ts"],"names":[],"mappings":"AACA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAIhC,eAAO,MAAM,UAAU,YAAmB,GAAG,YAAW,GAAG,iBAAoC,CAAC;AAEhG,eAAO,MAAM,gBAAgB,uCAkB5B,CAAC;AAwBF,eAAO,MAAM,iBAAiB,gEAqB7B,CAAC;AAEF,eAAO,MAAM,mBAAmB,gEAS/B,CAAC;AA8CF,eAAO,MAAM,OAAO,mKA+BnB,CAAC"}
@@ -79,11 +79,13 @@ const getCLIParams = (persistedAnswers, params, defaults, dir, subdir, skipOptio
79
79
  const cliParams = Object.assign(Object.assign(Object.assign(Object.assign({}, base), persistedAnswers), params), { appName: dir, pkgName: dir, directory: dir, appSeed: {
80
80
  type: seedMeta.local ? 'local' : 'remote',
81
81
  name: seedMeta.seed,
82
- about: details.description || '',
83
- remoteUser: seedMeta.user,
84
- remoteRepo: seedMeta.repo,
85
- remoteBranch: seedMeta.ref,
86
- subdir: seedMeta.subdir || '',
82
+ description: details.description,
83
+ version: details.version,
84
+ repo: seedMeta.repo,
85
+ artifact: seedMeta.artifact,
86
+ ref: seedMeta.ref,
87
+ subdir: seedMeta.subdir,
88
+ date: new Date(),
87
89
  } });
88
90
  const validationErrors = validate(cliParams);
89
91
  if (validationErrors.length) {
@@ -0,0 +1,36 @@
1
+ import type { PackageJson } from 'pkg-types';
2
+ export type LocalFetchResult = {
3
+ local: boolean;
4
+ genxDir: string;
5
+ seed: string;
6
+ subdir: string;
7
+ pkg: PackageJson;
8
+ dir: string;
9
+ extractedSeedDir: string;
10
+ extractedSeedGenxDir: string;
11
+ };
12
+ export type RemoteGitFetchResult = {
13
+ repo: string;
14
+ ref: string;
15
+ id: string;
16
+ };
17
+ export type RemoteNPMFetchResult = {
18
+ artifact: string;
19
+ ref: string;
20
+ };
21
+ export type RemoteFetchResult = RemoteGitFetchResult | RemoteNPMFetchResult;
22
+ export type FetchResult = LocalFetchResult | (LocalFetchResult & RemoteFetchResult);
23
+ export declare const resolveGitSeed: (seed?: string, ref?: string, subdir?: string, provider?: string) => RemoteGitFetchResult;
24
+ export declare const resolveNPMSeed: (seed?: string, ref?: string, useDefaultNPMScope?: boolean) => RemoteNPMFetchResult;
25
+ export type SeedDirs = {
26
+ isLocalSeed: boolean;
27
+ dir: string;
28
+ subdir: string;
29
+ localPath: string;
30
+ genxDir: string;
31
+ extractedSeedDir: string;
32
+ extractedSeedGenxDir: string;
33
+ };
34
+ export declare const getSeedDirs: (seed: string, dir: string, subdir: string, isInit: boolean, remote: boolean) => SeedDirs;
35
+ export declare const fetchSeed: (seed: string, dir: string, remote: boolean, ref: string, insecure: boolean, subdir: string, isInit: boolean, lookupInNPM: boolean, useDefaultNPMScope: boolean) => Promise<FetchResult>;
36
+ //# sourceMappingURL=seed.fetching.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seed.fetching.d.ts","sourceRoot":"","sources":["../../src/utils/seed.fetching.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAQ7C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,WAAW,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB,EAAE,MAAM,CAAC;IACzB,oBAAoB,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,oBAAoB,GAAG,oBAAoB,CAAC;AAE5E,MAAM,MAAM,WAAW,GAAG,gBAAgB,GAAG,CAAC,gBAAgB,GAAG,iBAAiB,CAAC,CAAC;AAEpF,eAAO,MAAM,cAAc,uEAKxB,oBAWF,CAAC;AAEF,eAAO,MAAM,cAAc,iEAIxB,oBAUF,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,WAAW,EAAE,OAAO,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,MAAM,CAAC;IACzB,oBAAoB,EAAE,MAAM,CAAC;CAC9B,CAAC;AAEF,eAAO,MAAM,WAAW,SAChB,MAAM,OACP,MAAM,UACH,MAAM,UACN,OAAO,UACP,OAAO,KACd,QAmBF,CAAC;AA2GF,eAAO,MAAM,SAAS,SACd,MAAM,OACP,MAAM,UACH,OAAO,OACV,MAAM,YACD,OAAO,UACT,MAAM,UACN,OAAO,eACF,OAAO,sBACA,OAAO,KAC1B,QAAQ,WAAW,CA8BrB,CAAC"}
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchSeed = exports.getSeedDirs = exports.resolveNPMSeed = exports.resolveGitSeed = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const node_fs_1 = require("node:fs");
6
+ const node_path_1 = require("node:path");
7
+ const consola_1 = require("consola");
8
+ const get_npm_tarball_url_1 = tslib_1.__importDefault(require("get-npm-tarball-url"));
9
+ const giget_1 = require("giget");
10
+ const archive_1 = require("./archive");
11
+ const console_1 = require("./console");
12
+ const fs_1 = require("./fs");
13
+ const npm_1 = require("./npm");
14
+ const seed_meta_1 = require("./seed.meta");
15
+ const seed_processing_1 = require("./seed.processing");
16
+ const resolveGitSeed = (seed = '', ref = 'main', subdir = '', provider = 'gh') => {
17
+ const parts = seed.split('/');
18
+ const repo = parts.pop() || 'blank-app-seed';
19
+ const user = parts.pop() || 'genesiscommunitysuccess';
20
+ const dir = subdir ? `/${subdir}` : '';
21
+ return {
22
+ repo: `${user}/${repo}`,
23
+ ref,
24
+ // Giget-compatible template ID
25
+ id: `${provider}:${user}/${repo}${dir}#${ref}`,
26
+ };
27
+ };
28
+ exports.resolveGitSeed = resolveGitSeed;
29
+ const resolveNPMSeed = (seed = '', ref = 'latest', useDefaultNPMScope = true) => {
30
+ const parts = seed.split('/');
31
+ const moduleName = parts.pop() || 'blank-app-seed';
32
+ const scope = parts.pop() || (useDefaultNPMScope ? 'genesislcap' : '');
33
+ const scopeFormatted = scope ? `@${scope}/` : '';
34
+ const artifact = `${scopeFormatted}${moduleName}`;
35
+ return {
36
+ artifact,
37
+ ref,
38
+ };
39
+ };
40
+ exports.resolveNPMSeed = resolveNPMSeed;
41
+ const getSeedDirs = (seed, dir, subdir, isInit, remote) => {
42
+ const GENX_DIR = '/.genx';
43
+ const TMP_DIR = '/tmp';
44
+ const localPath = subdir ? `${seed}/${subdir}` : seed;
45
+ const isLocalSeed = !remote && (0, node_fs_1.existsSync)(localPath);
46
+ const genxDir = (0, node_path_1.relative)(process.cwd(), `${dir}${GENX_DIR}`);
47
+ const extractedSeedDir = isInit ? dir : (0, node_path_1.relative)(process.cwd(), `${dir}${GENX_DIR}${TMP_DIR}`);
48
+ const extractedSeedGenxDir = isInit
49
+ ? genxDir
50
+ : (0, node_path_1.relative)(process.cwd(), `${extractedSeedDir}${GENX_DIR}`);
51
+ return {
52
+ localPath,
53
+ dir,
54
+ subdir,
55
+ isLocalSeed,
56
+ genxDir,
57
+ extractedSeedDir,
58
+ extractedSeedGenxDir,
59
+ };
60
+ };
61
+ exports.getSeedDirs = getSeedDirs;
62
+ const copyLocalSeed = (dirs, ref, start) => {
63
+ const { dir, subdir, localPath, extractedSeedDir, genxDir, extractedSeedGenxDir } = dirs;
64
+ consola_1.consola.info(`Copying local seed ${(0, console_1.bold)(localPath)}`);
65
+ try {
66
+ if (ref) {
67
+ consola_1.consola.warn(`${(0, console_1.bold)('ref')} has no effect when used with a local seed`);
68
+ }
69
+ (0, node_fs_1.cpSync)(localPath, extractedSeedDir, { recursive: true });
70
+ consola_1.consola.success(`Seed copied in ${Date.now() - start}ms`);
71
+ return {
72
+ local: true,
73
+ genxDir,
74
+ seed: localPath,
75
+ subdir,
76
+ pkg: (0, seed_meta_1.loadGenxModule)(extractedSeedGenxDir),
77
+ dir,
78
+ extractedSeedDir,
79
+ extractedSeedGenxDir,
80
+ };
81
+ }
82
+ catch (e) {
83
+ consola_1.consola.error(`Error copying ${localPath} to ${(0, console_1.bold)(dir)}`, e);
84
+ process.exit(1);
85
+ }
86
+ };
87
+ const fetchNPMSeed = (seed, ref, dirs, useDefaultNPMScope, start) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
88
+ let success = true;
89
+ const data = (0, exports.resolveNPMSeed)(seed, ref, useDefaultNPMScope);
90
+ consola_1.consola.info(`Downloading NPM module ${(0, console_1.bold)(data.artifact)} (dist tag ${(0, console_1.bold)(data.ref)}, subdir: ${(0, console_1.bold)(dirs.subdir || 'N/A')}) to ${(0, console_1.bold)(dirs.dir)} directory...`);
91
+ try {
92
+ const version = (0, npm_1.getLatestVersion)(data.artifact, data.ref, false);
93
+ const url = (0, get_npm_tarball_url_1.default)(data.artifact, version);
94
+ // NPM tarballs contains top-level directory called package
95
+ yield (0, archive_1.downloadTarball)(url, dirs.extractedSeedDir, `${node_path_1.sep}package`).catch((err) => {
96
+ consola_1.consola.warn('Error downloading module', err);
97
+ success = false;
98
+ });
99
+ }
100
+ catch (err) {
101
+ success = false;
102
+ consola_1.consola.warn('Error fetching version information from the registry');
103
+ }
104
+ // If NPM download successful return result, otherwise fall back to Git download
105
+ if (success) {
106
+ consola_1.consola.success(`Seed downloaded in ${Date.now() - start}ms`);
107
+ return Object.assign({ local: false, genxDir: dirs.genxDir, seed, subdir: dirs.subdir, pkg: (0, seed_meta_1.loadGenxModule)(dirs.extractedSeedGenxDir), dir: dirs.dir, extractedSeedDir: dirs.extractedSeedDir, extractedSeedGenxDir: dirs.extractedSeedGenxDir }, data);
108
+ }
109
+ });
110
+ const fetchGitSeed = (seed, ref, dirs, start) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
111
+ const data = (0, exports.resolveGitSeed)(seed, ref, dirs.subdir);
112
+ consola_1.consola.info(`Downloading Git seed ${(0, console_1.bold)(data.repo)} (Ref ${(0, console_1.bold)(data.ref)}, subdir: ${(0, console_1.bold)(dirs.subdir || 'N/A')}) to ${(0, console_1.bold)(dirs.dir)} directory...`);
113
+ try {
114
+ yield (0, giget_1.downloadTemplate)(data.id, {
115
+ dir: dirs.extractedSeedDir,
116
+ // auth?: string; // custom Authorization token to use for downloading template
117
+ registry: false, // disable built-in Giget registry
118
+ });
119
+ consola_1.consola.success(`Seed downloaded in ${Date.now() - start}ms`);
120
+ return Object.assign({ local: false, genxDir: dirs.genxDir, seed, subdir: dirs.subdir, pkg: (0, seed_meta_1.loadGenxModule)(dirs.extractedSeedGenxDir), dir: dirs.dir, extractedSeedDir: dirs.extractedSeedDir, extractedSeedGenxDir: dirs.extractedSeedGenxDir }, data);
121
+ }
122
+ catch (err) {
123
+ const error = process.env.DEBUG ? err : err.message;
124
+ consola_1.consola.error(error);
125
+ process.exit(1);
126
+ }
127
+ });
128
+ // download remote or copy local seed
129
+ const fetchSeed = (seed, dir, remote, ref, insecure, subdir, isInit, lookupInNPM, useDefaultNPMScope) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
130
+ var _a;
131
+ // disable SSL cert verification
132
+ if (insecure) {
133
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
134
+ }
135
+ const start = Date.now();
136
+ const dirs = (0, exports.getSeedDirs)(seed, dir, subdir, isInit, remote);
137
+ if (!isInit) {
138
+ yield (0, fs_1.rm)(dirs.extractedSeedDir);
139
+ (0, node_fs_1.mkdirSync)(dirs.extractedSeedDir);
140
+ }
141
+ let result;
142
+ if (dirs.isLocalSeed) {
143
+ result = copyLocalSeed(dirs, ref, start);
144
+ }
145
+ else {
146
+ if (lookupInNPM) {
147
+ result = yield fetchNPMSeed(seed, ref, dirs, useDefaultNPMScope, start);
148
+ }
149
+ // if NPM lookup disabled or if it's enabled & failed, fall back to Git
150
+ if (!lookupInNPM || !result) {
151
+ result = yield fetchGitSeed(seed, ref, dirs, start);
152
+ }
153
+ }
154
+ yield (0, seed_processing_1.removeExclusions)(dirs.extractedSeedDir, (_a = result.pkg.genxSeedConfig) === null || _a === void 0 ? void 0 : _a.exclude);
155
+ return result;
156
+ });
157
+ exports.fetchSeed = fetchSeed;
@@ -0,0 +1,10 @@
1
+ export declare const loadSeed: (dir: any) => Promise<{
2
+ prompts: any;
3
+ configure: any;
4
+ details: any;
5
+ defaults: import("inquirer").Question<import("inquirer").Answers>;
6
+ validators: import("inquirer").Question<import("inquirer").Answers>;
7
+ validate: (data: any) => any[];
8
+ }>;
9
+ export declare const loadGenxModule: (genxDir: string, module?: string, warnIfMissing?: boolean) => any;
10
+ //# sourceMappingURL=seed.meta.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seed.meta.d.ts","sourceRoot":"","sources":["../../src/utils/seed.meta.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,QAAQ;;;;;;;EAgBpB,CAAC;AAEF,eAAO,MAAM,cAAc,YAAa,MAAM,kDAU7C,CAAC"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadGenxModule = exports.loadSeed = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const node_path_1 = require("node:path");
6
+ const consola_1 = require("consola");
7
+ const prompts_1 = require("./prompts");
8
+ // load seed details including prompt question defaults and validators
9
+ const loadSeed = (dir) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
10
+ const GENX_RC = '.genxrc.js';
11
+ const genxConfigPath = (0, node_path_1.resolve)(dir, GENX_RC);
12
+ const { prompts, configure, details } = require(genxConfigPath);
13
+ const defaults = yield (0, prompts_1.getPromptDefaults)(prompts());
14
+ const validators = yield (0, prompts_1.getPromptValidators)(prompts());
15
+ const validate = (data) => (0, prompts_1.validateSeedData)(data, validators);
16
+ return {
17
+ prompts: prompts(),
18
+ configure: configure(),
19
+ details: details(),
20
+ defaults,
21
+ validators,
22
+ validate,
23
+ };
24
+ });
25
+ exports.loadSeed = loadSeed;
26
+ const loadGenxModule = (genxDir, module = 'package.json', warnIfMissing = true) => {
27
+ const path = (0, node_path_1.resolve)(genxDir, module);
28
+ try {
29
+ return require(path);
30
+ }
31
+ catch (e) {
32
+ if (warnIfMissing) {
33
+ consola_1.consola.warn(`Could not load ${module} from ${genxDir}`);
34
+ }
35
+ return {};
36
+ }
37
+ };
38
+ exports.loadGenxModule = loadGenxModule;
@@ -0,0 +1,4 @@
1
+ export declare const PROMPT_DATA_FILE = "answers.json";
2
+ export declare const removeExclusions: (dir: any, exclusions: string[]) => Promise<void>;
3
+ export declare const processOptions: (fetchSeedResult: any, dir: any, data: any, isInit: any, persistedAnswers: any) => void;
4
+ //# sourceMappingURL=seed.processing.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processOptions = exports.removeExclusions = exports.PROMPT_DATA_FILE = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const node_fs_1 = require("node:fs");
6
+ const node_path_1 = require("node:path");
7
+ const consola_1 = require("consola");
8
+ const console_1 = require("./console");
9
+ const fs_1 = require("./fs");
10
+ const handlebars_1 = require("./handlebars");
11
+ const json_1 = require("./json");
12
+ exports.PROMPT_DATA_FILE = 'answers.json';
13
+ const removeExclusions = (dir, exclusions) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
14
+ try {
15
+ const exclude = (exclusions !== null && exclusions !== void 0 ? exclusions : []).map((x) => (0, node_path_1.resolve)(dir, x));
16
+ yield Promise.all(exclude.map((exclusion) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
17
+ if ((0, node_fs_1.existsSync)(exclusion)) {
18
+ yield (0, fs_1.rm)(exclusion);
19
+ consola_1.consola.debug(`Excluded: ${exclusion}`);
20
+ }
21
+ else {
22
+ consola_1.consola.debug(`Ignored invalid exclusion: ${exclusion}`);
23
+ }
24
+ })));
25
+ }
26
+ catch (err) {
27
+ const error = process.env.DEBUG ? err : err.message;
28
+ consola_1.consola.error(error);
29
+ process.exit(1);
30
+ }
31
+ });
32
+ exports.removeExclusions = removeExclusions;
33
+ const processItem = ({ base, dir: itemDir, path, isDir, ext, stats }, data, renamingEnabled, interpolationEnabled, interpolationWhitelist) => {
34
+ const baseNew = (0, handlebars_1.render)(base, data);
35
+ const needsRenaming = renamingEnabled && baseNew !== base;
36
+ const pathNew = needsRenaming ? (0, node_path_1.resolve)(itemDir, baseNew) : path;
37
+ if (needsRenaming) {
38
+ try {
39
+ (0, node_fs_1.renameSync)((0, node_path_1.resolve)(itemDir, base), (0, node_path_1.resolve)(itemDir, baseNew));
40
+ consola_1.consola.debug(`Renamed ${(0, console_1.bold)(base)} to ${(0, console_1.bold)(baseNew)}`);
41
+ }
42
+ catch (e) {
43
+ consola_1.consola.error(`Error renaming ${(0, console_1.bold)(base)} to ${(0, console_1.bold)(baseNew)}`);
44
+ }
45
+ }
46
+ // Handlebars rendering
47
+ if (interpolationEnabled && !isDir && interpolationWhitelist.some((i) => baseNew.includes(i))) {
48
+ try {
49
+ (0, handlebars_1.renderFile)(pathNew, data, pathNew);
50
+ consola_1.consola.debug(`Interpolated variables in ${pathNew}`);
51
+ }
52
+ catch (e) {
53
+ consola_1.consola.error(`Error interpolating variables in ${pathNew}`);
54
+ }
55
+ }
56
+ return { isDir, ext, dir: itemDir, base: baseNew, path: pathNew, stats };
57
+ };
58
+ const processOptions = (fetchSeedResult, dir, data, isInit, persistedAnswers) => {
59
+ var _a, _b;
60
+ const options = ((_a = fetchSeedResult.pkg) === null || _a === void 0 ? void 0 : _a.genxSeedConfig) || {};
61
+ consola_1.consola.debug('Seed options', JSON.stringify(options));
62
+ if (options.processFiles) {
63
+ const ignoreDirs = ((_b = options.processFiles) === null || _b === void 0 ? void 0 : _b.exclude) || [
64
+ '.git',
65
+ '.genx',
66
+ '.github',
67
+ 'node_modules',
68
+ '.gradle',
69
+ 'gradle',
70
+ ];
71
+ const filter = (entry) => !ignoreDirs.includes(entry.base);
72
+ const mapper = (entry) => {
73
+ var _a, _b, _c, _d, _e;
74
+ return processItem(entry, data, !!((_a = options.processFiles) === null || _a === void 0 ? void 0 : _a.rename), !!((_c = (_b = options.processFiles) === null || _b === void 0 ? void 0 : _b.interpolateVariables) === null || _c === void 0 ? void 0 : _c.enabled), (_e = (_d = options.processFiles) === null || _d === void 0 ? void 0 : _d.interpolateVariables) === null || _e === void 0 ? void 0 : _e.include);
75
+ };
76
+ (0, fs_1.listAllFiles)(dir, filter, mapper);
77
+ }
78
+ if (options.persistAnswers) {
79
+ const jsonPath = (0, node_path_1.resolve)(fetchSeedResult.genxDir, exports.PROMPT_DATA_FILE);
80
+ const additions = persistedAnswers.additions || [];
81
+ const json = isInit
82
+ ? data
83
+ : Object.assign(Object.assign({}, data), { appSeed: persistedAnswers.appSeed, additions: [...additions, data.appSeed] });
84
+ (0, json_1.writeJSON)(jsonPath, json);
85
+ }
86
+ };
87
+ exports.processOptions = processOptions;
@@ -0,0 +1,3 @@
1
+ export declare const installSeedDeps: (dir: any, isLogLevelVerbose: any) => Promise<void>;
2
+ export declare const configureSeedApp: (seedInfo: any, fetchSeedResult: any, params: any, dir: any, skipOptionalPrompts: any, isInit: boolean) => Promise<void>;
3
+ //# sourceMappingURL=seed.setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seed.setup.d.ts","sourceRoot":"","sources":["../../src/utils/seed.setup.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,eAAe,qDAmC3B,CAAC;AAGF,eAAO,MAAM,gBAAgB,iGAMnB,OAAO,kBAyChB,CAAC"}
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.configureSeedApp = exports.installSeedDeps = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const node_fs_1 = require("node:fs");
6
+ const node_path_1 = require("node:path");
7
+ const consola_1 = require("consola");
8
+ const child_process_1 = require("./child-process");
9
+ const fs_1 = require("./fs");
10
+ const handlebars_1 = require("./handlebars");
11
+ const json_1 = require("./json");
12
+ const object_1 = require("./object");
13
+ const prompts_1 = require("./prompts");
14
+ const seed_meta_1 = require("./seed.meta");
15
+ const seed_processing_1 = require("./seed.processing");
16
+ const installSeedDeps = (dir, isLogLevelVerbose) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
17
+ let dependencies = {};
18
+ try {
19
+ const packageJSONPath = (0, node_path_1.resolve)(dir, 'package.json');
20
+ const packageJSON = require(packageJSONPath);
21
+ dependencies = packageJSON.dependencies || {};
22
+ }
23
+ catch (e) { }
24
+ consola_1.consola.debug('Seed NPM dependencies', {
25
+ targetInstallDir: dir,
26
+ dependencyCount: Object.keys(dependencies).length,
27
+ });
28
+ if (Object.keys(dependencies).length !== 0) {
29
+ const start2 = Date.now();
30
+ consola_1.consola.info('Installing seed NPM dependencies...');
31
+ yield (0, child_process_1.runAsync)(dir, 'npm install', {
32
+ prefixCommandWithNode: false,
33
+ exitOnError: false,
34
+ verbose: isLogLevelVerbose,
35
+ env: Object.assign(Object.assign({}, process.env), { NODE_ENV: 'production' }),
36
+ }).catch((err) => {
37
+ consola_1.consola.error('Unexpected error installing seed dependencies. Try re-runing with --log-level verbose');
38
+ if (err) {
39
+ consola_1.consola.error(err);
40
+ }
41
+ process.exit(1);
42
+ });
43
+ consola_1.consola.success(`Installed in ${Date.now() - start2}ms`);
44
+ }
45
+ });
46
+ exports.installSeedDeps = installSeedDeps;
47
+ // run seed configure script
48
+ const configureSeedApp = (seedInfo, fetchSeedResult, params, dir, skipOptionalPrompts, isInit) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
49
+ const { configure, prompts, details, defaults, validate } = seedInfo;
50
+ // load persisted answers if available
51
+ const persistedAnswers = (0, seed_meta_1.loadGenxModule)(fetchSeedResult.genxDir, seed_processing_1.PROMPT_DATA_FILE, false);
52
+ // get prompt answers
53
+ const data = yield (0, prompts_1.getData)(persistedAnswers, prompts, details, defaults, validate, params, dir, skipOptionalPrompts, fetchSeedResult);
54
+ consola_1.consola.debug('Loaded seed data', data);
55
+ const utils = {
56
+ writeFileWithData: handlebars_1.renderFile,
57
+ editJSONFile: json_1.editJSONFile,
58
+ replaceObjectKeys: object_1.replaceObjectKeys,
59
+ listAllFiles: fs_1.listAllFiles,
60
+ rename: fs_1.rename,
61
+ };
62
+ // run seed configure script
63
+ yield configure(data, utils).catch((e) => consola_1.consola.error(e));
64
+ // process seed exclusions, render templates, rename files/folders
65
+ (0, seed_processing_1.processOptions)(fetchSeedResult, fetchSeedResult.extractedSeedDir, data, isInit, persistedAnswers);
66
+ // when adding seed, copy result from temp folder to the app root (omitting .genx folder of the seed)
67
+ if (!isInit) {
68
+ yield (0, fs_1.rm)(fetchSeedResult.extractedSeedGenxDir);
69
+ (0, node_fs_1.cpSync)(fetchSeedResult.extractedSeedDir, dir, { recursive: true });
70
+ yield (0, fs_1.rm)(fetchSeedResult.extractedSeedDir);
71
+ }
72
+ });
73
+ exports.configureSeedApp = configureSeedApp;
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.142.1-alpha-2787e5d.0",
4
+ "version": "14.143.1",
5
5
  "license": "SEE LICENSE IN license.txt",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -19,7 +19,9 @@
19
19
  "change-case": "^4.1.2",
20
20
  "consola": "^3.0.2",
21
21
  "defu": "^6.1.2",
22
+ "download-tarball": "2.0.0",
22
23
  "edit-json-file": "^1.7.0",
24
+ "get-npm-tarball-url": "2.1.0",
23
25
  "giget": "1.1.3",
24
26
  "handlebars": "^4.7.7",
25
27
  "inquirer": "^8.2.3",
@@ -27,11 +29,12 @@
27
29
  "pkg-types": "^1.0.2",
28
30
  "pretty-ms": "^7.0.0",
29
31
  "rimraf": "^5.0.0",
32
+ "tmp": "0.2.1",
30
33
  "unparse-args": "^1.2.0"
31
34
  },
32
35
  "devDependencies": {
33
36
  "@esbuild-kit/cjs-loader": "2.4.2",
34
- "@genesislcap/foundation-testing": "14.142.1-alpha-2787e5d.0",
37
+ "@genesislcap/foundation-testing": "14.143.1",
35
38
  "@types/node": "^20.8.7",
36
39
  "tsm": "^2.2.1",
37
40
  "typescript": "^4.5.5",
@@ -45,5 +48,5 @@
45
48
  "publishConfig": {
46
49
  "access": "public"
47
50
  },
48
- "gitHead": "a9af09bf42c255499aa83f98a4e2afc9f904cb48"
51
+ "gitHead": "5301ef68fff841cfb91d8b80ff57fee8e553b71b"
49
52
  }
@@ -0,0 +1,18 @@
1
+ import consola from 'consola';
2
+ import download from 'download-tarball';
3
+ import tmp from 'tmp';
4
+ import { rename } from './fs';
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
+ rename(`${source}`, destination);
18
+ };
@@ -1,4 +1,5 @@
1
1
  export * from './args';
2
+ export * from './archive';
2
3
  export * from './build-context';
3
4
  export * from './child-process';
4
5
  export * from './config';
@@ -11,5 +12,8 @@ export * from './json';
11
12
  export * from './npm';
12
13
  export * from './prompts';
13
14
  export * from './object';
14
- export * from './seed';
15
+ export * from './seed.fetching';
16
+ export * from './seed.meta';
17
+ export * from './seed.processing';
18
+ export * from './seed.setup';
15
19
  export * from './time';