add watcher
This commit is contained in:
parent
df17cb9cba
commit
2ed151ac51
15
package-lock.json
generated
15
package-lock.json
generated
@ -33,6 +33,7 @@
|
||||
"@squeebot/core": {
|
||||
"version": "file:../core",
|
||||
"requires": {
|
||||
"dateformat": "^4.0.0",
|
||||
"fs-extra": "^9.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
@ -145,6 +146,11 @@
|
||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
|
||||
},
|
||||
"dateformat": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/dateformat/-/dateformat-4.0.0.tgz",
|
||||
"integrity": "sha512-zpKyDYpeePyYGJp2HhRxLHlA+jZQNjt+MwmcVmLxCIECeC4Ks3TI3yk/CSMKylbnCJ5htonfOugYtRRTpyoHow=="
|
||||
},
|
||||
"diff": {
|
||||
"version": "4.0.2",
|
||||
"resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz",
|
||||
@ -399,6 +405,7 @@
|
||||
"version": "15.0.10",
|
||||
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.10.tgz",
|
||||
"integrity": "sha512-z8PNtlhrj7eJNLmrAivM7rjBESG6JwC5xP3RVk12i/8HVP7Xnx/sEmERnRImyEuUaJfO942X0qMOYsoupaJbZQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/yargs-parser": "*"
|
||||
}
|
||||
@ -406,7 +413,8 @@
|
||||
"@types/yargs-parser": {
|
||||
"version": "15.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-15.0.0.tgz",
|
||||
"integrity": "sha512-FA/BWv8t8ZWJ+gEOnLLd8ygxH/2UFbAvgEonyfN6yWGLKc7zVjbpl2Y4CTjid9h2RfgPP6SEt6uHwEOply00yw=="
|
||||
"integrity": "sha512-FA/BWv8t8ZWJ+gEOnLLd8ygxH/2UFbAvgEonyfN6yWGLKc7zVjbpl2Y4CTjid9h2RfgPP6SEt6uHwEOply00yw==",
|
||||
"dev": true
|
||||
},
|
||||
"ansi-regex": {
|
||||
"version": "5.0.0",
|
||||
@ -682,6 +690,11 @@
|
||||
"minimist": "^1.2.5"
|
||||
}
|
||||
},
|
||||
"node-watch": {
|
||||
"version": "0.7.0",
|
||||
"resolved": "https://registry.npmjs.org/node-watch/-/node-watch-0.7.0.tgz",
|
||||
"integrity": "sha512-OOBiglke5SlRQT5WYfwXTmYqTfXjcTNBHpalyHLtLxDpQYVpVRkJqabcch1kmwJsjV/J4OZuzEafeb4soqtFZA=="
|
||||
},
|
||||
"once": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||
|
@ -29,6 +29,7 @@
|
||||
"dependencies": {
|
||||
"@squeebot/core": "file:../core",
|
||||
"fs-extra": "^9.0.1",
|
||||
"node-watch": "^0.7.0",
|
||||
"yargs": "^16.1.1"
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import child_process from 'child_process';
|
||||
import fs from 'fs-extra';
|
||||
import watch from 'node-watch';
|
||||
import path from 'path';
|
||||
import readline from 'readline';
|
||||
import yargs from 'yargs';
|
||||
@ -282,6 +283,52 @@ async function buildRepository(
|
||||
deploy(meta.name, location, outDir, doDeploy);
|
||||
}
|
||||
|
||||
async function watchRepository(
|
||||
location?: string,
|
||||
out = true,
|
||||
doDeploy?: string,
|
||||
onlyDeploy = false): void {
|
||||
|
||||
if (!location) {
|
||||
location = process.cwd();
|
||||
}
|
||||
|
||||
const buildMetaFile = path.join(location, 'squeebot.repo.json');
|
||||
if (!await fs.pathExists(buildMetaFile)) {
|
||||
throw new Error(`${location} is not a valid squeebot repository development environment!`);
|
||||
}
|
||||
|
||||
const meta = await fs.readJson(buildMetaFile);
|
||||
if (!meta.name) {
|
||||
throw new Error(`${location} is not a valid squeebot repository development environment!`);
|
||||
}
|
||||
|
||||
console.log('Watching repository "%s"!', meta.name);
|
||||
|
||||
watch(location, {
|
||||
recursive: true,
|
||||
filter(f, skip): any {
|
||||
if (/\/node_modules/.test(f) ||
|
||||
/\.out/.test(f) ||
|
||||
/\.git/.test(f) ||
|
||||
/\.json$/.test(f)) {
|
||||
return skip;
|
||||
}
|
||||
|
||||
if (meta.typescript && /\.js$/.test(f)) {
|
||||
return skip;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
}, (evt, f) => {
|
||||
console.log(`\n ==> ${f} changed, rebuilding...`);
|
||||
buildRepository(location, out, doDeploy, onlyDeploy).catch((e) => {
|
||||
console.error(e);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const yar = yargs.scriptName('squeebot')
|
||||
.command('new [name] [path]', 'create a new Squeebot environment', (y) => {
|
||||
y.positional('name', {
|
||||
@ -321,14 +368,39 @@ const yar = yargs.scriptName('squeebot')
|
||||
nargs: 1,
|
||||
type: 'string',
|
||||
})
|
||||
.option('w', {
|
||||
alias: 'watch',
|
||||
describe: 'Watch files for changes',
|
||||
type: 'boolean',
|
||||
})
|
||||
.option('o', {
|
||||
alias: 'deploy-only',
|
||||
describe: 'Deploy only, without rebuilding',
|
||||
type: 'boolean',
|
||||
});
|
||||
}, (v) => buildRepository(v.path as string,
|
||||
v.p !== true,
|
||||
v.d as string,
|
||||
v.o === true));
|
||||
}, (v) => {
|
||||
const dargs = [
|
||||
v.path,
|
||||
v.p !== true,
|
||||
v.d,
|
||||
v.o === true,
|
||||
];
|
||||
|
||||
if (v.w) {
|
||||
return watchRepository(
|
||||
dargs[0] as string,
|
||||
dargs[1] as boolean,
|
||||
dargs[2] as string,
|
||||
dargs[3] as boolean,
|
||||
);
|
||||
}
|
||||
|
||||
buildRepository(
|
||||
dargs[0] as string,
|
||||
dargs[1] as boolean,
|
||||
dargs[2] as string,
|
||||
dargs[3] as boolean,
|
||||
);
|
||||
});
|
||||
})
|
||||
.argv;
|
||||
|
Loading…
Reference in New Issue
Block a user