Skip to content

Commit

Permalink
update template cache strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
zoumiaojiang committed Jun 30, 2017
1 parent 2f6b6ba commit ce19452
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# lavas-scaffold (Lavas 工程化解决方案脚手架解决方案)
# lavas-scaffold

安装
> Lavas 工程化解决方案脚手架解决方案
### 安装

```bash
npm install --save lavas-scaffold
```

API
### API

lavas-scaffold 提供两个 Promise 接口

Expand All @@ -23,6 +25,7 @@ const result = await lavasScaffold.exports(fields, [isStream]);

> Note
>
> fileds 的值为通过 fieldSchema 的约定而搜集的字段参数,一般在用户界面搜集用户自定义输入。
> isStream 是指定产物,当值为 true 的时候,产物为 zip 包的 readFileStream , 当值为 false 的时候,返回导出工程文件夹的 path
> fileds: fileds 的值为通过 fieldSchema 的约定而搜集的字段参数,一般在用户界面搜集用户自定义输入。
>
> isStream: 是指定产物形态,当值为 true 的时候,产物为 zip 包的 readStream,当值为 false 的时候,返回导出工程文件夹的 path
21 changes: 3 additions & 18 deletions lib/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,13 @@ let downloadFromGit = function (repo, targetPath) {

return new Promise((resolve, reject) => {

// 如果当前文件系统有 download 的缓存,就不立即下载了。我们走后台默默更新就好了
// 如果当前文件系统有 download 的缓存,就不重新 clone 了,将代码直接 pull 下来就好了
if (fs.existsSync(targetPath)) {
resolve(targetPath);
let timer = setTimeout(() => {
const tmpTarget = path.resolve(targetPath, '..', '__tmp');
if (fs.existsSync(tmpTarget)) {
fs.removeSync(tmpTarget);
}
git().clone(repo, tmpTarget, {}, () => {
fs.removeSync(targetPath);
fs.copySync(tmpTarget, targetPath);
fs.removeSync(tmpTarget);
clearTimeout(timer);
});
});

git(targetPath).pull((err, updates) => resolve(targetPath));
}
else {
fs.mkdirsSync(targetPath);
git().clone(repo, targetPath, {}, () => {
resolve(targetPath);
});
git().clone(repo, targetPath, {}, () => resolve(targetPath));
}
});
};
Expand Down

0 comments on commit ce19452

Please sign in to comment.