Skip to content

Commit

Permalink
fix writeKitOption issue
Browse files Browse the repository at this point in the history
  • Loading branch information
lcxfs1991 committed May 10, 2018
1 parent c28cbe8 commit 737d30c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 3.0.0-beta.7
- 修复writeKitOpionts错误

## 3.0.0-beta.6
- 尝试修复cloneLatest报错无法写入kitOption的问题

Expand Down
20 changes: 11 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ class KitPlugin extends SteamerPlugin {
}
else {
if (!this.kitOptions.list.hasOwnProperty(kitName)) {

// if the repo is not in config, but repo localPath exist, delete it and reinstall
if (this.fs.existsSync(localPath)) {
this.fs.removeSync(localPath);
}

this.kitOptions.list[kitName] = {
url: repo,
path: localPath,
Expand Down Expand Up @@ -675,18 +681,14 @@ class KitPlugin extends SteamerPlugin {
/**
* write starterkit options
* @param {Object} options starter kit options
* @param {String} key starterkit name
*/
writeKitOptions(options, key) {
writeKitOptions(options = {}) {
try {
let updatedOptions = this.getKitOptions();
// let updatedOptions = this.getKitOptions();

if (key) {
updatedOptions.list[key] = options.list[key];
}

updatedOptions.timestamp = Date.now();
this.fs.writeFileSync(this.kitOptionsPath, `module.exports = ${JSON.stringify(updatedOptions, null, 4)};`, 'utf-8');
// updatedOptions.timestamp = Date.now();
this.fs.ensureFileSync(this.kitOptionsPath);
this.fs.writeFileSync(this.kitOptionsPath, `module.exports = ${JSON.stringify(options, null, 4)};`, 'utf-8');

}
catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "steamer-plugin-kit",
"version": "3.0.0-beta.6",
"version": "3.0.0-beta.7",
"description": "steamer-plugin-kit",
"main": "index.js",
"bin": "index.js",
Expand Down
5 changes: 4 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ describe('add starterkit', function() {
if (!fs.existsSync(kitOptionsPath)) {
fs.ensureFileSync(kitOptionsPath);
}

return kitOptions;
});
let kitStub = sinon.stub(kit, "clone").usingPromise(bluebird.Promise).resolves().callsFake(function() {
Expand All @@ -132,9 +133,9 @@ describe('add starterkit', function() {
kit.init();

setTimeout(() => {
kitGetKitOptionsStub.restore();
expect(kit.getKitOptions()).to.eql(kitOptions);
kitStub.restore();
kitGetKitOptionsStub.restore();
cb();
}, 100);
});
Expand Down Expand Up @@ -223,6 +224,8 @@ describe('add starterkit', function() {
}

if (execTime === 1) {
kit.kitOptions.list['steamer-example1'].url = repoUrl;
kit.kitOptions.list['steamer-example1'].path = localPath;
expect(kit.kitOptions.list).to.eql({
'steamer-example1': {
url: repoUrl,
Expand Down

0 comments on commit 737d30c

Please sign in to comment.