Initial commit
This commit is contained in:
64
build.ts
Normal file
64
build.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Remove old files, copy front-end ones.
|
||||
*/
|
||||
|
||||
import fs from 'fs-extra';
|
||||
import logger from 'jet-logger';
|
||||
import childProcess from 'child_process';
|
||||
|
||||
|
||||
/**
|
||||
* Start
|
||||
*/
|
||||
(async () => {
|
||||
try {
|
||||
// Remove current build
|
||||
await remove('./dist/');
|
||||
// Copy front-end files
|
||||
await copy('./src/public', './dist/public');
|
||||
await copy('./src/views', './dist/views');
|
||||
// Copy back-end files
|
||||
await exec('tsc --build tsconfig.prod.json', './');
|
||||
} catch (err) {
|
||||
logger.err(err);
|
||||
}
|
||||
})();
|
||||
|
||||
/**
|
||||
* Remove file
|
||||
*/
|
||||
function remove(loc: string): Promise<void> {
|
||||
return new Promise((res, rej) => {
|
||||
return fs.remove(loc, (err) => {
|
||||
return (!!err ? rej(err) : res());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy file.
|
||||
*/
|
||||
function copy(src: string, dest: string): Promise<void> {
|
||||
return new Promise((res, rej) => {
|
||||
return fs.copy(src, dest, (err) => {
|
||||
return (!!err ? rej(err) : res());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Do command line command.
|
||||
*/
|
||||
function exec(cmd: string, loc: string): Promise<void> {
|
||||
return new Promise((res, rej) => {
|
||||
return childProcess.exec(cmd, {cwd: loc}, (err, stdout, stderr) => {
|
||||
if (!!stdout) {
|
||||
logger.info(stdout);
|
||||
}
|
||||
if (!!stderr) {
|
||||
logger.warn(stderr);
|
||||
}
|
||||
return (!!err ? rej(err) : res());
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user