@journeyapps/cloudcode-build-agent 0.0.0-dev.3868b04 → 0.0.0-dev.55699c3

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.
package/dist/builder.d.ts CHANGED
@@ -1,21 +1 @@
1
- import { DetectedTask } from './detect_tasks';
2
- export type GeneralTaskConfig = {
3
- app_id: string;
4
- env: string;
5
- backend_id: string;
6
- backend_url: string;
7
- };
8
- export type BuildOptions = {
9
- only?: string;
10
- custom_node_installation_path?: string;
11
- };
12
- type ToolPaths = {
13
- bin_path: string;
14
- node_bin: string;
15
- npm_bin: string;
16
- };
17
- export declare function buildTasks(project_path: string, dest: string, config: GeneralTaskConfig, options?: BuildOptions): Promise<void>;
18
- export declare function buildTask(task: DetectedTask, project_path: string, dest: string, config: GeneralTaskConfig, node_context: {
19
- node_version: string;
20
- } & ToolPaths): Promise<void>;
21
- export {};
1
+ export declare function buildTasks(project_path: string, dest: string, config: any, only?: string): Promise<void>;
package/dist/builder.js CHANGED
@@ -1,101 +1,13 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.buildTask = exports.buildTasks = void 0;
27
- const path = __importStar(require("node:path"));
28
- const jetpack = __importStar(require("fs-jetpack"));
29
- const semver = __importStar(require("semver"));
30
- const installer_1 = require("./installer");
3
+ exports.buildTasks = void 0;
31
4
  const detect_tasks_1 = require("./detect_tasks");
