Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: copy after build #10

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function run() {

const child = forkTsc(tscArgs, {
cwd,
onFirstCompileSuccess: () => {
onFirstWatchCompileSuccess: () => {
// copy non-ts files
copyFilesRecursive(
path.join(cwd, sourceDir),
Expand Down Expand Up @@ -106,12 +106,19 @@ function run() {
);
}
},
onCompileSuccess: () => {
onWatchCompileSuccess: () => {
restart();
},
onCompileFail: () => {
onWatchCompileFail: () => {
restart.clear();
},
onCompileSuccess: () => {
copyFilesRecursive(
path.join(cwd, sourceDir),
path.join(cwd, outDir),
allowJs
);
},
});

async function onSignal() {
Expand Down
18 changes: 13 additions & 5 deletions lib/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ const isWin = process.platform === 'win32';
*
* @param {*} tscArgs
* @param {*} options
* options.onFirstCompileSuccess
* options.onFirstWatchCompileSuccess
* options.onWatchCompileSuccess
* options.onWatchCompileFail
* options.onCompileSuccess
* options.onCompileFail
* @returns
*/
const forkTsc = (tscArgs = [], options = {}) => {
Expand All @@ -24,7 +25,7 @@ const forkTsc = (tscArgs = [], options = {}) => {
// has error
console.log(data);
// 如果已经启动了,则传递成功消息给子进程
options.onCompileFail && options.onCompileFail();
options.onWatchCompileFail && options.onWatchCompileFail();
} else {
console.log(data);
/**
Expand All @@ -35,15 +36,22 @@ const forkTsc = (tscArgs = [], options = {}) => {
if (!firstStarted) {
firstStarted = true;
// emit start
options.onFirstCompileSuccess && options.onFirstCompileSuccess();
options.onFirstWatchCompileSuccess &&
options.onFirstWatchCompileSuccess();
} else {
// 如果已经启动了,则传递成功消息给子进程
options.onCompileSuccess && options.onCompileSuccess();
options.onWatchCompileSuccess && options.onWatchCompileSuccess();
}
}
}
});

child.on('exit', (code, signal) => {
if (code === 0) {
options.onCompileSuccess && options.onCompileSuccess();
}
});

return child;
};

Expand Down