From 10c0ddd27d8e09fc680be8c65c5c22fe74de78c8 Mon Sep 17 00:00:00 2001 From: Christopher Monsanto Date: Sun, 9 Aug 2020 06:06:21 -0400 Subject: [PATCH] deploy: deploy -> run --- tools/deploy/deploy.ts | 15 --------------- tools/deploy/find.ts | 20 -------------------- tools/deploy/index.ts | 37 +++++++++++++++---------------------- 3 files changed, 15 insertions(+), 57 deletions(-) delete mode 100644 tools/deploy/deploy.ts delete mode 100644 tools/deploy/find.ts diff --git a/tools/deploy/deploy.ts b/tools/deploy/deploy.ts deleted file mode 100644 index 33e38aa0..00000000 --- a/tools/deploy/deploy.ts +++ /dev/null @@ -1,15 +0,0 @@ - -import fs from 'fs'; -import pathlib from 'path'; - -export function link(pairs : {src : string, dst : string}[], dstDir : string, mode : 'link' | 'copy') { - for (let {src, dst} of pairs) { - dst = pathlib.join(dstDir, dst); - fs.mkdirSync(pathlib.dirname(dst), {recursive: true}); - if (mode === 'link') { - fs.linkSync(src, dst); - } else { - fs.copyFileSync(src, dst); - } - } -} diff --git a/tools/deploy/find.ts b/tools/deploy/find.ts deleted file mode 100644 index 8084bffb..00000000 --- a/tools/deploy/find.ts +++ /dev/null @@ -1,20 +0,0 @@ - -import fs from 'fs'; -import pathlib from 'path'; - -export function find(startDir : string, tag : string) { - const stack = [startDir]; - const results = []; - let dir; - while (dir = stack.pop()) { - for (const name of fs.readdirSync(dir)) { - const path = pathlib.join(dir, name); - if (fs.lstatSync(path).isDirectory()) { - stack.push(path); - } else if (name === `${tag}.deploy.js`) { - results.push(path); - } - } - } - return results; -} diff --git a/tools/deploy/index.ts b/tools/deploy/index.ts index c81cce47..6c512a76 100644 --- a/tools/deploy/index.ts +++ b/tools/deploy/index.ts @@ -1,10 +1,8 @@ import program from 'commander'; -import {run} from './lang.js'; -import {find} from './find.js'; -import {link} from './deploy.js'; import * as script from './script.js'; import * as pathlib from './path.js'; +import nodePath from 'path'; import fs from 'fs'; function collect(value : string, previous : string[]) { @@ -49,27 +47,22 @@ program }); program - .command('deploy ') - .option('-d, --dir [dir]', 'Directory') - .action((tag : string, outputDir : string, opts) => { - const dir = opts.dir || '.'; - const results = run(find(dir, tag)); - link(results, outputDir, 'link'); - }); + .command('run [scripts...]') + .requiredOption('-o, --output ', 'Output directory') + .option('-n, --no-act', 'No act') + .action((scripts : string[], {output: outputDir, act}) => { + const aq = new script.ActionQueue; -program - .command('print ') - .option('-d, --dir [dir]', 'Directory') - .option('--json', 'As JSON') - .action((tag : string, opts) => { - const dir = opts.dir || '.'; - const results = run(find(dir, tag)); - if (opts.json) { - process.stdout.write(JSON.stringify(results, null, ' ') + "\n"); + for (const file of scripts) { + const code = fs.readFileSync(file, 'utf8'); + const scr = new script.Script(code); + scr.run(nodePath.dirname(file), outputDir, aq); + } + + if (act) { + aq.run('link'); } else { - for (const {src, dst} of results) { - console.log(`${src} ==> ${dst}`); - } + aq.print(); } });