@journeyapps/cloudcode-build-legacy 0.0.0-dev.08a6ddf

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/bin.js ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require('./dist/cli');
@@ -0,0 +1,7 @@
1
+ export interface BuildParameters {
2
+ /** Configuration built into the task. */
3
+ taskConfig: any;
4
+ appPath: string;
5
+ outPath: string;
6
+ zipPath?: string;
7
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=BuildParameters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BuildParameters.js","sourceRoot":"","sources":["../src/BuildParameters.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @param src - path to the task. Must contain a cloudcode folder.
3
+ * @param dest - destination folder. Will contain an `app/cloudcode` folder after building.
4
+ * @param [zipPath] - path to use for creating a zip of dest. No zip created if this is null.
5
+ * @param config - task config, written to config.json.
6
+ */
7
+ export declare function build(src: string, dest: string, zipPath: string | null, config: any): Promise<string>;
package/dist/build.js ADDED
@@ -0,0 +1,271 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.build = void 0;
4
+ const babel = require("@babel/core");
5
+ const jetpack = require("fs-jetpack");
6
+ const archiver = require("archiver");
7
+ const fs = require("fs");
8
+ const path = require("path");
9
+ const glob = require("glob-promise");
10
+ const cloudcodeBuild = require("@journeyapps/cloudcode-build");
11
+ const yarn_1 = require("./yarn");
12
+ const error_1 = require("./error");
13
+ const { YARN_HOME } = require('./config');
14
+ const debug = require('debug')('build');
15
+ // Babel config for tasks that don't have a defined "build" step.
16
+ const BABEL_PLUGINS = [
17
+ // Transform import statements into require() calls.
18
+ '@babel/plugin-transform-modules-commonjs'
19
+ ];
20
+ const BABEL_OPTIONS = {
21
+ plugins: BABEL_PLUGINS.map((plugin) => require.resolve(plugin)),
22
+ sourceMaps: 'inline',
23
+ highlightCode: false
24
+ };
25
+ async function transformFile(file) {
26
+ return new Promise((resolve, reject) => {
27
+ babel.transformFile(file, BABEL_OPTIONS, (error, result) => {
28
+ if (error) {
29
+ reject(error);
30
+ }
31
+ else {
32
+ resolve(result);
33
+ }
34
+ });
35
+ });
36
+ }
37
+ async function transformFiles(root, src, dest) {
38
+ const fullSrc = path.join(root, src);
39
+ var files = await glob(fullSrc + '/**/*.js');
40
+ debug('building files in', fullSrc, ':', files);
41
+ for (let file of files) {
42
+ debug('building', file);
43
+ let promise = transformFile(file).then(async (result) => {
44
+ var fileDest = file.replace(fullSrc, dest);
45
+ await jetpack.writeAsync(fileDest, result.code);
46
+ debug('built', file);
47
+ return fileDest;
48
+ }, (error) => {
49
+ let message = error.message || '';
50
+ // Replace filename
51
+ message = message.replace(/^.+?: /, '');
52
+ // Only use the first line
53
+ message = message.split('\n')[0];
54
+ throw new error_1.BuildError(message, {
55
+ error: 'CLOUDCODE/BUILD/COMPILE_ERROR',
56
+ file: file.replace(root + '/', ''),
57
+ cause: error
58
+ });
59
+ });
60
+ // If we transform multiple files in parallel, babel often returns the wrong filename
61
+ // in SyntaxErrors. To avoid this, we build sequentially for now.
62
+ // We can change this to parallel again in the future if this is fixed by Babel.
63
+ await promise;
64
+ }
65
+ }
66
+ async function createEntry(dest, taskPath) {
67
+ // Use entry.js from @journeyapps/cloudcode, which should be installed as a task dependency.
68
+ const content = `
69
+ const path = require('path');
70
+ const taskPath = path.join(__dirname, '${taskPath}');
71
+
72
+ const cc_entry_path = require.resolve('@journeyapps/cloudcode/entry', {
73
+ paths: [taskPath]
74
+ });
75
+ const entry = require(cc_entry_path);
76
+
77
+ if (module == require.main) {
78
+ entry.runCli(taskPath);
79
+ } else {
80
+ entry.setupLambda(taskPath);
81
+ }
82
+
83
+ module.exports = entry;
84
+ `;
85
+ await jetpack.writeAsync(path.join(dest, 'entry.js'), content);
86
+ }
87
+ async function copyBase(src, dest) {
88
+ if (await jetpack.existsAsync(src)) {
89
+ await jetpack.copyAsync(src, dest, { overwrite: true });
90
+ }
91
+ }
92
+ async function zip(src, dest) {
93
+ // Some stats for base template (on dev machine):
94
+ // archiver takes around 2500ms (3450ms on lambda)
95
+ // jszip via easy-zip takes around 4500ms
96
+ // zip command takes around 660ms
97
+ return new Promise((resolve, reject) => {
98
+ var output = fs.createWriteStream(dest);
99
+ var z = archiver.create('zip', {});
100
+ output.on('close', resolve);
101
+ z.on('error', reject);
102
+ z.pipe(output);
103
+ z.directory(src, '');
104
+ z.finalize();
105
+ });
106
+ }
107
+ /**
108
+ * @param src - path to the task. Must contain a cloudcode folder.
109
+ * @param dest - destination folder. Will contain an `app/cloudcode` folder after building.
110
+ * @param [zipPath] - path to use for creating a zip of dest. No zip created if this is null.
111
+ * @param config - task config, written to config.json.
112
+ */
113
+ async function build(src, dest, zipPath, config) {
114
+ const taskName = config.task;
115
+ // true if safe to run user- or package-defined scripts as part of the install process.
116
+ const runInstallScripts = config.runInstallScripts;
117
+ await jetpack.dir(dest, { empty: true });
118
+ debug('copy app');
119
+ const taskSrc = path.join(src, 'cloudcode', taskName);
120
+ const taskSharedSrc = path.join(src, 'cloudcode', 'shared');
121
+ const taskPath = path.join(dest, 'app', 'cloudcode', taskName);
122
+ const destTaskPath = path.join('app', 'cloudcode', taskName);
123
+ const taskSharedPath = path.join(dest, 'app', 'cloudcode', 'shared');
124
+ // Copy base files
125
+ for (let file of ['schema.xml', 'application.xml', 'config.json', 'translations']) {
126
+ await copyBase(path.join(src, file), path.join(dest, 'app', file));
127
+ }
128
+ // Copy only CloudCode files for the specific task (including shared task files)
129
+ await copyBase(taskSrc, taskPath);
130
+ await copyBase(taskSharedSrc, taskSharedPath);
131
+ debug('build task');
132
+ const packageJson = JSON.parse(fs.readFileSync(path.join(taskPath, 'package.json'), 'utf-8'));
133
+ const packageDependencies = packageJson.dependencies || {};
134
+ const packageDevDependencies = packageJson.devDependencies || {};
135
+ const needsYarn = Object.keys(packageDependencies).length > 0 || Object.keys(packageDevDependencies).length > 0;
136
+ const hasBuild = packageJson.scripts && packageJson.scripts.build;
137
+ const isCloudCodeBuild = hasBuild && packageJson.scripts.build == 'cloudcode-build';
138
+ if (!hasBuild) {
139
+ // For tasks without a "build" script, use babel.
140
+ await transformFiles(src, 'cloudcode/' + taskName, taskPath);
141
+ await transformFiles(src, path.join('cloudcode', 'shared'), taskSharedPath);
142
+ }
143
+ else if (!runInstallScripts && !isCloudCodeBuild) {
144
+ throw new error_1.BuildError(`Custom build scripts not allowed. Use \`"build": "cloudcode-build"\` in package.json.`, {
145
+ error: 'CLOUDCODE/BUILD/BUILD_FAILED'
146
+ });
147
+ }
148
+ const yarnLock = path.join(taskPath, 'yarn.lock');
149
+ if (needsYarn && !fs.existsSync(yarnLock)) {
150
+ throw new Error('yarn.lock required to install dependencies');
151
+ }
152
+ const cacheOptions = ['--cache-folder', path.join(YARN_HOME, 'yarn-cache')];
153
+ let args = [
154
+ 'install',
155
+ // Yarn should auto-detect that we're not in an interactive shell, but we add this to make sure.
156
+ // In interactive mode, yarn could prompt the user to select a different version if an invalid version
157
+ // was specified.
158
+ '--non-interactive',
159
+ // Ensure yarn.lock is in sync with package.json; refuse to install otherwise
160
+ '--frozen-lockfile',
161
+ // Specify cache path
162
+ ...cacheOptions
163
+ ];
164
+ if (!runInstallScripts) {
165
+ // runInstallScripts is behind a hidden feature flag,
166
+ // Don't run lifecycle scripts when installing, which could be a security issue, unless it's
167
+ // authorized by the feature flag.
168
+ //
169
+ // The security issue is that this Lambda process may be re-used when rebuilding the next app,
170
+ // and lifecycle scripts could theoretically spawn a long-running process that can then read
171
+ // the source of the next app.
172
+ //
173
+ // Disabling scripts prevents certain packages from being installed correctly, especially packages using
174
+ // native extensions, or downloading external resources.
175
+ args.push('--ignore-scripts');
176
+ }
177
+ let env = {
178
+ // Yarn is hardcoded to store configuration in the user's home dir.
179
+ // Since our home dir is read-only, we override it for yarn.
180
+ HOME: YARN_HOME
181
+ };
182
+ try {
183
+ if (needsYarn && hasBuild) {
184
+ // We only need to do this if a build script is defined, and (dev)dependencies are defined.
185
+ debug('Installing devDependencies with yarn...');
186
+ await (0, yarn_1.runYarn)(taskPath, args, { env });
187
+ }
188
+ }
189
+ catch (err) {
190
+ throw new error_1.BuildError(err.message, {
191
+ error: 'CLOUDCODE/BUILD/YARN_DEV_FAILED',
192
+ cause: err
193
+ });
194
+ }
195
+ try {
196
+ if (isCloudCodeBuild) {
197
+ // Use @journeyapps/cloudcode-build directly.
198
+ // For security purposes, use the bundled version, not whatever the developer specified.
199
+ await cloudcodeBuild.buildTask(taskPath);
200
+ }
201
+ else if (hasBuild && runInstallScripts) {
202
+ // Custom build script.
203
+ await (0, yarn_1.runScript)(taskPath, ['run', '--quiet', 'build'], { env });
204
+ }
205
+ }
206
+ catch (err) {
207
+ throw new error_1.BuildError(err.message, {
208
+ error: 'CLOUDCODE/BUILD/BUILD_FAILED',
209
+ cause: err
210
+ });
211
+ }
212
+ try {
213
+ if (needsYarn) {
214
+ // Remove devDependencies (or install dependencies in the case of (needsYarn && !hasBuild)
215
+ debug('Installing production dependencies with yarn...');
216
+ await (0, yarn_1.runYarn)(taskPath, [...args, '--production'], { env });
217
+ }
218
+ }
219
+ catch (err) {
220
+ throw new error_1.BuildError(err.message, {
221
+ error: 'CLOUDCODE/BUILD/YARN_PROD_FAILED',
222
+ cause: err
223
+ });
224
+ }
225
+ try {
226
+ // For easier migration, we automatically add @journeyapps/cloudcode and node-fetch if it's not present in the task.
227
+ // We do this by copying our local dependency.
228
+ // Because it's installed as a link: dependency, this includes all the production sub-dependencies.
229
+ // We do this after the `yarn install --production`, to make sure yarn doesn't remove this again.
230
+ // node-fetch has no transitive dependencies, so we can just copy that as well.
231
+ const ccdest = path.join(taskPath, 'node_modules', '@journeyapps', 'cloudcode');
232
+ if (!(await jetpack.existsAsync(ccdest))) {
233
+ const localPath = path.dirname(require.resolve('@journeyapps/cloudcode/package.json'));
234
+ await jetpack.copyAsync(localPath, ccdest);
235
+ }
236
+ const fetchtest = path.join(taskPath, 'node_modules', 'node-fetch');
237
+ if (!(await jetpack.existsAsync(fetchtest))) {
238
+ // We want this as a top-level dependency.
239
+ const localPath = require.resolve('node-fetch', {
240
+ paths: [require.resolve('@journeyapps/cloudcode')]
241
+ });
242
+ await jetpack.copyAsync(localPath, fetchtest);
243
+ }
244
+ }
245
+ catch (err) {
246
+ throw new error_1.BuildError(err.message, {
247
+ error: 'CLOUDCODE/BUILD/COPY_TEMPLATE_FAILED',
248
+ cause: err
249
+ });
250
+ }
251
+ const savedConfig = {
252
+ // config contains more than this, but these are the only values we want to save
253
+ backendUrl: config.backendUrl,
254
+ appInstanceIds: config.appInstanceIds,
255
+ task: config.task,
256
+ appId: config.appId,
257
+ env: config.env
258
+ };
259
+ await jetpack.writeAsync(dest + '/config.json', JSON.stringify(savedConfig));
260
+ await createEntry(dest, destTaskPath);
261
+ if (zipPath) {
262
+ debug('zip');
263
+ await zip(dest, zipPath);
264
+ return zipPath;
265
+ }
266
+ else {
267
+ return dest;
268
+ }
269
+ }
270
+ exports.build = build;
271
+ //# sourceMappingURL=build.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.js","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":";;;AAAA,qCAAqC;AACrC,sCAAsC;AACtC,qCAAqC;AACrC,yBAAyB;AACzB,6BAA6B;AAC7B,qCAAqC;AACrC,+DAA+D;AAE/D,iCAA4C;AAC5C,mCAAqC;AAErC,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAE1C,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC;AAExC,iEAAiE;AACjE,MAAM,aAAa,GAAG;IACpB,oDAAoD;IACpD,0CAA0C;CAC3C,CAAC;AAEF,MAAM,aAAa,GAA2B;IAC5C,OAAO,EAAE,aAAa,CAAC,GAAG,CAAC,C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AE,OAAO,CAAC,CAAC;QACzB,OAAO,OAAO,CAAC;KAChB;SAAM;QACL,OAAO,IAAI,CAAC;KACb;AACH,CAAC;AA7KD,sBA6KC"}
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const yargs = require("yargs");
5
+ const index_1 = require("./index");
6
+ yargs
7
+ .command(['build', '$0'], // $0 means this is the default command
8
+ 'build task', (yargs) => {
9
+ return (yargs
10
+ .option('src', { string: true, demandOption: true })
11
+ .option('out', { string: true, demandOption: true })
12
+ .option('zip', { string: true })
13
+ .option('task', { string: true, demandOption: true })
14
+ .option('runInstallScripts', { default: false })
15
+ // TODO: investigate yargs.config() for reading task config blob from a file. But how to ensure required args?
16
+ .option('appId', { string: true, demandOption: true, describe: "CloudCode's reference id" })
17
+ .option('env', { string: true, demandOption: true })
18
+ .option('backendId', { string: true, demandOption: true })
19
+ .option('backendUrl', { string: true, demandOption: true }));
20
+ }, handled(async (argv) => {
21
+ (0, index_1.handle)({
22
+ appPath: argv.src,
23
+ outPath: argv.out,
24
+ zipPath: argv.zip,
25
+ taskConfig: {
26
+ appId: argv.appId,
27
+ env: argv.env,
28
+ task: argv.task,
29
+ appInstanceIds: [argv.backendId],
30
+ backendUrl: argv.backendUrl,
31
+ runInstallScripts: argv.runInstallScripts
32
+ }
33
+ });
34
+ }))
35
+ .option('verbose', {
36
+ alias: 'v',
37
+ default: false
38
+ }).argv;
39
+ function handled(fn) {
40
+ return async (argv) => {
41
+ try {
42
+ await fn(argv);
43
+ }
44
+ catch (err) {
45
+ console.error(err.stack);
46
+ process.exit(1);
47
+ }
48
+ };
49
+ }
50
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],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,CAAC,KAAK;YACjB,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,cAAc,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC;YAChC,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,iBAAiB,EAAE,IAAI,CAAC,iBAAiB;SAC1C;KACF,CAAC,CAAC;AACL,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,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACzB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjB;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ declare const TMP_PATH = "/tmp/cloudcode-build";
2
+ declare const WORKING_PATH: string;
3
+ declare const APP_PATH: string;
4
+ declare const OUTPUT_PATH: string;
5
+ declare const ZIP_PATH: string;
6
+ declare const YARN_HOME: string;
7
+ export { TMP_PATH, WORKING_PATH, APP_PATH, OUTPUT_PATH, ZIP_PATH, YARN_HOME };
package/dist/config.js ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.YARN_HOME = exports.ZIP_PATH = exports.OUTPUT_PATH = exports.APP_PATH = exports.WORKING_PATH = exports.TMP_PATH = void 0;
4
+ const TMP_PATH = '/tmp/cloudcode-build'; // FIXME: maybe use mktemp or other task-specific workdir?
5
+ exports.TMP_PATH = TMP_PATH;
6
+ const WORKING_PATH = TMP_PATH + '/extract';
7
+ exports.WORKING_PATH = WORKING_PATH;
8
+ const APP_PATH = WORKING_PATH + '/app';
9
+ exports.APP_PATH = APP_PATH;
10
+ const OUTPUT_PATH = TMP_PATH + '/dist';
11
+ exports.OUTPUT_PATH = OUTPUT_PATH;
12
+ const ZIP_PATH = TMP_PATH + '/build.zip';
13
+ exports.ZIP_PATH = ZIP_PATH;
14
+ const YARN_HOME = TMP_PATH + '/yarn';
15
+ exports.YARN_HOME = YARN_HOME;
16
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;AAAA,MAAM,QAAQ,GAAG,sBAAsB,CAAC,CAAC,0DAA0D;AAO1F,4BAAQ;AANjB,MAAM,YAAY,GAAG,QAAQ,GAAG,UAAU,CAAC;AAMxB,oCAAY;AAL/B,MAAM,QAAQ,GAAG,YAAY,GAAG,MAAM,CAAC;AAKN,4BAAQ;AAJzC,MAAM,WAAW,GAAG,QAAQ,GAAG,OAAO,CAAC;AAII,kCAAW;AAHtD,MAAM,QAAQ,GAAG,QAAQ,GAAG,YAAY,CAAC;AAGe,4BAAQ;AAFhE,MAAM,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE6B,8BAAS"}
@@ -0,0 +1,18 @@
1
+ export declare class BuildError extends Error {
2
+ file: string;
3
+ error: string;
4
+ name: string;
5
+ cause?: Error;
6
+ constructor(message: string, options: {
7
+ cause?: Error;
8
+ file?: string;
9
+ error?: string;
10
+ });
11
+ toJSON(): {
12
+ error: string;
13
+ message: string;
14
+ file: string;
15
+ stack: string;
16
+ };
17
+ static fromError(error: Error): BuildError;
18
+ }
package/dist/error.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BuildError = void 0;
4
+ class BuildError extends Error {
5
+ constructor(message, options) {
6
+ super(message);
7
+ options = options || {};
8
+ // Non-enumerable to not display in logs
9
+ Object.defineProperty(this, 'name', {
10
+ value: this.constructor.name
11
+ });
12
+ Object.defineProperty(this, 'cause', {
13
+ value: options.cause
14
+ });
15
+ // These are displayed in console.log
16
+ this.file = options.file;
17
+ this.error = options.error || 'CLOUDCODE/BUILD/ERROR';
18
+ Error.captureStackTrace(this, this.constructor);
19
+ if (options.cause && options.cause.stack) {
20
+ this.stack += '\nCaused by: ' + options.cause.stack;
21
+ }
22
+ }
23
+ toJSON() {
24
+ return {
25
+ error: this.error,
26
+ message: this.message,
27
+ file: this.file,
28
+ stack: this.stack
29
+ };
30
+ }
31
+ static fromError(error) {
32
+ if (error instanceof BuildError) {
33
+ return error;
34
+ }
35
+ return new BuildError(error.message, { cause: error });
36
+ }
37
+ }
38
+ exports.BuildError = BuildError;
39
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":";;;AAAA,MAAa,UAAW,SAAQ,KAAK;IAMnC,YAAY,OAAe,EAAE,OAAyD;QACpF,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;QAExB,wCAAwC;QACxC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE;YAClC,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI;SAC7B,CAAC,CAAC;QAEH,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE;YACnC,KAAK,EAAE,OAAO,CAAC,KAAK;SACrB,CAAC,CAAC;QAEH,qCAAqC;QACrC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,uBAAuB,CAAC;QAEtD,KAAK,CAAC,iBAAiB,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAChD,IAAI,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,EAAE;YACxC,IAAI,CAAC,KAAK,IAAI,eAAe,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;SACrD;IACH,CAAC;IAED,MAAM;QACJ,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,KAAY;QAC3B,IAAI,KAAK,YAAY,UAAU,EAAE;YAC/B,OAAO,KAAK,CAAC;SACd;QACD,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACzD,CAAC;CACF;AA5CD,gCA4CC"}
@@ -0,0 +1,2 @@
1
+ import { BuildParameters } from './BuildParameters';
2
+ export declare function handle(event: BuildParameters): Promise<string>;
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handle = void 0;
4
+ const jetpack = require("fs-jetpack");
5
+ const build_1 = require("./build");
6
+ const error_1 = require("./error");
7
+ const debug = require('debug')('build');
8
+ const { TMP_PATH, APP_PATH, ZIP_PATH, OUTPUT_PATH } = require('./config');
9
+ async function handle(event) {
10
+ var _a, _b;
11
+ try {
12
+ await jetpack.dir(TMP_PATH, { empty: true });
13
+ await jetpack.dir(APP_PATH, { empty: true });
14
+ const outPath = (_a = event.outPath) !== null && _a !== void 0 ? _a : OUTPUT_PATH;
15
+ const zipPath = (_b = event.zipPath) !== null && _b !== void 0 ? _b : ZIP_PATH;
16
+ debug('copying...');
17
+ await jetpack.copy(event.appPath, APP_PATH, { overwrite: true }); // FIXME: this might cause copy-loops if outPath is inside event.appPath
18
+ debug('building...');
19
+ var zipFile = await (0, build_1.build)(APP_PATH, outPath, zipPath, event.taskConfig);
20
+ debug('built', outPath, zipFile);
21
+ debug('done.');
22
+ return 'done!';
23
+ }
24
+ catch (error) {
25
+ const wrappedError = error_1.BuildError.fromError(error);
26
+ console.error(wrappedError); // Includes error.stack
27
+ // return wrappedError;
28
+ throw wrappedError;
29
+ }
30
+ }
31
+ exports.handle = handle;
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,sCAAsC;AACtC,mCAAgC;AAChC,mCAAqC;AAGrC,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC;AAExC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEnE,KAAK,UAAU,MAAM,CAAC,KAAsB;;IACjD,IAAI;QACF,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAC7C,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QAE7C,MAAM,OAAO,GAAG,MAAA,KAAK,CAAC,OAAO,mCAAI,WAAW,CAAC;QAC7C,MAAM,OAAO,GAAG,MAAA,KAAK,CAAC,OAAO,mCAAI,QAAQ,CAAC;QAC1C,KAAK,CAAC,YAAY,CAAC,CAAC;QACpB,MAAM,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,wEAAwE;QAC1I,KAAK,CAAC,aAAa,CAAC,CAAC;QACrB,IAAI,OAAO,GAAG,MAAM,IAAA,aAAK,EAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;QACxE,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACjC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,OAAO,OAAO,CAAC;KAChB;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,YAAY,GAAG,kBAAU,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACjD,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,uBAAuB;QACpD,uBAAuB;QACvB,MAAM,YAAY,CAAC;KACpB;AACH,CAAC;AApBD,wBAoBC"}
package/dist/yarn.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare function runYarn(dir: string, args: string[], options: any): Promise<any>;
2
+ export declare function runScript(dir: string, args: string[], options: any): Promise<void>;
package/dist/yarn.js ADDED
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runScript = exports.runYarn = void 0;
4
+ const child_process_promise_1 = require("child-process-promise");
5
+ const debug = require('debug')('build');
6
+ function runYarn(dir, args, options) {
7
+ const yarnPath = require.resolve('yarn/bin/yarn.js');
8
+ const runArgs = [process.argv[0], yarnPath, ...args];
9
+ return runYarnCommand(runArgs, Object.assign({ cwd: dir, logPrefix: 'yarn' }, options));
10
+ }
11
+ exports.runYarn = runYarn;
12
+ async function runScript(dir, args, options) {
13
+ const yarnPath = require.resolve('yarn/bin/yarn.js');
14
+ const runArgs = [process.argv[0], yarnPath, ...args];
15
+ let errors = [];
16
+ const logLine = (isStderr, line, childProcess) => {
17
+ if (isStderr) {
18
+ if (line.startsWith('warning package.json: No license field')) {
19
+ // This is a noisy yarn warning, ignore it.
20
+ return;
21
+ }
22
+ errors.push(line);
23
+ }
24
+ };
25
+ let result;
26
+ try {
27
+ result = await runCommand(runArgs, Object.assign({ cwd: dir, logPrefix: args[0], logLine }, options));
28
+ }
29
+ catch (err) {
30
+ if (errors.length > 0) {
31
+ // Ignore yarn exit code message.
32
+ throw new Error(`${errors.join('\n')}`);
33
+ }
34
+ else {
35
+ throw err;
36
+ }
37
+ }
38
+ if (result.code == 0) {
39
+ return;
40
+ }
41
+ throw new Error(`${errors.join('\n')}
42
+
43
+ Process exit with code ${result.code}`);
44
+ }
45
+ exports.runScript = runScript;
46
+ /**
47
+ * Run a yarn command and log the output.
48
+ *
49
+ * Ported from scripts/build/shell.js, then added yarn-specific hacks.
50
+ */
51
+ async function runYarnCommand(commandArgs, options) {
52
+ let errors = [];
53
+ options = Object.assign({}, options, {
54
+ logLine(isStderr, line, childProcess) {
55
+ if (isStderr && line.startsWith('error')) {
56
+ errors.push(line);
57
+ }
58
+ }
59
+ });
60
+ let result;
61
+ try {
62
+ result = await runCommand(commandArgs, options);
63
+ }
64
+ catch (err) {
65
+ if (errors.length > 0) {
66
+ // Handled below
67
+ }
68
+ else {
69
+ // Exit code without any logged errors.
70
+ throw err;
71
+ }
72
+ }
73
+ if (result) {
74
+ debug('yarn exit code:', result.code);
75
+ }
76
+ if (errors.length > 0) {
77
+ // We consider this a failure, regardless of exit code.
78
+ // In general, we expect errors to be accompanied by an error code of 1 (and vice versa),
79
+ // but we do not depend on that behaviour.
80
+ throw new Error('Error installing dependencies: ' + errors.join('\n'));
81
+ }
82
+ if (result.code === 0) {
83
+ return result;
84
+ }
85
+ else {
86
+ throw new Error(`Error code '${result.code}' while running command`);
87
+ }
88
+ }
89
+ /**
90
+ * Run a yarn command and log the output.
91
+ *
92
+ * Ported from scripts/build/shell.js, then added yarn-specific hacks.
93
+ */
94
+ async function runCommand(commandArgs, options) {
95
+ options = Object.assign({}, options);
96
+ let logPrefix = options.logPrefix || '';
97
+ delete options.logPrefix;
98
+ if (logPrefix) {
99
+ logPrefix += ' ';
100
+ }
101
+ const logLine = options.logLine;
102
+ delete options.receivedLines;
103
+ let logBuffer = '';
104
+ const log = (isStderr, data) => {
105
+ data = data.toString();
106
+ let trimmed = data.replace(/[\n|\r|\r\n]$/, '');
107
+ if (trimmed.length == data.length) {
108
+ logBuffer += trimmed;
109
+ return;
110
+ }
111
+ if (logBuffer.length > 0) {
112
+ trimmed = logBuffer + trimmed;
113
+ logBuffer = '';
114
+ }
115
+ trimmed.split('\n').forEach((line) => {
116
+ debug(`${logPrefix}${line}`);
117
+ logLine(isStderr, line, spawnPromise.childProcess);
118
+ });
119
+ };
120
+ debug(`${logPrefix}(${options.cwd || '.'}) \$ ${commandArgs.join(' ')}`);
121
+ let spawnPromise = (0, child_process_promise_1.spawn)(commandArgs.shift(), commandArgs, options);
122
+ spawnPromise.childProcess.stdout.on('data', log.bind(null, false));
123
+ spawnPromise.childProcess.stderr.on('data', log.bind(null, true));
124
+ try {
125
+ return await spawnPromise;
126
+ }
127
+ finally {
128
+ spawnPromise.childProcess.stdout.removeAllListeners('data');
129
+ spawnPromise.childProcess.stderr.removeAllListeners('data');
130
+ }
131
+ }
132
+ //# sourceMappingURL=yarn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yarn.js","sourceRoot":"","sources":["../src/yarn.ts"],"names":[],"mappings":";;;AAAA,iEAA8C;AAC9C,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC;AAExC,SAAgB,OAAO,CAAC,GAAW,EAAE,IAAc,EAAE,OAAO;IAC1D,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACrD,MAAM,OAAO,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,CAAC;IAErD,OAAO,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;AAC1F,CAAC;AALD,0BAKC;AAEM,KAAK,UAAU,SAAS,CAAC,GAAW,EAAE,IAAc,EAAE,OAAO;IAClE,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACrD,MAAM,OA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C;IAElE,IAAI;QACF,OAAO,MAAM,YAAY,CAAC;KAC3B;YAAS;QACR,YAAY,CAAC,YAAY,CAAC,MAAM,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAC5D,YAAY,CAAC,YAAY,CAAC,MAAM,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;KAC7D;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@journeyapps/cloudcode-build-legacy",
3
+ "version": "0.0.0-dev.08a6ddf",
4
+ "description": "Port of JourneyApps CloudCode's legacy build tooling.",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "bin": {
9
+ "cloudcode-build-legacy": "./bin.js"
10
+ },
11
+ "files": [
12
+ "bin.js",
13
+ "dist"
14
+ ],
15
+ "dependencies": {
16
+ "@babel/core": "^7.14.6",
17
+ "@babel/plugin-transform-modules-commonjs": "^7.14.5",
18
+ "@journeyapps/cloudcode": "1.12.0",
19
+ "@journeyapps/cloudcode-build": "1.12.0",
20
+ "archiver": "^1.0.1",
21
+ "aws-sdk": "^2.5.2",
22
+ "child-process-promise": "^2.2.0",
23
+ "concat-stream": "^1.6.0",
24
+ "debug": "^2.6.0",
25
+ "fs-jetpack": "^0.9.2",
26
+ "glob": "^7.0.5",
27
+ "glob-promise": "^3.1.0",
28
+ "lodash": "^4.17.2",
29
+ "mkdirp": "^0.5.1",
30
+ "source-map-support": "^0.4.2",
31
+ "yargs": "17.7.1",
32
+ "yarn": "^1.7.0"
33
+ },
34
+ "devDependencies": {
35
+ "@types/node": "14.18.36",
36
+ "@types/yargs": "17.0.22"
37
+ },
38
+ "scripts": {
39
+ "build": "tsc -b"
40
+ }
41
+ }