@journeyapps/cloudcode-build-legacy 0.0.0-dev.02b8c87

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,8 @@
1
+ export interface BuildParameters {
2
+ /** Configuration built into the task. */
3
+ taskConfig: any;
4
+ appPath: string;
5
+ outPath: string;
6
+ zipPath: string;
7
+ yarnHome?: string;
8
+ }
@@ -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,10 @@
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.
5
+ * @param config - task config, written to config.json.
6
+ * @param options - build options.
7
+ */
8
+ export declare function build(src: string, dest: string, zipPath: string, config: any, options: {
9
+ yarnHome: string;
10
+ }): Promise<string>;
package/dist/build.js ADDED
@@ -0,0 +1,252 @@
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 debug = require('debug')('build');
14
+ // Babel config for tasks that don't have a defined "build" step.
15
+ const BABEL_PLUGINS = [
16
+ // Transform import statements into require() calls.
17
+ '@babel/plugin-transform-modules-commonjs'
18
+ ];
19
+ const BABEL_OPTIONS = {
20
+ plugins: BABEL_PLUGINS.map((plugin) => require.resolve(plugin)),
21
+ sourceMaps: 'inline',
22
+ highlightCode: false
23
+ };
24
+ async function transformFile(file) {
25
+ return new Promise((resolve, reject) => {
26
+ babel.transformFile(file, BABEL_OPTIONS, (error, result) => {
27
+ if (error) {
28
+ reject(error);
29
+ }
30
+ else {
31
+ resolve(result);
32
+ }
33
+ });
34
+ });
35
+ }
36
+ async function transformFiles(root, src, dest) {
37
+ const fullSrc = path.join(root, src);
38
+ var files = await glob(fullSrc + '/**/*.js');
39
+ debug('building files in', fullSrc, ':', files);
40
+ for (let file of files) {
41
+ debug('building', file);
42
+ let promise = transformFile(file).then(async (result) => {
43
+ var fileDest = file.replace(fullSrc, dest);
44
+ await jetpack.writeAsync(fileDest, result.code);
45
+ debug('built', file);
46
+ return fileDest;
47
+ }, (error) => {
48
+ let message = error.message || '';
49
+ // Replace filename
50
+ message = message.replace(/^.+?: /, '');
51
+ // Only use the first line
52
+ message = message.split('\n')[0];
53
+ throw new error_1.BuildError(message, {
54
+ error: 'CLOUDCODE/BUILD/COMPILE_ERROR',
55
+ file: file.replace(root + '/', ''),
56
+ cause: error
57
+ });
58
+ });
59
+ // If we transform multiple files in parallel, babel often returns the wrong filename
60
+ // in SyntaxErrors. To avoid this, we build sequentially for now.
61
+ // We can change this to parallel again in the future if this is fixed by Babel.
62
+ await promise;
63
+ }
64
+ }
65
+ async function createEntry(dest, taskPath) {
66
+ // Use entry.js from @journeyapps/cloudcode, which should be installed as a task dependency.
67
+ const content = `
68
+ const path = require('path');
69
+ const taskPath = path.join(__dirname, '${taskPath}');
70
+
71
+ const cc_entry_path = require.resolve('@journeyapps/cloudcode/entry', {
72
+ paths: [taskPath]
73
+ });
74
+ const entry = require(cc_entry_path);
75
+
76
+ if (module == require.main) {
77
+ entry.runCli(taskPath);
78
+ } else {
79
+ entry.setupLambda(taskPath);
80
+ }
81
+
82
+ module.exports = entry;
83
+ `;
84
+ await jetpack.writeAsync(path.join(dest, 'entry.js'), content);
85
+ }
86
+ async function copyBase(src, dest) {
87
+ if (await jetpack.existsAsync(src)) {
88
+ await jetpack.copyAsync(src, dest, { overwrite: true });
89
+ }
90
+ }
91
+ async function zip(src, dest) {
92
+ // Some stats for base template (on dev machine):
93
+ // archiver takes around 2500ms (3450ms on lambda)
94
+ // jszip via easy-zip takes around 4500ms
95
+ // zip command takes around 660ms
96
+ return new Promise((resolve, reject) => {
97
+ var output = fs.createWriteStream(dest);
98
+ var z = archiver.create('zip', {});
99
+ output.on('close', resolve);
100
+ z.on('error', reject);
101
+ z.pipe(output);
102
+ z.directory(src, '');
103
+ z.finalize();
104
+ });
105
+ }
106
+ /**
107
+ * @param src - path to the task. Must contain a cloudcode folder.
108
+ * @param dest - destination folder. Will contain an `app/cloudcode` folder after building.
109
+ * @param zipPath - path to use for creating a zip of dest.
110
+ * @param config - task config, written to config.json.
111
+ * @param options - build options.
112
+ */
113
+ async function build(src, dest, zipPath, config, options) {
114
+ const taskName = config.task;
115
+ const yarnHome = options.yarnHome;
116
+ await jetpack.dir(dest, { empty: true });
117
+ debug('copy app');
118
+ const taskSrc = path.join(src, 'cloudcode', taskName);
119
+ const taskSharedSrc = path.join(src, 'cloudcode', 'shared');
120
+ const taskPath = path.join(dest, 'app', 'cloudcode', taskName);
121
+ const destTaskPath = path.join('app', 'cloudcode', taskName);
122
+ const taskSharedPath = path.join(dest, 'app', 'cloudcode', 'shared');
123
+ // Copy base files
124
+ for (let file of ['schema.xml', 'application.xml', 'config.json', 'translations']) {
125
+ await copyBase(path.join(src, file), path.join(dest, 'app', file));
126
+ }
127
+ // Copy only CloudCode files for the specific task (including shared task files)
128
+ await copyBase(taskSrc, taskPath);
129
+ await copyBase(taskSharedSrc, taskSharedPath);
130
+ debug('build task');
131
+ const packageJson = JSON.parse(fs.readFileSync(path.join(taskPath, 'package.json'), 'utf-8'));
132
+ const packageDependencies = packageJson.dependencies || {};
133
+ const packageDevDependencies = packageJson.devDependencies || {};
134
+ const needsYarn = Object.keys(packageDependencies).length > 0 || Object.keys(packageDevDependencies).length > 0;
135
+ const hasBuild = packageJson.scripts && packageJson.scripts.build;
136
+ const isCloudCodeBuild = hasBuild && packageJson.scripts.build == 'cloudcode-build';
137
+ if (!hasBuild) {
138
+ // For tasks without a "build" script, use babel.
139
+ await transformFiles(src, 'cloudcode/' + taskName, taskPath);
140
+ await transformFiles(src, path.join('cloudcode', 'shared'), taskSharedPath);
141
+ }
142
+ else if (!isCloudCodeBuild) {
143
+ throw new error_1.BuildError(`Custom build scripts not allowed. Use \`"build": "cloudcode-build"\` in package.json.`, {
144
+ error: 'CLOUDCODE/BUILD/BUILD_FAILED'
145
+ });
146
+ }
147
+ const yarnLock = path.join(taskPath, 'yarn.lock');
148
+ if (needsYarn && !fs.existsSync(yarnLock)) {
149
+ throw new Error('yarn.lock required to install dependencies');
150
+ }
151
+ const cacheOptions = ['--cache-folder', path.join(yarnHome, 'yarn-cache')];
152
+ let args = [
153
+ 'install',
154
+ // Yarn should auto-detect that we're not in an interactive shell, but we add this to make sure.
155
+ // In interactive mode, yarn could prompt the user to select a different version if an invalid version
156
+ // was specified.
157
+ '--non-interactive',
158
+ // Ensure yarn.lock is in sync with package.json; refuse to install otherwise
159
+ '--frozen-lockfile',
160
+ // Specify cache path
161
+ ...cacheOptions
162
+ ];
163
+ let env = {
164
+ // Yarn is hardcoded to store configuration in the user's home dir.
165
+ // Since our home dir might be read-only, we override it for yarn.
166
+ HOME: yarnHome
167
+ };
168
+ try {
169
+ if (needsYarn && hasBuild) {
170
+ // We only need to do this if a build script is defined, and (dev)dependencies are defined.
171
+ debug('Installing devDependencies with yarn...');
172
+ await (0, yarn_1.runYarn)(taskPath, args, { env });
173
+ }
174
+ }
175
+ catch (err) {
176
+ throw new error_1.BuildError(err.message, {
177
+ error: 'CLOUDCODE/BUILD/YARN_DEV_FAILED',
178
+ cause: err
179
+ });
180
+ }
181
+ try {
182
+ if (isCloudCodeBuild) {
183
+ // Use @journeyapps/cloudcode-build directly.
184
+ // For security purposes, use the bundled version, not whatever the developer specified.
185
+ await cloudcodeBuild.buildTask(taskPath);
186
+ }
187
+ else if (hasBuild) {
188
+ // Custom build script.
189
+ await (0, yarn_1.runScript)(taskPath, ['run', '--quiet', 'build'], { env });
190
+ }
191
+ }
192
+ catch (err) {
193
+ throw new error_1.BuildError(err.message, {
194
+ error: 'CLOUDCODE/BUILD/BUILD_FAILED',
195
+ cause: err
196
+ });
197
+ }
198
+ try {
199
+ if (needsYarn) {
200
+ // Remove devDependencies (or install dependencies in the case of (needsYarn && !hasBuild)
201
+ debug('Installing production dependencies with yarn...');
202
+ await (0, yarn_1.runYarn)(taskPath, [...args, '--production'], { env });
203
+ }
204
+ }
205
+ catch (err) {
206
+ throw new error_1.BuildError(err.message, {
207
+ error: 'CLOUDCODE/BUILD/YARN_PROD_FAILED',
208
+ cause: err
209
+ });
210
+ }
211
+ try {
212
+ // For easier migration, we automatically add @journeyapps/cloudcode and node-fetch if it's not present in the task.
213
+ // We do this by copying our local dependency.
214
+ // Because it's installed as a link: dependency, this includes all the production sub-dependencies.
215
+ // We do this after the `yarn install --production`, to make sure yarn doesn't remove this again.
216
+ // node-fetch has no transitive dependencies, so we can just copy that as well.
217
+ const ccdest = path.join(taskPath, 'node_modules', '@journeyapps', 'cloudcode');
218
+ if (!(await jetpack.existsAsync(ccdest))) {
219
+ const localPath = path.dirname(require.resolve('@journeyapps/cloudcode/package.json'));
220
+ await jetpack.copyAsync(localPath, ccdest);
221
+ }
222
+ const fetchtest = path.join(taskPath, 'node_modules', 'node-fetch');
223
+ if (!(await jetpack.existsAsync(fetchtest))) {
224
+ // We want this as a top-level dependency.
225
+ const localPath = require.resolve('node-fetch', {
226
+ paths: [require.resolve('@journeyapps/cloudcode')]
227
+ });
228
+ await jetpack.copyAsync(localPath, fetchtest);
229
+ }
230
+ }
231
+ catch (err) {
232
+ throw new error_1.BuildError(err.message, {
233
+ error: 'CLOUDCODE/BUILD/COPY_TEMPLATE_FAILED',
234
+ cause: err
235
+ });
236
+ }
237
+ const savedConfig = {
238
+ // config contains more than this, but these are the only values we want to save
239
+ backendUrl: config.backendUrl,
240
+ appInstanceIds: config.appInstanceIds,
241
+ task: config.task,
242
+ appId: config.appId,
243
+ env: config.env
244
+ };
245
+ await jetpack.writeAsync(dest + '/config.json', JSON.stringify(savedConfig));
246
+ await createEntry(dest, destTaskPath);
247
+ debug('zip');
248
+ await zip(dest, zipPath);
249
+ return zipPath;
250
+ }
251
+ exports.build = build;
252
+ //# 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,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,CAAC,MAAM,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/D,UAAU,EAAE,QAAQ;IACpB,aAAa,EAAE,KAAK;CACrB,CAAC;AAEF,KAAK,UAAU,aAAa,CAAC,IAAY;IACvC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,KAAK,CAAC,aAAa,CAAC,IAAI,EAAE,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;YACzD,IAAI,KAAK,EAAE;gBACT,MAAM,CAAC,KAAK,CAAC,CAAC;aACf;iBAAM;gBACL,OAAO,CAAC,MAAM,CAAC,CAAC;aACjB;QACH,CAAC,CAAC,CAAC;IACL,C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;KACJ;IAED,MAAM,WAAW,GAAG;QAClB,gFAAgF;QAChF,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,cAAc,EAAE,MAAM,CAAC,cAAc;QACrC,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,GAAG,EAAE,MAAM,CAAC,GAAG;KAChB,CAAC;IAEF,MAAM,OAAO,CAAC,UAAU,CAAC,IAAI,GAAG,cAAc,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC;IAE7E,MAAM,WAAW,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IAEtC,KAAK,CAAC,KAAK,CAAC,CAAC;IACb,MAAM,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACzB,OAAO,OAAO,CAAC;AACjB,CAAC;AAzJD,sBAyJC"}
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, demandOption: true })
13
+ .option('task', { string: true, demandOption: true })
14
+ .option('yarnHome', { string: true })
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
+ },
32
+ yarnHome: argv.yarnHome
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":[],"mappings":";;;AAEA,+BAA+B;AAE/B,mCAA0C;AAE1C,KAAK;KACF,OAAO,CACN,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,uCAAuC;AACxD,YAAY,EACZ,CAAC,KAAK,EAAE,EAAE;IACR,OAAO,CACL,KAAK;SACF,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;SACnD,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;SACnD,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;SACnD,MAAM,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;SACpD,MAAM,CAAC,UAAU,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QACrC,8GAA8G;SAC7G,MAAM,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,0BAA0B,EAAE,CAAC;SAC3F,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,YA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@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.YARN_HOME = exports.TMP_PATH = void 0;
4
+ const TMP_PATH = '/tmp/cloudcode-build';
5
+ exports.TMP_PATH = TMP_PATH;
6
+ const YARN_HOME = TMP_PATH + '/yarn';
7
+ exports.YARN_HOME = YARN_HOME;
8
+ //# 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;AAG/B,4BAAQ;AAFjB,MAAM,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;AAElB,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,31 @@
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, YARN_HOME } = require('./config');
9
+ async function handle(event) {
10
+ var _a;
11
+ try {
12
+ // await jetpack.dir(TMP_PATH, { empty: true });
13
+ await jetpack.dir(TMP_PATH, {});
14
+ const appPath = event.appPath;
15
+ const outPath = event.outPath;
16
+ const zipPath = event.zipPath;
17
+ const yarnHome = (_a = event.yarnHome) !== null && _a !== void 0 ? _a : YARN_HOME;
18
+ debug('building...');
19
+ var zipFile = await (0, build_1.build)(appPath, outPath, zipPath, event.taskConfig, { yarnHome });
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
+ throw wrappedError;
28
+ }
29
+ }
30
+ exports.handle = handle;
31
+ //# 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,SAAS,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAE7C,KAAK,UAAU,MAAM,CAAC,KAAsB;;IACjD,IAAI;QACF,gDAAgD;QAChD,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAEhC,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC9B,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC9B,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC9B,MAAM,QAAQ,GAAG,MAAA,KAAK,CAAC,QAAQ,mCAAI,SAAS,CAAC;QAE7C,KAAK,CAAC,aAAa,CAAC,CAAC;QACrB,IAAI,OAAO,GAAG,MAAM,IAAA,aAAK,EAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,UAAU,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;QACrF,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,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,C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OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,YAAY,CAAC,YAAY,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,KAAK,CAAC,GAAG,SAAS,IAAI,OAAO,CAAC,GAAG,IAAI,GAAG,QAAQ,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACzE,IAAI,YAAY,GAAG,IAAA,6BAAK,EAAC,WAAW,CAAC,KAAK,EAAE,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;IAEpE,YAAY,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IACnE,YAAY,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;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.02b8c87",
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
+ }