deploy: use actionqueue/script for copy cli

This commit is contained in:
Christopher Monsanto 2020-07-28 14:38:34 -04:00
parent 49c5f5a873
commit e5812e2da0
2 changed files with 13 additions and 25 deletions

View File

@ -1,22 +0,0 @@
import fs from 'fs';
import vm from 'vm';
import * as pathlib from './path.js';
export function imp(files: string[], code : string) {
const script = new vm.Script(code);
const results = [];
for (const file of files) {
const parsed = pathlib.parse(file);
const delta = script.runInNewContext({path: parsed, ...parsed});
if (delta) {
const result = pathlib.path(parsed, delta);
const dest = pathlib.format(result);
results.push({src: file, dst: dest});
} else {
throw new Error(`result of eval on ${file} falsy`);
}
}
return results;
}

View File

@ -3,7 +3,8 @@ import program from 'commander';
import {run} from './lang.js';
import {find} from './find.js';
import {link} from './deploy.js';
import {imp} from './import.js';
import * as script from './script.js';
import * as pathlib from './path.js';
import fs from 'fs';
function collect(value : string, previous : string[]) {
@ -27,8 +28,17 @@ program
throw new Error(`one of -e or -m must be provided`);
}
const result = imp(files, code);
link(result, outputDir, 'copy');
const aq = new script.ActionQueue;
const scr = new script.Script(code);
for (const file of files) {
const src = pathlib.path(file);
const dst = pathlib.path(src, scr.runOnFile(src));
aq.copy(src, dst);
}
// TODO: output
aq.run('copy');
});
program