mirror of
https://github.com/smogon/sprites.git
synced 2026-09-09 18:45:39 -05:00
deploy/script: factor out more cli logic into runOnFile
This commit is contained in:
@@ -36,12 +36,7 @@ program
|
||||
|
||||
for (const file of files) {
|
||||
const src = pathlib.path(file);
|
||||
const input = pathlib.update(src, {dir: ""});
|
||||
const result = scr.runOnFile(input);
|
||||
if (result === undefined) {
|
||||
throw new Error(`undefined output on ${file}`);
|
||||
}
|
||||
const output = pathlib.path(input, result);
|
||||
const output = scr.runOnFile(src);
|
||||
const dst = pathlib.join(outputDir, output);
|
||||
aq.copy(src, dst);
|
||||
}
|
||||
|
||||
@@ -2,17 +2,10 @@
|
||||
import * as pathlib from './path.js';
|
||||
import * as script from './script.js';
|
||||
|
||||
test('aq', () => {
|
||||
const aq = new script.ActionQueue();
|
||||
const src = pathlib.path('/foo/bar/pikachu.png');
|
||||
const input = pathlib.update(src, {dir: ""});
|
||||
test('correct output', () => {
|
||||
const scr = new script.Script('({name: "25"})');
|
||||
const result = scr.runOnFile(input);
|
||||
const output = pathlib.path(input, result);
|
||||
const dst = output;
|
||||
aq.copy(src, dst);
|
||||
|
||||
expect(aq.describe()).toEqual([{src: pathlib.path('/foo/bar/pikachu.png'),
|
||||
dst: pathlib.path('25.png')}]);
|
||||
const src = pathlib.path('/foo/bar/pikachu.png');
|
||||
const dst = scr.runOnFile(src);
|
||||
expect(dst).toEqual(pathlib.path('25.png'));
|
||||
});
|
||||
|
||||
|
||||
@@ -64,8 +64,18 @@ export class Script {
|
||||
this.script = new vm.Script(code);
|
||||
}
|
||||
|
||||
runOnFile(p : pathlib.Path) : any {
|
||||
return this.script.runInNewContext({spritename: _spritename, path: p, ...p});
|
||||
runOnFile(src : pathlib.Path) : pathlib.Path {
|
||||
const input = pathlib.update(src, {dir: ""});
|
||||
const result = this.script.runInNewContext({
|
||||
spritename: _spritename,
|
||||
path: input,
|
||||
...input
|
||||
});
|
||||
if (result === undefined) {
|
||||
throw new Error(`undefined output on ${pathlib.format(src)}`);
|
||||
}
|
||||
const output = pathlib.path(input, result);
|
||||
return output;
|
||||
}
|
||||
|
||||
run(srcDir : string, dstDir : string, queue : ActionQueue) {
|
||||
|
||||
Reference in New Issue
Block a user