Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
Feverqwe committed Sep 20, 2023
1 parent c37411e commit bb299fd
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/utils/pluginEnvApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ class PluginEnvApi {
const to = safeRelativePath(rawTo);

this.asyncActionQueue.push({type: AsyncActionType.Copy, from, to});
if (this.cacheFile) {
this.cacheFile.addCopyFile({from, to});
}
}

readFile<T extends BufferEncoding>(rawTarget: string, encoding: T) {
Expand Down Expand Up @@ -99,9 +96,6 @@ class PluginEnvApi {
const to = safeRelativePath(rawTo);

this.asyncActionQueue.push({type: AsyncActionType.Write, to, data});
if (this.cacheFile) {
this.cacheFile.addWriteFile(to, data);
}
}

getFileVars(rawTarget: string) {
Expand All @@ -115,7 +109,9 @@ class PluginEnvApi {
}

executeActions() {
this.asyncActionQueue.splice(0).forEach((action) => {
const {asyncActionQueue} = this;

asyncActionQueue.splice(0).forEach((action) => {
switch (action.type) {
case AsyncActionType.Copy: {
const {from, to} = action;
Expand All @@ -124,6 +120,9 @@ class PluginEnvApi {

fs.mkdirSync(path.dirname(fullTo), {recursive: true});
fs.copyFileSync(fullFrom, fullTo);
if (this.cacheFile) {
this.cacheFile.addCopyFile({from, to});
}
break;
}
case AsyncActionType.Write: {
Expand All @@ -132,6 +131,9 @@ class PluginEnvApi {

fs.mkdirSync(path.dirname(fullTo), {recursive: true});
fs.writeFileSync(fullTo, data);
if (this.cacheFile) {
this.cacheFile.addWriteFile(to, data);
}
break;
}
}
Expand All @@ -150,6 +152,9 @@ class PluginEnvApi {

await fs.promises.mkdir(path.dirname(fullTo), {recursive: true});
await fs.promises.copyFile(fullFrom, fullTo);
if (this.cacheFile) {
this.cacheFile.addCopyFile({from, to});
}
break;
}
case AsyncActionType.Write: {
Expand All @@ -158,6 +163,9 @@ class PluginEnvApi {

await fs.promises.mkdir(path.dirname(fullTo), {recursive: true});
await fs.promises.writeFile(fullTo, data);
if (this.cacheFile) {
this.cacheFile.addWriteFile(to, data);
}
break;
}
}
Expand Down

0 comments on commit bb299fd

Please sign in to comment.