Skip to content

Commit 53b1818

Browse files
committed
Support transformers on uploading packages
1 parent 6576cd3 commit 53b1818

4 files changed

Lines changed: 44 additions & 5 deletions

File tree

cli/commands/up.js

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const Command = require('cmnd').Command;
44
const Registry = require('../registry.js');
5+
const Transformers = require('../transformers.js');
56

67
const fs = require('fs');
78
const zlib = require('zlib');
@@ -17,7 +18,7 @@ const serviceConfig = require('../service_config');
1718

1819
const RELEASE_ENV = 'release';
1920

20-
function readFiles(base, properties, dir, data) {
21+
function readFiles (base, properties, dir, data) {
2122

2223
dir = dir || '/';
2324
data = data || [];
@@ -148,17 +149,53 @@ class UpCommand extends Command {
148149
}
149150
ignore = ignore.map(v => v.endsWith('/') ? `${v}*` : v);
150151

152+
// Load transformers
153+
let env, stdlib;
154+
155+
try {
156+
env = require(path.join(process.cwd(), 'env.json'));
157+
} catch (e) {
158+
console.error(e);
159+
console.error(new Error('Invalid env.json in this directory'));
160+
process.exit(1);
161+
}
162+
163+
try {
164+
stdlib = require(path.join(process.cwd(), 'stdlib.json'));
165+
} catch (e) {
166+
console.error(e);
167+
console.error(new Error('Invalid stdlib.json in this directory'));
168+
process.exit(1);
169+
}
170+
171+
const transformers = new Transformers(env, stdlib, environment);
172+
let preloadFiles = transformers.compile();
173+
151174
let data = readFiles(
152175
process.cwd(),
153-
{ignore: ignore}
176+
{ignore: ignore},
154177
);
155178

179+
data.forEach(file => {
180+
if (preloadFiles[file.filename]) {
181+
throw new Error(
182+
`Error with file "${file.filename}":` +
183+
`This file was preloaded as part of a transformer, ` +
184+
`it can not be overwritten.`
185+
);
186+
}
187+
});
188+
189+
Object.keys(preloadFiles).forEach(filename => {
190+
data.push({filename: filename, buffer: preloadFiles[filename]});
191+
});
192+
156193
// pipe the pack stream to your file
157194
pack.pipe(tarball);
158195

159196
// Run everything in parallel...
160197

161-
async.parallel(data.map((file) => {
198+
async.parallel(data.map(file => {
162199
return (callback) => {
163200
pack.entry({name: file.filename}, file.buffer, callback);
164201
};

cli/local_http.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ if (cluster.isMaster) {
2424

2525
} else {
2626

27+
let env, stdlib;
28+
2729
try {
2830
env = require(path.join(process.cwd(), 'env.json'));
2931
} catch (e) {
@@ -41,7 +43,6 @@ if (cluster.isMaster) {
4143
}
4244

4345
const transformers = new Transformers(env, stdlib, 'local');
44-
transformers.load();
4546

4647
// Cluster to Gateway
4748
let gateway = new LocalGateway({

cli/transformers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class Transformers {
77
this.stdlib = stdlib;
88
this.environment = environment;
99
this.list = [];
10+
this.load();
1011
}
1112

1213
load () {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lib.cli",
3-
"version": "5.4.0",
3+
"version": "5.5.0",
44
"description": "Command Line tools for Autocode - autocode.com",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)