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

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/run.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runCommand = void 0;
4
+ const spawn_stream_1 = require("./spawn-stream");
5
+ async function* runCommand(command, args, options) {
6
+ const { childProcess, stream } = (0, spawn_stream_1.spawnStream)(command, args, { cwd: options?.cwd, splitLines: true, ...options });
7
+ let exitCode = null;
8
+ for await (let event of stream) {
9
+ yield event;
10
+ if (event.exitCode != null) {
11
+ exitCode = event.exitCode;
12
+ }
13
+ }
14
+ if (exitCode != 0) {
15
+ throw new Error(`Command failed with code ${exitCode}`);
16
+ }
17
+ }
18
+ exports.runCommand = runCommand;
19
+ //# sourceMappingURL=run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.js","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":";;;AAAA,iDAA+D;AAGxD,KAAK,SAAS,CAAC,CAAC,UAAU,CAC/B,OAAe,EACf,IAAc,EACd,OAA+B;IAE/B,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,IAAA,0BAAW,EAAC,OAAO,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;IAEjH,IAAI,QAAQ,GAAkB,IAAI,CAAC;IAEnC,IAAI,KAAK,EAAE,IAAI,KAAK,IAAI,MAAM,EAAE;QAC9B,MAAM,KAAK,CAAC;QACZ,IAAI,KAAK,CAAC,QAAQ,IAAI,IAAI,EAAE;YAC1B,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;SAC3B;KACF;IAED,IAAI,QAAQ,IAAI,CAAC,EAAE;QACjB,MAAM,IAAI,KAAK,CAAC,4BAA4B,QAAQ,EAAE,CAAC,CAAC;KACzD;AACH,CAAC;AAnBD,gCAmBC"}
@@ -0,0 +1,15 @@
1
+ /// <reference types="node" />
2
+ import { SpawnOptions } from 'child_process';
3
+ export interface StreamOptions {
4
+ splitLines?: boolean;
5
+ }
6
+ export declare function spawnStream(command: string, args: string[], options: SpawnOptions & StreamOptions): {
7
+ childProcess: import("child_process").ChildProcessWithoutNullStreams;
8
+ stream: AsyncIterable<SpawnStreamEvent>;
9
+ };
10
+ export interface SpawnStreamEvent {
11
+ event: 'stdout' | 'stderr' | 'exit';
12
+ stdout?: string;
13
+ stderr?: string;
14
+ exitCode?: number;
15
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.spawnStream = void 0;
4
+ const child_process_1 = require("child_process");
5
+ const stream_1 = require("stream");
6
+ function spawnStream(command, args, options) {
7
+ const process = (0, child_process_1.spawn)(command, args, {
8
+ ...options,
9
+ stdio: 'pipe'
10
+ });
11
+ return {
12
+ childProcess: process,
13
+ stream: processToStream(process, options)
14
+ };
15
+ }
16
+ exports.spawnStream = spawnStream;
17
+ function processToStream(process, options) {
18
+ const combinedStream = new stream_1.PassThrough({ objectMode: true });
19
+ async function* transform(stream, key) {
20
+ stream.setEncoding('utf-8');
21
+ let iterable = stream;
22
+ if (options.splitLines) {
23
+ iterable = splitLines(iterable);
24
+ }
25
+ for await (const chunk of iterable) {
26
+ yield {
27
+ event: key,
28
+ [key]: chunk
29
+ };
30
+ }
31
+ }
32
+ if (process.stdout) {
33
+ stream_1.Readable.from(transform(process.stdout, 'stdout')).pipe(combinedStream, { end: false });
34
+ }
35
+ if (process.stderr) {
36
+ stream_1.Readable.from(transform(process.stderr, 'stderr')).pipe(combinedStream, { end: false });
37
+ }
38
+ process.on('exit', (code) => {
39
+ combinedStream.write({ exitCode: code }, () => {
40
+ combinedStream.end();
41
+ });
42
+ });
43
+ return combinedStream;
44
+ }
45
+ async function* splitLines(stream) {
46
+ let buffer = '';
47
+ for await (const chunk of stream) {
48
+ buffer += chunk;
49
+ const lines = buffer.split('\n');
50
+ buffer = lines.pop();
51
+ for (let line of lines) {
52
+ yield `${line}\n`;
53
+ }
54
+ }
55
+ if (buffer) {
56
+ yield buffer;
57
+ }
58
+ }
59
+ //# sourceMappingURL=spawn-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spawn-stream.js","sourceRoot":"","sources":["../src/spawn-stream.ts"],"names":[],"mappings":";;;AAAA,iDAAkE;AAClE,mCAA+C;AAM/C,SAAgB,WAAW,CAAC,OAAe,EAAE,IAAc,EAAE,OAAqC;IAChG,MAAM,OAAO,GAAG,IAAA,qBAAK,EAAC,OAAO,EAAE,IAAI,EAAE;QACnC,GAAG,OAAO;QACV,KAAK,EAAE,MAAM;KACd,CAAC,CAAC;IAEH,OAAO;QACL,YAAY,EAAE,OAAO;QACrB,MAAM,EAAE,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC;KAC1C,CAAC;AACJ,CAAC;AAVD,kCAUC;AASD,SAAS,eAAe,CAAC,OAAqB,EAAE,OAAsB;IACpE,MAAM,cAAc,GAAG,IAAI,oBAAW,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;IAE7D,KAAK,SAAS,CAAC,CAAC,SAAS,CAAC,MAAgB,EAAE,GAAwB;QAClE,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAC5B,IAAI,QAAQ,GAA0B,MAAM,CAAC;QAC7C,IAAI,OAAO,CAAC,UAAU,EAAE;YACtB,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;SACjC;QACD,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,QAAQ,EAAE;YAClC,MAAM;gBACJ,KAAK,EAAE,GAAG;gBACV,CAAC,GAAG,CAAC,EAAE,KAAK;aACb,CAAC;SACH;IACH,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,EAAE;QAClB,iBAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;KACzF;IACD,IAAI,OAAO,CAAC,MAAM,EAAE;QAClB,iBAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;KACzF;IAED,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAmB,EAAE,EAAE;QACzC,cAAc,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE;YAC5C,cAAc,CAAC,GAAG,EAAE,CAAC;QACvB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,cAAc,CAAC;AACxB,CAAC;AAED,KAAK,SAAS,CAAC,CAAC,UAAU,CAAC,MAA6B;IACtD,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE;QAChC,MAAM,IAAI,KAAK,CAAC;QAChB,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACjC,MAAM,GAAG,KAAK,CAAC,GAAG,EAAG,CAAC;QACtB,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE;YACtB,MAAM,GAAG,IAAI,IAAI,CAAC;SACnB;KACF;IACD,IAAI,MAAM,EAAE;QACV,MAAM,MAAM,CAAC;KACd;AACH,CAAC"}
package/package.json CHANGED
@@ -1,14 +1,21 @@
1
1
  {
2
2
  "name": "@journeyapps/cloudcode-build-agent",
3
- "version": "0.0.0-dev.55699c3",
4
- "description": "",
3
+ "version": "0.0.0-dev.6666079",
4
+ "description": "Detect CloudCode tasks in a JourneyApps App and build them for installation on AWS Lambda",
5
5
  "main": "./dist/index",
6
6
  "types": "./dist/index",
7
- "license": "MIT",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
8
10
  "bin": {
9
11
  "cloudcode-build-agent": "./bin.js"
10
12
  },
13
+ "files": [
14
+ "bin.js",
15
+ "dist"
16
+ ],
11
17
  "dependencies": {
18
+ "child-process-promise": "^2.2.1",
12
19
  "fs-jetpack": "5.1.0",
13
20
  "lodash": "4.17.21",
14
21
  "node-fetch": "<3",
@@ -17,8 +24,9 @@
17
24
  "yargs": "17.6.2"
18
25
  },
19
26
  "devDependencies": {
27
+ "@types/child-process-promise": "2.2.2",
20
28
  "@types/lodash": "4.14.191",
21
- "@types/node": "16.11.7",
29
+ "@types/node": "14.18.36",
22
30
  "@types/node-fetch": "2.6.2",
23
31
  "@types/semver": "7.3.13",
24
32
  "@types/tar": "6.1.4",
package/dist/errors.d.ts DELETED
@@ -1,8 +0,0 @@
1
- /// <reference types="node" />
2
- import { SpawnSyncReturns } from 'child_process';
3
- export 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 DELETED
@@ -1,21 +0,0 @@
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
@@ -1 +0,0 @@
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/utils.d.ts DELETED
@@ -1,11 +0,0 @@
1
- export declare function downloadAndInstallNode(node_version: string, destination: string): Promise<{
2
- bin_path: string;
3
- node_bin: string;
4
- npm_bin: string;
5
- }>;
6
- export declare function nodePaths(destination: string): {
7
- bin_path: string;
8
- node_bin: string;
9
- npm_bin: string;
10
- };
11
- export declare function downloadAndExtractTarball(url: string, dest: string): Promise<void>;
package/dist/utils.js DELETED
@@ -1,99 +0,0 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.downloadAndExtractTarball = exports.nodePaths = exports.downloadAndInstallNode = void 0;
30
- const node_fetch_1 = __importDefault(require("node-fetch"));
31
- const path = __importStar(require("node:path"));
32
- const fs = __importStar(require("node:fs"));
33
- const os = __importStar(require("node:os"));
34
- const URL = __importStar(require("node:url"));
35
- const tar = __importStar(require("tar"));
36
- /* Basically this, but for different dirs.
37
- curl https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${PLATFORM}64.tar.gz -L | tar -xzC /node-dedicated && \
38
- mv /node-dedicated/node-v${NODE_VERSION}-linux-${PLATFORM}64/bin/node /node-dedicated/node
39
- */
40
- // TODO: feature to find the latest minor and patch for a given major version?
41
- async function downloadAndInstallNode(node_version, destination) {
42
- // eg. https://nodejs.org/dist/v18.14.2/node-v18.14.2-linux-x64.tar.xz
43
- // const PLATFORM = 'x';
44
- // const node_download_url = `https://nodejs.org/dist/v${node_version}/node-v${node_version}-linux-${PLATFORM}64.tar.gz`;
45
- // TODO: this is just for dev for now. Find a better fix.
46
- const ARCH = os.arch();
47
- const PLATFORM = os.platform();
48
- const node_download_url = `https://nodejs.org/dist/v${node_version}/node-v${node_version}-${PLATFORM}-${ARCH}.tar.gz`;
49
- await downloadAndExtractTarball(node_download_url, destination);
50
- // TODO: move binaries into local bin path?
51
- return nodePaths(destination);
52
- }
53
- exports.downloadAndInstallNode = downloadAndInstallNode;
54
- function nodePaths(destination) {
55
- return {
56
- bin_path: path.resolve(destination, 'bin'),
57
- node_bin: path.resolve(destination, 'bin', 'node'),
58
- npm_bin: path.resolve(destination, 'bin', 'npm')
59
- };
60
- }
61
- exports.nodePaths = nodePaths;
62
- async function downloadAndExtractTarball(url, dest) {
63
- const tmpdir = os.tmpdir();
64
- const filename = path.basename(URL.parse(url).pathname);
65
- const base = path.basename(filename, '.tar.gz');
66
- const download = path.join(tmpdir, filename);
67
- console.log(`fetching ${url}`);
68
- const file = fs.createWriteStream(download);
69
- const response = await (0, node_fetch_1.default)(url);
70
- if (!response.ok) {
71
- const errorBody = await response.statusText;
72
- throw new Error(`Failed to download: ${errorBody}`);
73
- }
74
- // FIXME: replace with webstreams?
75
- response.body.pipe(file);
76
- file.on('finish', async () => {
77
- console.log('Extracting...', download);
78
- const comp = fs.createReadStream(download);
79
- tar.extract({
80
- cwd: tmpdir,
81
- file: comp.path,
82
- sync: true
83
- });
84
- const uncomp = path.join(tmpdir, base);
85
- const dist = path.resolve(dest);
86
- // FIXME: dangerous. Add protection or replace.
87
- // if (fs.existsSync(dist)) {
88
- // fs.rmSync(dist, { recursive: true });
89
- // }
90
- if (fs.existsSync(uncomp)) {
91
- console.log(`Moving extracted files from ${uncomp} to ${dist}`);
92
- fs.renameSync(uncomp, dist);
93
- }
94
- // FIXME: this seems to sometimes cause errors
95
- // fs.unlinkSync(file.path);
96
- });
97
- }
98
- exports.downloadAndExtractTarball = downloadAndExtractTarball;
99
- //# sourceMappingURL=utils.js.map
package/dist/utils.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"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"}
package/src/builder.ts DELETED
@@ -1,11 +0,0 @@
1
- import { spawnSync } from 'child_process';
2
- import { detectTasks } from './detect_tasks';
3
-
4
- // Detect tasks in given path and build them.
5
- export async function buildTasks(project_path: string, dest: string, config: any, only?: string) {
6
- const tasks = await detectTasks(project_path, only);
7
-
8
- for (const t of tasks) {
9
- // await t.drink()
10
- }
11
- }
package/src/cli.ts DELETED
@@ -1,60 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import * as yargs from 'yargs';
4
-
5
- import { ProcessError, buildTasks, prepareBuildEnvForTasks } from './';
6
-
7
- const DEFAULT_SRC_PATH = './';
8
- const DEFAULT_OUT_PATH = '';
9
-
10
- yargs
11
- .command(
12
- ['build', '$0'], // $0 means this is the default command
13
- 'build tasks',
14
- (yargs) => {
15
- return yargs
16
- .option('only', { string: true })
17
- .option('path', { default: DEFAULT_SRC_PATH })
18
- .option('out', { default: DEFAULT_OUT_PATH });
19
- },
20
- handled(async (argv) => {
21
- // iterate over task directories and run: 'yarn cloudcode-build'.
22
- // optionally filtered by `argv.only` to build a single task.
23
-
24
- await buildTasks(argv.path, argv.out, argv.only);
25
- })
26
- )
27
- .command(
28
- 'prepare-env',
29
- 'Install node environments and packages for each task',
30
- (yargs) => {
31
- return yargs.option('only', { string: true }).option('path', { default: DEFAULT_SRC_PATH });
32
- },
33
- handled(async (argv) => {
34
- // iterate over task directories:
35
- // ensure required node version for task CC version is installed - What if too old - error?
36
- // run yarn install
37
-
38
- await prepareBuildEnvForTasks(argv.path, argv.only);
39
- })
40
- )
41
- .option('verbose', {
42
- alias: 'v',
43
- default: false
44
- }).argv;
45
-
46
- function handled<T>(fn: (argv: T) => Promise<void>): (argv: T) => Promise<void> {
47
- return async (argv: T) => {
48
- try {
49
- await fn(argv);
50
- } catch (err) {
51
- if (err instanceof ProcessError) {
52
- console.error(err.message);
53
- process.exit(err.status);
54
- } else {
55
- console.error(err.stack);
56
- process.exit(1);
57
- }
58
- }
59
- };
60
- }
package/src/defs.ts DELETED
@@ -1,45 +0,0 @@
1
- // TODO: maybe publish (some of) this from the CC service?
2
- export const SUPPORTED_VERSIONS = [
3
- {
4
- // proposed
5
- version: '1.13.0',
6
- node: '16.19.1',
7
- builder_package: '@journeyapps/cloudcode-build@1.13.0',
8
- builder_script: 'cloudcode-build'
9
- },
10
- {
11
- version: '1.12.0',
12
- node: '16.19.1', // FIXME: maybe the very specific node version here is too brittle?
13
- // builder_package: '@journeyapps/cloudcode-build-legacy@1.12.0'
14
- // DEV HACK:
15
- builder_package: '~/src/journey-cloudcode/packages/cloudcode-build-legacy',
16
- builder_script: 'cloudcode-build-legacy'
17
- },
18
- {
19
- version: '1.11.2',
20
- // node: '14.21.3',
21
- // builder_package: '@journeyapps/cloudcode-build-legacy@1.12.0'
22
- // DEV HACK:
23
- node: '16.19.1', // because local dev on darwin/arm64 and there's no darwin-arm64 builds for node14 available.
24
- builder_package: '~/src/journey-cloudcode/packages/cloudcode-build-legacy',
25
- builder_script: 'cloudcode-build-legacy'
26
- },
27
- {
28
- version: '1.11.1',
29
- // node: '14.21.3',
30
- // builder_package: '@journeyapps/cloudcode-build-legacy@1.12.0'
31
- // DEV HACK:
32
- node: '16.19.1', // because local dev on darwin/arm64 and there's no darwin-arm64 builds for node14 available.
33
- builder_package: '~/src/journey-cloudcode/packages/cloudcode-build-legacy',
34
- builder_script: 'cloudcode-build-legacy'
35
- },
36
- {
37
- version: '1.11.0',
38
- // node: '14.21.3',
39
- // builder_package: '@journeyapps/cloudcode-build-legacy@1.12.0'
40
- // DEV HACK:
41
- node: '16.19.1', // because local dev on darwin/arm64 and there's no darwin-arm64 builds for node14 available.
42
- builder_package: '~/src/journey-cloudcode/packages/cloudcode-build-legacy',
43
- builder_script: 'cloudcode-build-legacy'
44
- }
45
- ];
@@ -1,73 +0,0 @@
1
- import * as fs from 'node:fs';
2
- import * as path from 'node:path';
3
- import * as jetpack from 'fs-jetpack';
4
- import * as semver from 'semver';
5
- import * as defs from './defs';
6
-
7
- // TODO: validations for cloudcode specific keys and structure?
8
- async function readPackage(path: string) {
9
- try {
10
- const content = await fs.promises.readFile(path, { encoding: 'utf-8' });
11
- return JSON.parse(content);
12
- } catch (err) {
13
- console.error(`ERROR: ${err}`);
14
- throw err;
15
- // todo: check for enoent and skip?
16
- // todo: if json error, throw a CC build error?
17
- }
18
- }
19
-
20
- export async function detectTasks(project_path: string, only?: string) {
21
- const package_files = await jetpack.findAsync(path.join(project_path, 'cloudcode'), { matching: '**/package.json' });
22
- const filtered_package_files = package_files.filter((pkg_path) => {
23
- // FIXME: this is kinda clunky.
24
- const pm = /^\/?cloudcode\/([^\/]+)\/package\.json$/.exec(pkg_path);
25
- if (!pm) {
26
- return false;
27
- }
28
- const taskName = pm[1];
29
-
30
- if (only != null && only != taskName) {
31
- // !(only.indexOf(taskName) >= 0) // TODO: support a specific list of tasks to build?
32
- return false;
33
- }
34
- return true;
35
- });
36
-
37
- return Promise.all(
38
- filtered_package_files.map(async (pkg_path) => {
39
- const task_package = await readPackage(pkg_path);
40
-
41
- const task_name = task_package.name; // CAVEAT: the pkg name _must_ match the dir.
42
- const task_version = task_package?.cloudcode?.runtime;
43
-
44
- console.debug(`Detected task version ${task_version}`);
45
-
46
- const matching = defs.SUPPORTED_VERSIONS.find((v) => {
47
- return semver.satisfies(v.version, task_version);
48
- });
49
- if (!matching) {
50
- throw new Error('FIXME: unsupported version');
51
- }
52
-
53
- console.debug(`Matching versions: ${JSON.stringify(matching)}`);
54
-
55
- const running_node_version = process.versions.node;
56
- let required_node_version;
57
- // if (matching?.node && semver.major(matching.node) !== semver.major(running_node_version)) {
58
- if (matching?.node && semver.parse(matching.node) !== semver.parse(running_node_version)) {
59
- console.debug(`Task requires different node version: v${matching.node}`);
60
-
61
- required_node_version = matching.node;
62
- }
63
- return {
64
- pkg_path,
65
- task_name,
66
- task_version,
67
- required_node_version,
68
- builder_package: matching.builder_package,
69
- builder_script: matching.builder_script
70
- };
71
- })
72
- );
73
- }
package/src/errors.ts DELETED
@@ -1,22 +0,0 @@
1
- import { SpawnSyncReturns } from 'child_process';
2
-
3
- export class ProcessError extends Error {
4
- cause?: Error;
5
- status: number;
6
-
7
- constructor(public result: SpawnSyncReturns<string>) {
8
- super(constructMessage(result));
9
-
10
- if (result.error) {
11
- this.cause = result.error;
12
- }
13
- this.status = result.status || 1;
14
- }
15
- }
16
-
17
- function constructMessage(result: SpawnSyncReturns<string>): string {
18
- if (result.error) {
19
- return result.error.message;
20
- }
21
- return `${result.stdout}${result.stderr}`.trim();
22
- }
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './errors';
2
- export * from './builder';
3
- export * from './installer';
package/src/installer.ts DELETED
@@ -1,82 +0,0 @@
1
- import * as fs from 'node:fs';
2
- import * as path from 'node:path';
3
- import * as jetpack from 'fs-jetpack';
4
- import * as semver from 'semver';
5
- import * as utils from './utils';
6
- import { spawnSync } from 'child_process';
7
- import { detectTasks } from './detect_tasks';
8
-
9
- import * as _ from 'lodash';
10
-
11
- export async function prepareBuildEnvForTasks(project_path: string, only?: string) {
12
- const tasks = await detectTasks(project_path, only);
13
-
14
- const required_node_versions = _.compact(tasks.map((t) => t.required_node_version));
15
- const install_node_versions = _.uniq(required_node_versions);
16
-
17
- const tool_paths: Record<string, { bin_path: string; node_bin: string; npm_bin: string }> = {};
18
- for (const required_node_version of install_node_versions) {
19
- // FIXME: maybe a path prefix.
20
- const custom_node_path = path.resolve(`node-${semver.major(required_node_version)}`);
21
-
22
- if (!jetpack.exists(custom_node_path)) {
23
- console.log(`installing to ${custom_node_path}`);
24
- await jetpack.dirAsync(custom_node_path);
25
- await utils.downloadAndInstallNode(required_node_version, custom_node_path);
26
- } else {
27
- console.log(`already installed in ${custom_node_path}`);
28
- }
29
- tool_paths[required_node_version] = utils.nodePaths(custom_node_path);
30
- }
31
- console.log('----');
32
-
33
- for (const task of tasks) {
34
- const node_version = task.required_node_version ?? process.version;
35
- const builder_package = task.builder_package;
36
- const builder_script = task.builder_script;
37
- console.log(`[${task.task_name}] Installing builder script "${builder_package}" for node ${node_version}`);
38
- const { bin_path, node_bin, npm_bin } = tool_paths[node_version];
39
- const builder_bin = path.resolve(bin_path, builder_script);
40
-
41
- // 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?
42
- const spawnResult = spawnSync(node_bin, [npm_bin, '--global', 'install', builder_package], { cwd: project_path });
43
- if (spawnResult.status == 0 && jetpack.exists(builder_bin)) {
44
- // DEV HACK: this needs to move to the build thingie.
45
-
46
- const builder_args: string[] = [];
47
- // --src ~/src/cool-app-bro-master --out ~/src/dist --task echo --appId 'appid' --env 'testing' --backendId 'backendid' --backendUrl 'http://run.journeyapps.test'
48
- builder_args.push(builder_bin);
49
- // // builder_args.push('--version')
50
- builder_args.push('--src', './');
51
- builder_args.push(`--out`, `./dist/${task.task_name}`);
52
- builder_args.push(`--task`, `${task.task_name}`);
53
- builder_args.push(
54
- `--appId`,
55
- 'appid',
56
- `--env`,
57
- 'testing',
58
- `--backendId`,
59
- 'backendid',
60
- `--backendUrl`,
61
- 'http://run.journeyapps.test'
62
- );
63
-
64
- console.log(`[${task.task_name}] Trying: ${node_bin} ${builder_args.join(' ')}`);
65
-
66
- const builderSpawnResult = spawnSync(node_bin, builder_args, { cwd: project_path });
67
-
68
- if (builderSpawnResult.status !== 0) {
69
- console.log(`[${task.task_name}] FAILED TO RUN BUILDER SCRIPT`);
70
- console.log(`[${task.task_name}] OUTPUT: ${builderSpawnResult.stdout}`);
71
- console.log(`[${task.task_name}] ERROR: ${builderSpawnResult.stderr}`);
72
- } else {
73
- console.log(`[${task.task_name}] SCRIPT SUCCESS?`);
74
- console.log(`[${task.task_name}] OUTPUT: ${builderSpawnResult.stdout}`);
75
- console.log(`[${task.task_name}] ERROR: ${builderSpawnResult.stderr}`);
76
- }
77
- console.log('----');
78
- } else {
79
- console.log(`[${task.task_name}] failed to install ${builder_package}`);
80
- }
81
- }
82
- }