deploy: ActionQueue interfaces use strings instead of Path objects

This commit is contained in:
Christopher Monsanto 2020-08-10 05:29:06 -04:00
parent 830c0fadfc
commit 1d9d10cf63
3 changed files with 12 additions and 12 deletions

View File

@ -34,7 +34,7 @@ program
const src = pathlib.path(file);
const output = script.runOnFile(scr, src);
const dst = pathlib.join(outputDir, output);
aq.copy(src, dst);
aq.copy(pathlib.format(src), pathlib.format(dst));
}
if (act) {

View File

@ -14,8 +14,8 @@ test('run identity', () => {
const scr = new script.Script(` list(".").forEach(p => copy(p, p))`, 'expr');
script.run(scr, "testsrc", aq);
expect(aq.describe()).toEqual(expect.arrayContaining([
{src: pathlib.path('testsrc/32.png'), dst: pathlib.path("./32.png")},
{src: pathlib.path('testsrc/192-g-vsmogon.png'), dst: pathlib.path("./192-g-vsmogon.png")},
{src: 'testsrc/32.png', dst: "./32.png"},
{src: 'testsrc/192-g-vsmogon.png', dst: "./192-g-vsmogon.png"},
]));
});

View File

@ -6,40 +6,40 @@ import * as pathlib from './path.js';
import * as spritename from './spritename.js';
export class ActionQueue {
private queue: {src : pathlib.Path, dst : pathlib.Path}[];
private queue: {src : string, dst : string}[];
constructor() {
this.queue = [];
}
copy(src : pathlib.Path, dst : pathlib.Path) {
copy(src : string, dst : string) {
// TODO: detect conflicts
this.queue.push({src, dst});
}
describe() : {src : pathlib.Path, dst : pathlib.Path}[] {
describe() : {src : string, dst : string}[] {
return this.queue;
}
join(dir : string) {
for (const pair of this.queue) {
pair.dst = pathlib.join(dir, pair.dst);
pair.dst = nodePath.join(dir, pair.dst);
}
}
print() {
for (const {src, dst} of this.queue) {
console.log(`${pathlib.format(src)} ==> ${pathlib.format(dst)}`);
console.log(`${src} ==> ${dst}`);
}
}
run(mode : 'link' | 'copy') {
for (const {src, dst} of this.queue) {
fs.mkdirSync(dst.dir, {recursive: true});
fs.mkdirSync(nodePath.dirname(dst), {recursive: true});
if (mode === 'link') {
fs.linkSync(pathlib.format(src), pathlib.format(dst));
fs.linkSync(src, dst);
} else {
fs.copyFileSync(pathlib.format(src), pathlib.format(dst));
fs.copyFileSync(src, dst);
}
}
}
@ -82,7 +82,7 @@ function makeEnv(srcDir : string, queue: ActionQueue) {
copy(src : pathlib.PathLike, dst : pathlib.PathLike) {
const srcp = pathlib.path(src);
const dstp = pathlib.path(dst);
queue.copy(pathlib.join(srcDir, srcp), dstp);
queue.copy(pathlib.format(pathlib.join(srcDir, srcp)), pathlib.format(dstp));
}
}
}