32
- const run_1 = require("./run");
33
- async function buildTasks(project_path, dest, config, options) {
34
- const tasks = await (0, detect_tasks_1.detectTasks)(project_path, options?.only);
35
- // Use the version of nodejs that's running this script as the default.
36
- const default_tool_paths = {
37
- bin_path: path.dirname(process.execPath),
38
- node_bin: process.execPath,
39
- npm_bin: path.join(path.dirname(process.execPath), 'npm')
40
- };
41
- for (const task of tasks) {
42
- let custom_tool_paths;
43
- if (task.required_node_version) {
44
- // FIXME: when defaulting to project_path, the custom node installation is copied into the builder's workdir as well.
45
- const custom_node_installation_path = options?.custom_node_installation_path ?? project_path;
46
- const custom_node_path = path.resolve(custom_node_installation_path, `node-${semver.major(task.required_node_version)}`);
47
- custom_tool_paths = await (0, installer_1.ensureCustomNodeVersion)(task.required_node_version, custom_node_path);
48
- }
49
- const node_version = task.required_node_version ?? process.version;
50
- await buildTask(task, project_path, dest, config, {
51
- node_version,
52
- ...(custom_tool_paths ?? default_tool_paths)
53
- });
5
+ // Detect tasks in given path and build them.
6
+ async function buildTasks(project_path, dest, config, only) {
7
+ const tasks = await (0, detect_tasks_1.detectTasks)(project_path, only);
8
+ for (const t of tasks) {
9
+ // await t.drink()
54
10
  }
55
11
  }
56
12
  exports.buildTasks = buildTasks;
57
- async function buildTask(task, project_path, dest, config, node_context) {
58
- const builder_package = task.builder_package;
59
- const builder_script = task.builder_script;
60
- const { bin_path, node_bin, npm_bin } = node_context;
61
- const builder_bin = path.resolve(bin_path, builder_script);
62
- if (!jetpack.exists(node_bin)) {
63
- throw new Error(`Node binary not found: ${node_bin}`);
64
- }
65
- console.debug(`[${task.task_name}] Installing builder script "${builder_package}" for node ${node_context.node_version}`);
66
- const stream1 = (0, run_1.runCommand)(node_bin, [npm_bin, '--global', 'install', builder_package], {
67
- cwd: project_path,
68
- env: process.env
69
- });
70
- for await (let event of stream1) {
71
- const log = event.stdout ?? event.stderr;
72
- if (log) {
73
- console.log(`[${task.task_name} - install]`, log.trimRight());
74
- }
75
- }
76
- if (!jetpack.exists(builder_bin)) {
77
- console.error(`[${task.task_name}] ${builder_bin} not found`);
78
- throw new Error(`Builder script not found for task ${task.task_name}`);
79
- }
80
- const builder_args = [];
81
- builder_args.push(builder_bin);
82
- builder_args.push('--src', project_path);
83
- builder_args.push(`--out`, path.join(dest, task.task_name));
84
- builder_args.push(`--zip`, path.join(dest, `${task.task_name}.zip`));
85
- builder_args.push(`--task`, `${task.task_name}`);
86
- builder_args.push(`--appId`, config.app_id);
87
- builder_args.push(`--env`, config.env);
88
- builder_args.push(`--backendId`, config.backend_id);
89
- builder_args.push(`--backendUrl`, config.backend_url);
90
- builder_args.push(`--runInstallScripts`, 'true');
91
- console.debug(`[${task.task_name}] Trying: ${node_bin} ${builder_args.join(' ')}`);
92
- const stream2 = (0, run_1.runCommand)(node_bin, builder_args, { cwd: project_path, env: process.env });
93
- for await (let event of stream2) {
94
- const log = event.stdout ?? event.stderr;
95
- if (log) {
96
- console.log(`[${task.task_name} - build]`, log.trimRight());
97
- }
98
- }
99
- }
100
- exports.buildTask = buildTask;
101
13
  //# sourceMappingURL=builder.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"builder.js","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAkC;AAClC,oDAAsC;AACtC,+CAAiC;AAEjC,2CAAsD;AACtD,iDAA2D;AAC3D,+BAAmC;AAkB5B,KAAK,UAAU,UAAU,CAC9B,YAAoB,EACpB,IAAY,EACZ,MAAyB,EACzB,OAAsB;IAEtB,MAAM,KAAK,GAAG,MA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"version":3,"file":"builder.js","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":";;;AACA,iDAA6C;AAE7C,6CAA6C;AACtC,KAAK,UAAU,UAAU,CAAC,YAAoB,EAAE,IAAY,EAAE,MAAW,EAAE,IAAa;IAC7F,MAAM,KAAK,GAAG,MAAM,IAAA,0BAAW,EAAC,YAAY,EAAE,IAAI,CAAC,CAAC;IAEpD,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE;QACrB,kBAAkB;KACnB;AACH,CAAC;AAND,gCAMC"}
package/dist/cli.js CHANGED
@@ -27,32 +27,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
27
27
  const yargs = __importStar(require("yargs"));
28
28
  const _1 = require("./");
29
29
  const DEFAULT_SRC_PATH = './';
30
- const DEFAULT_OUT_PATH = './dist/cloudcode';
31
- const DEFAULT_TMP_PATH = '/tmp/cloudcode-build-agent/node';
30
+ const DEFAULT_OUT_PATH = '';
32
31
  yargs
33
32
  .command(['build', '$0'], // $0 means this is the default command
34
33
  'build tasks', (yargs) => {
35
- return (yargs
34
+ return yargs
36
35
  .option('only', { string: true })
37
36
  .option('path', { default: DEFAULT_SRC_PATH })
38
- .option('out', { default: DEFAULT_OUT_PATH })
39
- .option('node_work_dir', { default: DEFAULT_TMP_PATH })
40
- // TODO: investigate yargs.config() for reading task config blob from a file. But how to ensure required args?
41
- .option('appId', { string: true, demandOption: true, describe: "CloudCode's reference id" })
42
- .option('env', { string: true, demandOption: true })
43
- .option('backendId', { string: true, demandOption: true })
44
- .option('backendUrl', { string: true, demandOption: true }));
37
+ .option('out', { default: DEFAULT_OUT_PATH });
45
38
  }, handled(async (argv) => {
46
- const config = {
47
- app_id: argv.appId,
48
- env: argv.env,
49
- backend_id: argv.backendId,
50
- backend_url: argv.backendUrl
51
- };
52
- await (0, _1.buildTasks)(argv.path, argv.out, config, {
53
- only: argv.only,
54
- custom_node_installation_path: argv.node_work_dir
55
- });
39
+ // iterate over task directories and run: 'yarn cloudcode-build'.
40
+ // optionally filtered by `argv.only` to build a single task.
41
+ await (0, _1.buildTasks)(argv.path, argv.out, argv.only);
42
+ }))
43
+ .command('prepare-env', 'Install node environments and packages for each task', (yargs) => {
44
+ return yargs.option('only', { string: true }).option('path', { default: DEFAULT_SRC_PATH });
45
+ }, handled(async (argv) => {
46
+ // iterate over task directories:
47
+ // ensure required node version for task CC version is installed - What if too old - error?
48
+ // run yarn install
49
+ await (0, _1.prepareBuildEnvForTasks)(argv.path, argv.only);
56
50
  }))
57
51
  .option('verbose', {
58
52
  alias: 'v',
@@ -64,8 +58,14 @@ function handled(fn) {
64
58
  await fn(argv);
65
59
  }
66
60
  catch (err) {
67
- console.error(err.stack);
68
- process.exit(1);
61
+ if (err instanceof _1.ProcessError) {
62
+ console.error(err.message);
63
+ process.exit(err.status);
64
+ }
65
+ else {
66
+ console.error(err.stack);
67
+ process.exit(1);
68
+ }
69
69
  }
70
70
  };
71
71
  }
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,6CAA+B;AAE/B,yBAAgC;AAEhC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAC9B,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAC5C,MAAM,gBAAgB,GAAG,iCAAiC,CAAC;AAE3D,KAAK;KACF,OAAO,CACN,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,uCAAuC;AACxD,aAAa,EACb,CAAC,KAAK,EAAE,EAAE;IACR,OAAO,CACL,KAAK;SACF,MAAM,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;SAChC,MAAM,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC;SAC7C,MAAM,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC;SAC5C,MAAM,CAAC,eAAe,EAAE,E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,IAAI,CAAC,CAAC;AACtD,CAAC,CAAC,CACH;KACA,MAAM,CAAC,SAAS,EAAE;IACjB,KAAK,EAAE,GAAG;IACV,OAAO,EAAE,KAAK;CACf,CAAC,CAAC,IAAI,CAAC;AAEV,SAAS,OAAO,CAAI,EAA8B;IAChD,OAAO,KAAK,EAAE,IAAO,EAAE,EAAE;QACvB,IAAI;YACF,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC;SAChB;QAAC,OAAO,GAAG,EAAE;YACZ,IAAI,GAAG,YAAY,eAAY,EAAE;gBAC/B,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;gBAC3B,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;aAC1B;iBAAM;gBACL,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBACzB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACjB;SACF;IACH,CAAC,CAAC;AACJ,CAAC"}
package/dist/defs.js CHANGED
@@ -3,35 +3,46 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SUPPORTED_VERSIONS = void 0;
4
4
  // TODO: maybe publish (some of) this from the CC service?
5
5
  exports.SUPPORTED_VERSIONS = [
6
- // {
7
- // // proposed
8
- // version: '1.13.0',
9
- // node: '16.19.1',
10
- // builder_package: '@journeyapps/cloudcode-build@1.13.0',
11
- // builder_script: 'cloudcode-build'
12
- // },
6
+ {
7
+ // proposed
8
+ version: '1.13.0',
9
+ node: '16.19.1',
10
+ builder_package: '@journeyapps/cloudcode-build@1.13.0',
11
+ builder_script: 'cloudcode-build'
12
+ },
13
13
  {
14
14
  version: '1.12.0',
15
15
  node: '16.19.1',
16
- builder_package: '@journeyapps/cloudcode-build-legacy@1.12.0',
16
+ // builder_package: '@journeyapps/cloudcode-build-legacy@1.12.0'
17
+ // DEV HACK:
18
+ builder_package: '~/src/journey-cloudcode/packages/cloudcode-build-legacy',
17
19
  builder_script: 'cloudcode-build-legacy'
18
20
  },
19
21
  {
20
22
  version: '1.11.2',
21
- node: '14.21.3',
22
- builder_package: '@journeyapps/cloudcode-build-legacy@1.12.0',
23
+ // node: '14.21.3',
24
+ // builder_package: '@journeyapps/cloudcode-build-legacy@1.12.0'
25
+ // DEV HACK:
26
+ node: '16.19.1',
27
+ builder_package: '~/src/journey-cloudcode/packages/cloudcode-build-legacy',
23
28
  builder_script: 'cloudcode-build-legacy'
24
29
  },
25
30
  {
26
31
  version: '1.11.1',
27
- node: '14.21.3',
28
- builder_package: '@journeyapps/cloudcode-build-legacy@1.12.0',
32
+ // node: '14.21.3',
33
+ // builder_package: '@journeyapps/cloudcode-build-legacy@1.12.0'
34
+ // DEV HACK:
35
+ node: '16.19.1',
36
+ builder_package: '~/src/journey-cloudcode/packages/cloudcode-build-legacy',
29
37
  builder_script: 'cloudcode-build-legacy'
30
38
  },
31
39
  {
32
40
  version: '1.11.0',
33
- node: '14.21.3',
34
- builder_package: '@journeyapps/cloudcode-build-legacy@1.12.0',
41
+ // node: '14.21.3',
42
+ // builder_package: '@journeyapps/cloudcode-build-legacy@1.12.0'
43
+ // DEV HACK:
44
+ node: '16.19.1',
45
+ builder_package: '~/src/journey-cloudcode/packages/cloudcode-build-legacy',
35
46
  builder_script: 'cloudcode-build-legacy'
36
47
  }
37
48
  ];
package/dist/defs.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"defs.js","sourceRoot":"","sources":["../src/defs.ts"],"names":[],"mappings":";;;AAAA,0DAA0D;AAC7C,QAAA,kBAAkB,GAAG;IAChC,IAAI;IACJ,gBAAgB;IAChB,uBAAuB;IACvB,qBAAqB;IACrB,4DAA4D;IAC5D,sCAAsC;IACtC,KAAK;IACL;QACE,OAAO,EAAE,QAAQ;QACjB,IAAI,EAAE,SAAS;QACf,eAAe,EAAE,4CAA4C;QAC7D,cAAc,EAAE,wBAAwB;KACzC;IACD;QACE,OAAO,EAAE,QAAQ;QACjB,IAAI,EAAE,SAAS;QACf,eAAe,EAAE,4CAA4C;QAC7D,cAAc,EAAE,wBAAwB;KACzC;IACD;QACE,OAAO,EAAE,QAAQ;QACjB,IAAI,EAAE,SAAS;QACf,eAAe,EAAE,4CAA4C;QAC7D,cAAc,EAAE,wBAAwB;KACzC;IACD;QACE,OAAO,EAAE,QAAQ;QACjB,IAAI,EAAE,SAAS;QACf,eAAe,EAAE,4CAA4C;QAC7D,cAAc,EAAE,wBAAwB;KACzC;CACF,CAAC"}
1
+ {"version":3,"file":"defs.js","sourceRoot":"","sources":["../src/defs.ts"],"names":[],"mappings":";;;AAAA,0DAA0D;AAC7C,QAAA,kBAAkB,GAAG;IAChC;QACE,WAAW;QACX,OAAO,EAAE,QAAQ;QACjB,IAAI,EAAE,SAAS;QACf,eAAe,EAAE,qCAAqC;QACtD,cAAc,EAAE,iBAAiB;KAClC;IACD;QACE,OAAO,EAAE,QAAQ;QACjB,IAAI,EAAE,SAAS;QACf,gEAAgE;QAChE,YAAY;QACZ,eAAe,EAAE,yDAAyD;QAC1E,cAAc,EAAE,wBAAwB;KACzC;IACD;QACE,OAAO,EAAE,QAAQ;QACjB,mBAAmB;QACnB,gEAAgE;QAChE,YAAY;QACZ,IAAI,EAAE,SAAS;QACf,eAAe,EAAE,yDAAyD;QAC1E,cAAc,EAAE,wBAAwB;KACzC;IACD;QACE,OAAO,EAAE,QAAQ;QACjB,mBAAmB;QACnB,gEAAgE;QAChE,YAAY;QACZ,IAAI,EAAE,SAAS;QACf,eAAe,EAAE,yDAAyD;QAC1E,cAAc,EAAE,wBAAwB;KACzC;IACD;QACE,OAAO,EAAE,QAAQ;QACjB,mBAAmB;QACnB,gEAAgE;QAChE,YAAY;QACZ,IAAI,EAAE,SAAS;QACf,eAAe,EAAE,yDAAyD;QAC1E,cAAc,EAAE,wBAAwB;KACzC;CACF,CAAC"}
@@ -1,9 +1,8 @@
1
- export type DetectedTask = {
1
+ export declare function detectTasks(project_path: string, only?: string): Promise<{
2
2
  pkg_path: string;
3
- task_name: string;
4
- task_version: string;
5
- required_node_version?: string;
3
+ task_name: any;
4
+ task_version: any;
5
+ required_node_version: string | undefined;
6
6
  builder_package: string;
7
7
  builder_script: string;
8
- };
9
- export declare function detectTasks(project_path: string, only?: string): Promise<DetectedTask[]>;
8
+ }[]>;
@@ -29,6 +29,7 @@ const path = __importStar(require("node:path"));
29
29
  const jetpack = __importStar(require("fs-jetpack"));
30
30
  const semver = __importStar(require("semver"));
31
31
  const defs = __importStar(require("./defs"));
32
+ // TODO: validations for cloudcode specific keys and structure?
32
33
  async function readPackage(path) {
33
34
  try {
34
35
  const content = await fs.promises.readFile(path, { encoding: 'utf-8' });
@@ -60,7 +61,6 @@ async function detectTasks(project_path, only) {
60
61
  const task_package = await readPackage(pkg_path);
61
62
  const task_name = task_package.name; // CAVEAT: the pkg name _must_ match the dir.
62
63
  const task_version = task_package?.cloudcode?.runtime;
63
- // FIXME: Do we want to filter out disabled tasks from the build process?
64
64
  console.debug(`Detected task version ${task_version}`);
65
65
  const matching = defs.SUPPORTED_VERSIONS.find((v) => {
66
66
  return semver.satisfies(v.version, task_version);
@@ -71,8 +71,9 @@ async function detectTasks(project_path, only) {
71
71
  console.debug(`Matching versions: ${JSON.stringify(matching)}`);
72
72
  const running_node_version = process.versions.node;
73
73
  let required_node_version;
74
- if (matching?.node && semver.major(matching.node) !== semver.major(running_node_version)) {
75
- console.debug(`Task requires different node version: v${matching.node}. Running: ${running_node_version}`);
74
+ // if (matching?.node && semver.major(matching.node) !== semver.major(running_node_version)) {
75
+ if (matching?.node && semver.parse(matching.node) !== semver.parse(running_node_version)) {
76
+ console.debug(`Task requires different node version: v${matching.node}`);
76
77
  required_node_version = matching.node;
77
78
  }
78
79
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"detect_tasks.js","sourceRoot":"","sources":["../src/detect_tasks.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA8B;AAC9B,gDAAkC;AAClC,oDAAs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declare class ProcessError extends Error {
4
+ result: SpawnSyncReturns<string>;
5
+ cause?: Error;
6
+ status: number;
7
+ constructor(result: SpawnSyncReturns<string>);
8
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProcessError = void 0;
4
+ class ProcessError extends Error {
5
+ constructor(result) {
6
+ super(constructMessage(result));
7
+ this.result = result;
8
+ if (result.error) {
9
+ this.cause = result.error;
10
+ }
11
+ this.status = result.status || 1;
12
+ }
13
+ }
14
+ exports.ProcessError = ProcessError;
15
+ function constructMessage(result) {
16
+ if (result.error) {
17
+ return result.error.message;
18
+ }
19
+ return `${result.stdout}${result.stderr}`.trim();
20
+ }
21
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAEA,MAAa,YAAa,SAAQ,KAAK;IAIrC,YAAmB,MAAgC;QACjD,KAAK,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC;QADf,WAAM,GAAN,MAAM,CAA0B;QAGjD,IAAI,MAAM,CAAC,KAAK,EAAE;YAChB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;SAC3B;QACD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC;IACnC,CAAC;CACF;AAZD,oCAYC;AAED,SAAS,gBAAgB,CAAC,MAAgC;IACxD,IAAI,MAAM,CAAC,KAAK,EAAE;QAChB,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC;KAC7B;IACD,OAAO,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC;AACnD,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1 +1,3 @@
1
+ export * from './errors';
1
2
  export * from './builder';
3
+ export * from './installer';
package/dist/index.js CHANGED
@@ -14,5 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./errors"), exports);
17
18
  __exportStar(require("./builder"), exports);
19
+ __exportStar(require("./installer"), exports);
18
20
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,4CAA0B;AAC1B,8CAA4B"}
@@ -1,16 +1 @@
1
- export declare function ensureCustomNodeVersion(node_version: string, install_path: string): Promise<{
2
- bin_path: string;
3
- node_bin: string;
4
- npm_bin: string;
5
- }>;
6
- export declare function downloadAndInstallNode(node_version: string, destination: string): Promise<{
7
- bin_path: string;
8
- node_bin: string;
9
- npm_bin: string;
10
- }>;
11
- export declare function nodePaths(destination: string): {
12
- bin_path: string;
13
- node_bin: string;
14
- npm_bin: string;
15
- };
16
- export declare function downloadAndExtractTarball(url: string, dest: string): Promise<void>;
1
+ export declare function prepareBuildEnvForTasks(project_path: string, only?: string): Promise<void>;
package/dist/installer.js CHANGED
@@ -22,117 +22,71 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
25
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.downloadAndExtractTarball = exports.nodePaths = exports.downloadAndInstallNode = exports.ensureCustomNodeVersion = void 0;
30
- const jetpack = __importStar(require("fs-jetpack"));
26
+ exports.prepareBuildEnvForTasks = void 0;
31
27
  const path = __importStar(require("node:path"));
32
- const URL = __importStar(require("node:url"));
33
- const node_fetch_1 = __importDefault(require("node-fetch"));
34
- const fs = __importStar(require("node:fs"));
35
- const os = __importStar(require("node:os"));
36
- const tar = __importStar(require("tar"));
37
- async function ensureCustomNodeVersion(node_version, install_path) {
38
- if (!jetpack.exists(path.join(install_path, 'bin/node'))) {
39
- console.debug(`[node ${node_version}] Installing to ${install_path}`);
40
- await jetpack.dirAsync(install_path);
41
- await downloadAndInstallNode(node_version, install_path);
42
- }
43
- else {
44
- console.debug(`[node ${node_version}] Already installed in ${install_path}`);
45
- }
46
- return nodePaths(install_path);
47
- }
48
- exports.ensureCustomNodeVersion = ensureCustomNodeVersion;
49
- /* Basically this, but for different dirs.
50
- curl https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${PLATFORM}64.tar.gz -L | tar -xzC /node-dedicated && \
51
- mv /node-dedicated/node-v${NODE_VERSION}-linux-${PLATFORM}64/bin/node /node-dedicated/node
52
- */
53
- // TODO: feature to find the latest minor and patch for a given major version?
54
- async function downloadAndInstallNode(node_version, destination) {
55
- // eg. https://nodejs.org/dist/v18.14.2/node-v18.14.2-linux-x64.tar.xz
56
- const ARCH = os.arch();
57
- const PLATFORM = os.platform();
58
- const node_download_url = `https://nodejs.org/dist/v${node_version}/node-v${node_version}-${PLATFORM}-${ARCH}.tar.gz`;
59
- await downloadAndExtractTarball(node_download_url, destination);
60
- return nodePaths(destination);
61
- }
62
- exports.downloadAndInstallNode = downloadAndInstallNode;
63
- function nodePaths(destination) {
64
- return {
65
- bin_path: path.resolve(destination, 'bin'),
66
- node_bin: path.resolve(destination, 'bin', 'node'),
67
- npm_bin: path.resolve(destination, 'bin', 'npm')
68
- };
69
- }
70
- exports.nodePaths = nodePaths;
71
- async function downloadAndExtractTarball(url, dest) {
72
- const tmpdir = os.tmpdir();
73
- const filename = path.basename(URL.parse(url).pathname);
74
- const base = path.basename(filename, '.tar.gz');
75
- const download = path.join(tmpdir, filename);
76
- if (fs.existsSync(download)) {
77
- console.debug(`deleting old ${download}`);
78
- fs.unlinkSync(download);
79
- }
80
- await new Promise(async (resolve, reject) => {
81
- console.log(`fetching ${url} into ${download}`);
82
- const response = await (0, node_fetch_1.default)(url);
83
- if (!response.ok) {
84
- const errorBody = await response.statusText;
85
- throw new Error(`Failed to download: ${errorBody}`);
28
+ const jetpack = __importStar(require("fs-jetpack"));
29
+ const semver = __importStar(require("semver"));
30
+ const utils = __importStar(require("./utils"));
31
+ const child_process_1 = require("child_process");
32
+ const detect_tasks_1 = require("./detect_tasks");
33
+ const _ = __importStar(require("lodash"));
34
+ async function prepareBuildEnvForTasks(project_path, only) {
35
+ const tasks = await (0, detect_tasks_1.detectTasks)(project_path, only);
36
+ const required_node_versions = _.compact(tasks.map((t) => t.required_node_version));
37
+ const install_node_versions = _.uniq(required_node_versions);
38
+ const tool_paths = {};
39
+ for (const required_node_version of install_node_versions) {
40
+ // FIXME: maybe a path prefix.
41
+ const custom_node_path = path.resolve(`node-${semver.major(required_node_version)}`);
42
+ if (!jetpack.exists(custom_node_path)) {
43
+ console.log(`installing to ${custom_node_path}`);
44
+ await jetpack.dirAsync(custom_node_path);
45
+ await utils.downloadAndInstallNode(required_node_version, custom_node_path);
86
46
  }
87
- const file = fs.createWriteStream(download); // Sink the download stream into a file, so it can be extracted.
88
- response.body.pipe(file);
89
- file.on('finish', async () => {
90
- try {
91
- console.debug('Extracting...', download);
92
- tar.extract({
93
- cwd: tmpdir,
94
- file: download,
95
- sync: true
96
- });
97
- const uncomp = path.join(tmpdir, base);
98
- const dist = path.resolve(dest);
99
- // FIXME: dangerous. Add protection or replace.
100
- // if (fs.existsSync(dist)) {
101
- // fs.rmSync(dist, { recursive: true });
102
- // }
103
- if (fs.existsSync(uncomp)) {
104
- console.debug(`Moving extracted files from ${uncomp} to ${dist}`);
105
- fs.renameSync(uncomp, dist);
106
- }
107
- else {
108
- console.debug(`Can't find extract dir ${uncomp}`);
109
- }
110
- /*
111
- FIXME: this seems to sometimes cause errors: eg.
112
- ```
113
- node:events:505
114
- throw er; // Unhandled 'error' event
115
- ^
116
-
117
- Error: ENOENT: no such file or directory, open '/var/folders/kc/h6m4zpmd23v13s63mygvkslm0000gn/T/node-v16.19.1-darwin-arm64.tar.gz'
118
- Emitted 'error' event on ReadStream instance at:
119
- at emitErrorNT (node:internal/streams/destroy:157:8)
120
- at emitErrorCloseNT (node:internal/streams/destroy:122:3)
121
- at processTicksAndRejections (node:internal/process/task_queues:83:21) {
122
- errno: -2,
123
- code: 'ENOENT',
124
- syscall: 'open',
125
- path: '/var/folders/kc/h6m4zpmd23v13s63mygvkslm0000gn/T/node-v16.19.1-darwin-arm64.tar.gz'
126
- ```
127
- */
128
- // fs.unlinkSync(file.path);
129
- resolve(null);
47
+ else {
48
+ console.log(`already installed in ${custom_node_path}`);
49
+ }
50
+ tool_paths[required_node_version] = utils.nodePaths(custom_node_path);
51
+ }
52
+ console.log('----');
53
+ for (const task of tasks) {
54
+ const node_version = task.required_node_version ?? process.version;
55
+ const builder_package = task.builder_package;
56
+ const builder_script = task.builder_script;
57
+ console.log(`[${task.task_name}] Installing builder script "${builder_package}" for node ${node_version}`);
58
+ const { bin_path, node_bin, npm_bin } = tool_paths[node_version];
59
+ const builder_bin = path.resolve(bin_path, builder_script);
60
+ // TODO: This may need to be replaced with the something like the spawn-stream stuff in build-agent? OR what to do with the stdout/stderr and errorhandling?
61
+ const spawnResult = (0, child_process_1.spawnSync)(node_bin, [npm_bin, '--global', 'install', builder_package], { cwd: project_path });
62
+ if (spawnResult.status == 0 && jetpack.exists(builder_bin)) {
63
+ // DEV HACK: this needs to move to the build thingie.
64
+ const builder_args = [];
65
+ // --src ~/src/cool-app-bro-master --out ~/src/dist --task echo --appId 'appid' --env 'testing' --backendId 'backendid' --backendUrl 'http://run.journeyapps.test'
66
+ builder_args.push(builder_bin);
67
+ // // builder_args.push('--version')
68
+ builder_args.push('--src', './');
69
+ builder_args.push(`--out`, `./dist/${task.task_name}`);
70
+ builder_args.push(`--task`, `${task.task_name}`);
71
+ builder_args.push(`--appId`, 'appid', `--env`, 'testing', `--backendId`, 'backendid', `--backendUrl`, 'http://run.journeyapps.test');
72
+ console.log(`[${task.task_name}] Trying: ${node_bin} ${builder_args.join(' ')}`);
73
+ const builderSpawnResult = (0, child_process_1.spawnSync)(node_bin, builder_args, { cwd: project_path });
74
+ if (builderSpawnResult.status !== 0) {
75
+ console.log(`[${task.task_name}] FAILED TO RUN BUILDER SCRIPT`);
76
+ console.log(`[${task.task_name}] OUTPUT: ${builderSpawnResult.stdout}`);
77
+ console.log(`[${task.task_name}] ERROR: ${builderSpawnResult.stderr}`);
130
78
  }
131
- catch (err) {
132
- reject(err);
79
+ else {
80
+ console.log(`[${task.task_name}] SCRIPT SUCCESS?`);
81
+ console.log(`[${task.task_name}] OUTPUT: ${builderSpawnResult.stdout}`);
82
+ console.log(`[${task.task_name}] ERROR: ${builderSpawnResult.stderr}`);
133
83
  }
134
- });
135
- });
84
+ console.log('----');
85
+ }
86
+ else {
87
+ console.log(`[${task.task_name}] failed to install ${builder_package}`);
88
+ }
89
+ }
136
90
  }
137
- exports.downloadAndExtractTarball = downloadAndExtractTarball;
91
+ exports.prepareBuildEnvForTasks = prepareBuildEnvForTasks;
138
92
  //# sourceMappingURL=installer.js.map