From 737d30c99dc5533de5286de79146ebec3b84c24c Mon Sep 17 00:00:00 2001 From: lcxfs1991 Date: Thu, 10 May 2018 13:00:22 +0800 Subject: [PATCH] fix writeKitOption issue --- CHANGELOG.md | 3 +++ index.js | 20 +++++++++++--------- package.json | 2 +- test/test.js | 5 ++++- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aaaa72a..6108077 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 3.0.0-beta.7 + - 修复writeKitOpionts错误 + ## 3.0.0-beta.6 - 尝试修复cloneLatest报错无法写入kitOption的问题 diff --git a/index.js b/index.js index 43a22f4..9294cc3 100755 --- a/index.js +++ b/index.js @@ -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, @@ -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) { diff --git a/package.json b/package.json index 26759bf..97fef6e 100755 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/test.js b/test/test.js index 04c255b..bc7af36 100755 --- a/test/test.js +++ b/test/test.js @@ -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() { @@ -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); }); @@ -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,