-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
46 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,22 @@ | ||
import addFile from './addFile'; | ||
import unlinkFile from './unlinkFile'; | ||
import getFiles from "./getFiles"; | ||
import fse from "fs-extra"; | ||
|
||
export default async function changeFile(path) { | ||
await unlinkFile(path); | ||
await addFile(path); | ||
let oldFiles = []; | ||
if(path.endsWith('.js')) { | ||
oldFiles = await getFiles(path); | ||
} | ||
let newFiles = await addFile(path); | ||
|
||
//删除冗余文件 | ||
getDeleteFiles(oldFiles, newFiles).map(async (file) => { | ||
fse.remove(file).catch((err) => console.log(err)); | ||
}); | ||
} | ||
|
||
function getDeleteFiles(oldFiles, newFiles) { | ||
return oldFiles.filter((v) => { | ||
return newFiles.indexOf(v) > -1 ? false : true; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import fse from "fs-extra"; | ||
const path = require('path'); | ||
|
||
export default async function getFiles(targetPath, suffix) { | ||
const targetdir = path.dirname(targetPath); | ||
const noSuffix = targetPath.substring(0, targetPath.lastIndexOf(suffix)); | ||
const suffixs = ['.json', '.wxss', '.js', '.comp.js', '.wxml']; | ||
const allFiles = suffixs.map((item) => { | ||
return noSuffix + item; | ||
}); | ||
allFiles.push(noSuffix + 'Template.wxml'); | ||
await fse.readdir(targetdir).then((files) => { | ||
files.forEach((fileName) => { | ||
if (fileName.indexOf(noSuffix.substring(noSuffix.lastIndexOf('/') + 1) + 'ICNP') === 0) { | ||
allFiles.push(path.resolve(targetdir, fileName)); | ||
} | ||
|
||
}); | ||
}); | ||
|
||
return allFiles.map((file) => { | ||
return fse.existsSync(file); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters