cli/src/squeebot.ts

83 lines
2.5 KiB
JavaScript

#!/usr/bin/env node
import yargs from 'yargs';
import { newEnvironment } from './build/environment';
import { buildRepository } from './build/repository/build';
import { newRepository } from './build/repository/create';
import { watchRepository } from './build/watch';
const yar = yargs.scriptName('squeebot')
.command('new [name] [path]', 'create a new Squeebot environment', (y) => {
y.positional('name', {
describe: 'The name of the new environment',
})
.positional('path', {
describe: 'The path to create a new Squeebot environment at (default: working directory)',
});
}, (v) => newEnvironment(v.name as string, v.path as string))
.command('repository', 'manage repositories', (y) => {
y.command('new [name] [path]', 'create a new repository', (yi) => {
yi.positional('name', {
demandOption: 'The repository requires a name',
describe: 'The name of the new repository',
})
.positional('path', {
describe: 'The path to create the new Squeebot plugin repository at (default: working directory)',
})
.option('t', {
alias: 'no-typescript',
describe: 'Do not include TypeScript in the development environment',
type: 'boolean',
});
}, (v) => newRepository(v.name as string, v.path as string, v.t !== true));
y.command('build [path]', 'build a repository of plugins and generate the index file', (yi) => {
yi.positional('path', {
describe: 'The path of the repository',
})
.option('p', {
alias: 'no-output',
describe: 'Do not create an output directory, just build',
type: 'boolean',
})
.option('d', {
alias: 'deploy',
describe: 'Deploy the output directory as configured',
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) => {
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,
);
}
buildRepository(
dargs[0] as string,
dargs[1] as boolean,
dargs[2] as string,
dargs[3] as boolean,
);
});
})
.argv;