mirror of
https://github.com/smogon/sprites.git
synced 2026-08-27 04:06:43 -05:00
deploy/script: add skip()
This commit is contained in:
@@ -132,9 +132,16 @@ export class Script extends vm.Script {
|
||||
}
|
||||
}
|
||||
|
||||
const SKIP = {};
|
||||
|
||||
const ENV_PROTO = {
|
||||
spritename,
|
||||
spritedata
|
||||
spritedata,
|
||||
SKIP,
|
||||
// Because throw SKIP isn't an expression
|
||||
skip() {
|
||||
throw SKIP;
|
||||
}
|
||||
};
|
||||
|
||||
function makeEnv(srcDir : string, queue: ActionQueue) {
|
||||
@@ -181,6 +188,7 @@ export function runOnFile(scr : Script, src : string, queue: ActionQueue) {
|
||||
const dst = pathlib.format(output);
|
||||
queue.copy(src, dst);
|
||||
} catch(e) {
|
||||
if (e === SKIP) return;
|
||||
queue.throw(e);
|
||||
}
|
||||
}
|
||||
@@ -189,6 +197,7 @@ export function run(scr : Script, srcDir : string, queue : ActionQueue) {
|
||||
try {
|
||||
scr.runInNewContext(makeEnv(srcDir, queue));
|
||||
} catch(e) {
|
||||
if (e === SKIP) return;
|
||||
queue.throw(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,11 @@ it('aq', () => {
|
||||
});
|
||||
|
||||
it('runOnFile', () => {
|
||||
const scr = new script.Script('({name: "25"})', 'expr');
|
||||
const scr = new script.Script('name === "rhydont" ? skip() : {name: "25"}', 'expr');
|
||||
const aq = new script.ActionQueue();
|
||||
script.runOnFile(scr, '/foo/bar/pikachu.png', aq);
|
||||
script.runOnFile(scr, '/foo/bar/rhydont.png', aq);
|
||||
expect(aq.log.length).toBe(1);
|
||||
expect(aq.log).toEqual(expect.arrayContaining([
|
||||
{type: 'Copy', src: '/foo/bar/pikachu.png', dst: "25.png", valid: 'Success', debugObjs: []},
|
||||
]));
|
||||
|
||||
Reference in New Issue
Block a user