@journeyapps/cloudcode-build-agent 0.0.0-dev.90a9f01 → 0.0.0-dev.9117f43

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/installer.js CHANGED
@@ -22,84 +22,113 @@ 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
+ };
25
28
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.prepareBuildEnvForTasks = void 0;
27
- const fs = __importStar(require("node:fs"));
28
- const path = __importStar(require("node:path"));
29
+ exports.ensureCustomNodeVersion = ensureCustomNodeVersion;
30
+ exports.downloadAndInstallNode = downloadAndInstallNode;
31
+ exports.nodePaths = nodePaths;
32
+ exports.downloadAndExtractTarball = downloadAndExtractTarball;
29
33
  const jetpack = __importStar(require("fs-jetpack"));
30
- const semver = __importStar(require("semver"));
31
- const utils = __importStar(require("./utils"));
32
- const SUPPORTED_VERSIONS = [
33
- {
34
- version: '1.12.0',
35
- node: '16.19.1' // FIXME: this is maybe brittle?
36
- },
37
- {
38
- version: '1.11.2',
39
- node: '14.21.3'
40
- },
41
- {
42
- version: '1.11.1',
43
- node: '14.21.3'
44
- },
45
- {
46
- version: '1.11.0',
47
- node: '14.21.3'
34
+ const path = __importStar(require("node:path"));
35
+ const URL = __importStar(require("node:url"));
36
+ const node_fetch_1 = __importDefault(require("node-fetch"));
37
+ const fs = __importStar(require("node:fs"));
38
+ const os = __importStar(require("node:os"));
39
+ const tar = __importStar(require("tar"));
40
+ async function ensureCustomNodeVersion(node_version, install_path) {
41
+ if (!jetpack.exists(path.join(install_path, 'bin/node'))) {
42
+ console.debug(`[node ${node_version}] Installing to ${install_path}`);
43
+ await jetpack.dirAsync(install_path);
44
+ await downloadAndInstallNode(node_version, install_path);
48
45
  }
49
- ];
50
- async function prepareBuildEnvForTasks(project_path, only) {
51
- const package_files = await jetpack.findAsync(path.join(project_path, 'cloudcode'), { matching: '**/package.json' });
52
- const filtered_package_files = package_files.filter((pkg_path) => {
53
- // FIXME: this is kinda clunky.
54
- const pm = /^\/?cloudcode\/([^\/]+)\/package\.json$/.exec(pkg_path);
55
- if (!pm) {
56
- return false;
57
- }
58
- const taskName = pm[1];
59
- if (only != null && only != taskName) {
60
- // !(only.indexOf(taskName) >= 0)
61
- return false;
46
+ else {
47
+ console.debug(`[node ${node_version}] Already installed in ${install_path}`);
48
+ }
49
+ return nodePaths(install_path);
50
+ }
51
+ /* Basically this, but for different dirs.
52
+ curl https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${PLATFORM}64.tar.gz -L | tar -xzC /node-dedicated && \
53
+ mv /node-dedicated/node-v${NODE_VERSION}-linux-${PLATFORM}64/bin/node /node-dedicated/node
54
+ */
55
+ // TODO: feature to find the latest minor and patch for a given major version?
56
+ async function downloadAndInstallNode(node_version, destination) {
57
+ // eg. https://nodejs.org/dist/v18.14.2/node-v18.14.2-linux-x64.tar.xz
58
+ const ARCH = os.arch();
59
+ const PLATFORM = os.platform();
60
+ const node_download_url = `https://nodejs.org/dist/v${node_version}/node-v${node_version}-${PLATFORM}-${ARCH}.tar.gz`;
61
+ await downloadAndExtractTarball(node_download_url, destination);
62
+ return nodePaths(destination);
63
+ }
64
+ function nodePaths(destination) {
65
+ return {
66
+ bin_path: path.resolve(destination, 'bin'),
67
+ node_bin: path.resolve(destination, 'bin', 'node'),
68
+ npm_bin: path.resolve(destination, 'bin', 'npm'),
69
+ npx_bin: path.resolve(destination, 'bin', 'npx')
70
+ };
71
+ }
72
+ async function downloadAndExtractTarball(url, dest) {
73
+ const tmpdir = os.tmpdir();
74
+ const filename = path.basename(URL.parse(url).pathname);
75
+ const base = path.basename(filename, '.tar.gz');
76
+ const download = path.join(tmpdir, filename);
77
+ if (fs.existsSync(download)) {
78
+ console.debug(`deleting old ${download}`);
79
+ fs.unlinkSync(download);
80
+ }
81
+ await new Promise(async (resolve, reject) => {
82
+ console.debug(`fetching ${url} into ${download}`);
83
+ const response = await (0, node_fetch_1.default)(url);
84
+ if (!response.ok) {
85
+ const errorBody = await response.statusText;
86
+ throw new Error(`Failed to download: ${errorBody}`);
62
87
  }
63
- return true;
64
- });
65
- // FIXME: Would it be better to map out required node_versions and subsequently install them, or is this in-line approach okay?
66
- /* TODO:
67
- How to install and execute custom node version in a portable way?
68
- - install to predictable path inside project dir, which is writeable in the container.
69
- But how to run it from inside task dirs? local bin? ENV?
70
- What about yarn for each node version?
71
- */
72
- for (const pkg_path of filtered_package_files) {
73
- try {
74
- const content = await fs.promises.readFile(pkg_path, { encoding: 'utf-8' });
75
- const task_package = JSON.parse(content);
76
- const task_version = task_package?.cloudcode?.runtime;
77
- // check task version against supported versions, install relevant node version and yarn
78
- console.log(`Detected task version ${task_version}`);
79
- const matching = SUPPORTED_VERSIONS.find((v) => {
80
- return semver.satisfies(v.version, task_version);
81
- });
82
- if (!matching) {
83
- console.error('FIXME: unsupported version');
84
- }
85
- console.log(`Matching versions: ${JSON.stringify(matching)}`);
86
- const running_node_version = process.versions.node;
87
- if (matching?.node && semver.major(matching.node) !== semver.major(running_node_version)) {
88
- console.log(`Task requires different node version: v${matching.node}`);
89
- const NODE_VERSION = matching.node;
90
- const custom_node_path = path.resolve(`node-${semver.major(NODE_VERSION)}`);
91
- if (!jetpack.exists(custom_node_path)) {
92
- await jetpack.dirAsync(custom_node_path);
93
- await utils.downloadAndInstallNode(NODE_VERSION, custom_node_path);
88
+ const file = fs.createWriteStream(download); // Sink the download stream into a file, so it can be extracted.
89
+ response.body.pipe(file);
90
+ file.on('finish', async () => {
91
+ try {
92
+ console.debug('Extracting...', download);
93
+ tar.extract({
94
+ cwd: tmpdir,
95
+ file: download,
96
+ sync: true
97
+ });
98
+ const uncomp = path.join(tmpdir, base);
99
+ const dist = path.resolve(dest);
100
+ if (fs.existsSync(uncomp)) {
101
+ console.debug(`Moving extracted files from ${uncomp} to ${dist}`);
102
+ fs.renameSync(uncomp, dist);
94
103
  }
104
+ else {
105
+ console.debug(`Can't find extract dir ${uncomp}`);
106
+ }
107
+ /*
108
+ FIXME: the unlinking seems to sometimes cause errors: eg.
109
+ ```
110
+ node:events:505
111
+ throw er; // Unhandled 'error' event
112
+ ^
113
+
114
+ Error: ENOENT: no such file or directory, open '/var/folders/kc/h6m4zpmd23v13s63mygvkslm0000gn/T/node-v16.19.1-darwin-arm64.tar.gz'
115
+ Emitted 'error' event on ReadStream instance at:
116
+ at emitErrorNT (node:internal/streams/destroy:157:8)
117
+ at emitErrorCloseNT (node:internal/streams/destroy:122:3)
118
+ at processTicksAndRejections (node:internal/process/task_queues:83:21) {
119
+ errno: -2,
120
+ code: 'ENOENT',
121
+ syscall: 'open',
122
+ path: '/var/folders/kc/h6m4zpmd23v13s63mygvkslm0000gn/T/node-v16.19.1-darwin-arm64.tar.gz'
123
+ ```
124
+ */
125
+ // fs.unlinkSync(file.path);
126
+ resolve(null);
95
127
  }
96
- }
97
- catch (err) {
98
- console.error(`ERROR: ${err}`);
99
- // todo: check for enoent and skip?
100
- // todo: if json error, throw a CC build error?
101
- }
102
- }
128
+ catch (err) {
129
+ reject(err);
130
+ }
131
+ });
132
+ });
103
133
  }
104
- exports.prepareBuildEnvForTasks = prepareBuildEnvForTasks;
105
134
  //# sourceMappingURL=installer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"installer.js","sourceRoot":"","sources":["../src/installer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,4CAA8B;AAC9B,gDAAkC;AAClC,oDAAsC;AACtC,+CAAiC;AACjC,+CAAiC;AAEjC,MAAM,kBAAkB,GAAG;IACzB;QACE,OAAO,EAAE,QAAQ;QACjB,IAAI,EAAE,SAAS,CAAC,gCAAgC;KACjD;IACD;QACE,OAAO,EAAE,QAAQ;QACjB,IAAI,EAAE,SAAS;KAChB;IACD;QACE,OAAO,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gEAAgE;QAC7G,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEzB,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;YAC3B,IAAI,CAAC;gBACH,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;gBAEzC,GAAG,CAAC,OAAO,CAAC;oBACV,GAAG,EAAE,MAAM;oBACX,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,IAAI;iBACX,CAAC,CAAC;gBAEH,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;gBAEvC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gBAChC,IAAI,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;oBAC1B,OAAO,CAAC,KAAK,CAAC,+BAA+B,MAAM,OAAO,IAAI,EAAE,CAAC,CAAC;oBAClE,EAAE,CAAC,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;gBAC9B,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,KAAK,CAAC,0BAA0B,MAAM,EAAE,CAAC,CAAC;gBACpD,CAAC;gBAED;;;;;;;;;;;;;;;;;kBAiBE;gBACF,4BAA4B;gBAE5B,OAAO,CAAC,IAAI,CAAC,CAAC;YAChB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,MAAM,CAAC,GAAG,CAAC,CAAC;YACd,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
package/dist/run.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { SpawnStreamEvent } from './spawn-stream';
2
+ import { SpawnOptions } from 'child_process';
3
+ export declare function runCommand(command: string, args: string[], options?: Partial<SpawnOptions>): AsyncIterable<SpawnStreamEvent>;
package/dist/run.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runCommand = runCommand;
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
+ //# sourceMappingURL=run.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.js","sourceRoot":"","sources":["../src/run.ts"],"names":[],"mappings":";;AAGA,gCAmBC;AAtBD,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,CAAC;QAC/B,MAAM,KAAK,CAAC;QACZ,IAAI,KAAK,CAAC,QAAQ,IAAI,IAAI,EAAE,CAAC;YAC3B,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAC5B,CAAC;IACH,CAAC;IAED,IAAI,QAAQ,IAAI,CAAC,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,4BAA4B,QAAQ,EAAE,CAAC,CAAC;IAC1D,CAAC;AACH,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { SpawnOptions } from 'child_process';
2
+ export interface StreamOptions {
3
+ splitLines?: boolean;
4
+ }
5
+ export declare function spawnStream(command: string, args: string[], options: SpawnOptions & StreamOptions): {
6
+ childProcess: import("child_process").ChildProcessWithoutNullStreams;
7
+ stream: AsyncIterable<SpawnStreamEvent>;
8
+ };
9
+ export interface SpawnStreamEvent {
10
+ event: 'stdout' | 'stderr' | 'exit';
11
+ stdout?: string;
12
+ stderr?: string;
13
+ exitCode?: number;
14
+ }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.spawnStream = spawnStream;
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
+ function processToStream(process, options) {
17
+ const combinedStream = new stream_1.PassThrough({ objectMode: true });
18
+ async function* transform(stream, key) {
19
+ stream.setEncoding('utf-8');
20
+ let iterable = stream;
21
+ if (options.splitLines) {
22
+ iterable = splitLines(iterable);
23
+ }
24
+ for await (const chunk of iterable) {
25
+ yield {
26
+ event: key,
27
+ [key]: chunk
28
+ };
29
+ }
30
+ }
31
+ if (process.stdout) {
32
+ stream_1.Readable.from(transform(process.stdout, 'stdout')).pipe(combinedStream, { end: false });
33
+ }
34
+ if (process.stderr) {
35
+ stream_1.Readable.from(transform(process.stderr, 'stderr')).pipe(combinedStream, { end: false });
36
+ }
37
+ process.on('exit', (code) => {
38
+ combinedStream.write({ exitCode: code }, () => {
39
+ combinedStream.end();
40
+ });
41
+ });
42
+ return combinedStream;
43
+ }
44
+ async function* splitLines(stream) {
45
+ let buffer = '';
46
+ for await (const chunk of stream) {
47
+ buffer += chunk;
48
+ const lines = buffer.split('\n');
49
+ buffer = lines.pop();
50
+ for (let line of lines) {
51
+ yield `${line}\n`;
52
+ }
53
+ }
54
+ if (buffer) {
55
+ yield buffer;
56
+ }
57
+ }
58
+ //# source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AAO,CAAC,MAAM,EAAE,CAAC;QACnB,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;IAC1F,CAAC;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,CAAC;QACjC,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,CAAC;YACvB,MAAM,GAAG,IAAI,IAAI,CAAC;QACpB,CAAC;IACH,CAAC;IACD,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,MAAM,CAAC;IACf,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,27 +1,37 @@
1
1
  {
2
2
  "name": "@journeyapps/cloudcode-build-agent",
3
- "version": "0.0.0-dev.90a9f01",
4
- "description": "",
3
+ "version": "0.0.0-dev.9117f43",
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",
20
+ "lodash": "4.17.21",
13
21
  "node-fetch": "<3",
14
- "semver": "7.3.8",
15
- "tar": "6.1.13",
16
- "yargs": "17.6.2"
22
+ "semver": "7.6.3",
23
+ "tar": "7.4.3",
24
+ "yargs": "17.7.2"
17
25
  },
18
26
  "devDependencies": {
19
- "@types/node": "^18.6.3",
27
+ "@types/child-process-promise": "2.2.6",
28
+ "@types/lodash": "4.17.7",
29
+ "@types/node": "22.5.0",
20
30
  "@types/node-fetch": "2.6.2",
21
- "@types/semver": "7.3.13",
22
- "@types/tar": "6.1.4",
23
- "@types/yargs": "17.0.22",
24
- "typescript": "4.9.5"
31
+ "@types/semver": "7.5.8",
32
+ "@types/tar": "6.1.13",
33
+ "@types/yargs": "17.0.33",
34
+ "typescript": "5.5.4"
25
35
  },
26
36
  "scripts": {
27
37
  "build": "tsc -b"
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,2 +0,0 @@
1
- export declare function downloadAndInstallNode(node_version: string, destination: string): Promise<void>;
2
- export declare function downloadAndExtractTarball(url: string, dest: string): Promise<void>;
package/dist/utils.js DELETED
@@ -1,83 +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.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
- async function downloadAndInstallNode(node_version, destination) {
41
- // eg. https://nodejs.org/dist/v18.14.2/node-v18.14.2-linux-x64.tar.xz
42
- const PLATFORM = 'x';
43
- const node_download_url = `https://nodejs.org/dist/v${node_version}/node-v${node_version}-linux-${PLATFORM}64.tar.gz`;
44
- await downloadAndExtractTarball(node_download_url, destination);
45
- // TODO: move binaries into local bin path?
46
- }
47
- exports.downloadAndInstallNode = downloadAndInstallNode;
48
- async function downloadAndExtractTarball(url, dest) {
49
- const tmpdir = os.tmpdir();
50
- const filename = path.basename(URL.parse(url).pathname);
51
- const base = path.basename(filename, '.tar.gz');
52
- const download = path.join(tmpdir, filename);
53
- const file = fs.createWriteStream(download);
54
- const response = await (0, node_fetch_1.default)(url);
55
- if (!response.ok) {
56
- const errorBody = await response.text();
57
- throw new Error(`Failed to download: ${errorBody}`);
58
- }
59
- // FIXME: replace with webstreams?
60
- response.body.pipe(file);
61
- file.on('finish', async () => {
62
- console.log('Extracting...', download);
63
- const comp = fs.createReadStream(download);
64
- tar.extract({
65
- cwd: tmpdir,
66
- file: comp.path,
67
- sync: true
68
- });
69
- const uncomp = path.join(tmpdir, base);
70
- const dist = path.resolve(dest);
71
- // FIXME: dangerous. Add protection or replace.
72
- // if (fs.existsSync(dist)) {
73
- // fs.rmSync(dist, { recursive: true });
74
- // }
75
- if (fs.existsSync(uncomp)) {
76
- console.log(`Moving extracted files from ${uncomp} to ${dist}`);
77
- fs.renameSync(uncomp, dist);
78
- }
79
- fs.unlinkSync(file.path);
80
- });
81
- }
82
- exports.downloadAndExtractTarball = downloadAndExtractTarball;
83
- //# 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAA+B;AAC/B,gDAAkC;AAClC,4CAA8B;AAC9B,4CAA8B;AAC9B,8CAAgC;AAChC,yCAA2B;AAE3B;;;EAGE;AACK,KAAK,UAAU,sBAAsB,CAAC,YAAoB,EAAE,WAAmB;IACpF,sEAAsE;IACtE,MAAM,QAAQ,GAAG,GAAG,CAAC;IACrB,MAAM,iBAAiB,GAAG,4BAA4B,YAAY,UAAU,YAAY,UAAU,QAAQ,WAAW,CAAC;IAEtH,MAAM,yBAAyB,CAAC,iBAAiB,EAAE,WAAW,CAAC,CAAC;IAChE,2CAA2C;AAC7C,CAAC;AAPD,wDAOC;AAEM,KAAK,UAAU,yBAAyB,CAAC,GAAW,EAAE,IAAY;IACvE,MAAM,MAAM,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC;IAE3B,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAkB,CAAC,CAAC;IAClE,MAAM,IAAI,GAAG,IAAI,CAAC,QAA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C7B;QAED,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;AACL,CAAC;AA1CD,8DA0CC"}
package/src/builder.ts DELETED
@@ -1,7 +0,0 @@
1
- import { spawnSync } from 'child_process';
2
-
3
- // Detect tasks in given path and build them.
4
- export async function buildTasks(src: string, dest: string, only?: string) {}
5
-
6
- // Build a single task in the specified subdirectory.
7
- async function buildTask(src: string, dest: string, config: any) {}
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/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';