@sprucelabs/spruce-cli 14.27.0 → 14.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/build/__tests__/behavioral/UpgradingANodeModule.test.d.ts +1 -0
- package/build/__tests__/behavioral/UpgradingANodeModule.test.js +50 -3
- package/build/__tests__/behavioral/UpgradingANodeModule.test.js.map +1 -1
- package/build/features/node/NodeFeature.d.ts +1 -0
- package/build/features/node/NodeFeature.js +83 -64
- package/build/features/node/NodeFeature.js.map +1 -1
- package/build/features/node/actions/UpgradeAction.js +20 -9
- package/build/features/node/actions/UpgradeAction.js.map +1 -1
- package/build/features/node/writers/NodeWriter.d.ts +5 -2
- package/build/features/node/writers/NodeWriter.js +37 -22
- package/build/features/node/writers/NodeWriter.js.map +1 -1
- package/build/features/skill/updaters/Updater.js +3 -1
- package/build/features/skill/updaters/Updater.js.map +1 -1
- package/build/tests/utilities/uiAssert.utility.d.ts +1 -0
- package/build/tests/utilities/uiAssert.utility.js +34 -0
- package/build/tests/utilities/uiAssert.utility.js.map +1 -1
- package/build/writers/AbstractWriter.d.ts +10 -10
- package/build/writers/AbstractWriter.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/behavioral/UpgradingANodeModule.test.ts +24 -0
- package/src/features/node/NodeFeature.ts +31 -25
- package/src/features/node/actions/UpgradeAction.ts +8 -1
- package/src/features/node/writers/NodeWriter.ts +38 -23
- package/src/features/skill/updaters/Updater.ts +2 -1
- package/src/tests/utilities/uiAssert.utility.ts +16 -0
- package/src/writers/AbstractWriter.ts +15 -10
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [14.28.0](https://github.com/sprucelabsai/spruce-cli-workspace/compare/v14.27.0...v14.28.0) (2021-11-30)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* upgrading a node module writes the expected files and asks about them too ([91b6534](https://github.com/sprucelabsai/spruce-cli-workspace/commit/91b6534))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [14.27.0](https://github.com/sprucelabsai/spruce-cli-workspace/compare/v14.26.19...v14.27.0) (2021-11-29)
|
|
7
18
|
|
|
8
19
|
|
|
@@ -3,4 +3,5 @@ export default class UpgradingANodeModuleTest extends AbstractCliTest {
|
|
|
3
3
|
protected static beforeEach(): Promise<void>;
|
|
4
4
|
protected static buildErrorsGetPassedThroughToResults(): Promise<void>;
|
|
5
5
|
protected static upgradingWritesExpectedFiles(): Promise<void>;
|
|
6
|
+
protected static shouldReWriteNodeDirsAndSkipIndx(): Promise<void>;
|
|
6
7
|
}
|
|
@@ -33,13 +33,15 @@ var _CommandService = _interopRequireDefault(require("../../services/CommandServ
|
|
|
33
33
|
|
|
34
34
|
var _AbstractCliTest2 = _interopRequireDefault(require("../../tests/AbstractCliTest"));
|
|
35
35
|
|
|
36
|
-
var
|
|
36
|
+
var _uiAssert = _interopRequireDefault(require("../../tests/utilities/uiAssert.utility"));
|
|
37
|
+
|
|
38
|
+
var _dec, _dec2, _dec3, _class;
|
|
37
39
|
|
|
38
40
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
39
41
|
|
|
40
42
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
41
43
|
|
|
42
|
-
var UpgradingANodeModuleTest = (_dec = (0, _test.test)(), _dec2 = (0, _test.test)(), (_class = /*#__PURE__*/function (_AbstractCliTest) {
|
|
44
|
+
var UpgradingANodeModuleTest = (_dec = (0, _test.test)(), _dec2 = (0, _test.test)(), _dec3 = (0, _test.test)(), (_class = /*#__PURE__*/function (_AbstractCliTest) {
|
|
43
45
|
(0, _inherits2["default"])(UpgradingANodeModuleTest, _AbstractCliTest);
|
|
44
46
|
|
|
45
47
|
var _super = _createSuper(UpgradingANodeModuleTest);
|
|
@@ -174,8 +176,53 @@ var UpgradingANodeModuleTest = (_dec = (0, _test.test)(), _dec2 = (0, _test.test
|
|
|
174
176
|
|
|
175
177
|
return upgradingWritesExpectedFiles;
|
|
176
178
|
}()
|
|
179
|
+
}, {
|
|
180
|
+
key: "shouldReWriteNodeDirsAndSkipIndx",
|
|
181
|
+
value: function () {
|
|
182
|
+
var _shouldReWriteNodeDirsAndSkipIndx = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
|
|
183
|
+
var _i2, _arr, file, tsConfig, promise;
|
|
184
|
+
|
|
185
|
+
return _regenerator["default"].wrap(function _callee4$(_context4) {
|
|
186
|
+
while (1) {
|
|
187
|
+
switch (_context4.prev = _context4.next) {
|
|
188
|
+
case 0:
|
|
189
|
+
for (_i2 = 0, _arr = ['tsconfig.json', 'src/index.ts']; _i2 < _arr.length; _i2++) {
|
|
190
|
+
file = _arr[_i2];
|
|
191
|
+
tsConfig = this.resolvePath(file);
|
|
192
|
+
|
|
193
|
+
_spruceSkillUtils.diskUtil.writeFile(tsConfig, 'beenChanged');
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
_CommandService["default"].setMockResponse(/yarn/gi, {
|
|
197
|
+
code: 0
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
promise = this.Action('node', 'upgrade').execute({});
|
|
201
|
+
_context4.next = 5;
|
|
202
|
+
return _uiAssert["default"].assertRendersConfirmWriteFile(this.ui);
|
|
203
|
+
|
|
204
|
+
case 5:
|
|
205
|
+
_test.assert.isEqual(_spruceSkillUtils.diskUtil.readFile(this.resolvePath('src/index.ts')), 'beenChanged');
|
|
206
|
+
|
|
207
|
+
_context4.next = 8;
|
|
208
|
+
return promise;
|
|
209
|
+
|
|
210
|
+
case 8:
|
|
211
|
+
case "end":
|
|
212
|
+
return _context4.stop();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}, _callee4, this);
|
|
216
|
+
}));
|
|
217
|
+
|
|
218
|
+
function shouldReWriteNodeDirsAndSkipIndx() {
|
|
219
|
+
return _shouldReWriteNodeDirsAndSkipIndx.apply(this, arguments);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return shouldReWriteNodeDirsAndSkipIndx;
|
|
223
|
+
}()
|
|
177
224
|
}]);
|
|
178
225
|
return UpgradingANodeModuleTest;
|
|
179
|
-
}(_AbstractCliTest2["default"]), ((0, _applyDecoratedDescriptor2["default"])(_class, "buildErrorsGetPassedThroughToResults", [_dec], Object.getOwnPropertyDescriptor(_class, "buildErrorsGetPassedThroughToResults"), _class), (0, _applyDecoratedDescriptor2["default"])(_class, "upgradingWritesExpectedFiles", [_dec2], Object.getOwnPropertyDescriptor(_class, "upgradingWritesExpectedFiles"), _class)), _class));
|
|
226
|
+
}(_AbstractCliTest2["default"]), ((0, _applyDecoratedDescriptor2["default"])(_class, "buildErrorsGetPassedThroughToResults", [_dec], Object.getOwnPropertyDescriptor(_class, "buildErrorsGetPassedThroughToResults"), _class), (0, _applyDecoratedDescriptor2["default"])(_class, "upgradingWritesExpectedFiles", [_dec2], Object.getOwnPropertyDescriptor(_class, "upgradingWritesExpectedFiles"), _class), (0, _applyDecoratedDescriptor2["default"])(_class, "shouldReWriteNodeDirsAndSkipIndx", [_dec3], Object.getOwnPropertyDescriptor(_class, "shouldReWriteNodeDirsAndSkipIndx"), _class)), _class));
|
|
180
227
|
exports["default"] = UpgradingANodeModuleTest;
|
|
181
228
|
//# sourceMappingURL=UpgradingANodeModule.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/__tests__/behavioral/UpgradingANodeModule.test.ts"],"names":["UpgradingANodeModuleTest","FeatureFixture","installCachedFeatures","featureInstaller","getFeatureInstaller","markAsPermanentlySkipped","CommandService","setMockResponse","code","getEmitter","on","errors","undefined","Action","execute","results","assert","isTruthy","shouldNotBeFound","isFalsy","search","doesExist","diskUtil","doesFileExist","resolvePath","isFalse","AbstractCliTest"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;;;IAEqBA,wB,WAUnB,iB,UAiBA,iB;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../../../src/__tests__/behavioral/UpgradingANodeModule.test.ts"],"names":["UpgradingANodeModuleTest","FeatureFixture","installCachedFeatures","featureInstaller","getFeatureInstaller","markAsPermanentlySkipped","CommandService","setMockResponse","code","getEmitter","on","errors","undefined","Action","execute","results","assert","isTruthy","shouldNotBeFound","isFalsy","search","doesExist","diskUtil","doesFileExist","resolvePath","isFalse","file","tsConfig","writeFile","promise","uiAssertUtil","assertRendersConfirmWriteFile","ui","isEqual","readFile","AbstractCliTest"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;;;;;IAEqBA,wB,WAUnB,iB,UAiBA,iB,UAcA,iB;;;;;;;;;;;;;sGAxCD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA,uBAGO,KAAKC,cAAL,GAAsBC,qBAAtB,CAA4C,kBAA5C,CAHP;;AAAA;AAKOC,gBAAAA,gBALP,GAK0B,KAAKC,mBAAL,EAL1B;AAMCD,gBAAAA,gBAAgB,CAACE,wBAAjB,CAA0C,OAA1C;;AAND;AAAA;AAAA;AAAA;AAAA;AAAA;A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AA;AAAA,O;;;;;;;;;;;4HAcA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAEC,qCAAmB,CAAC,eAAD,EAAkB,cAAlB,CAAnB,4BAAsD;AAA3CM,kBAAAA,IAA2C;AAC/CC,kBAAAA,QAD+C,GACpC,KAAKH,WAAL,CAAiBE,IAAjB,CADoC;;AAErDJ,6CAASM,SAAT,CAAmBD,QAAnB,EAA6B,aAA7B;AACA;;AAEDrB,2CAAeC,eAAf,CAA+B,QAA/B,EAAyC;AACxCC,kBAAAA,IAAI,EAAE;AADkC,iBAAzC;;AAIMqB,gBAAAA,OAXP,GAWiB,KAAKhB,MAAL,CAAY,MAAZ,EAAoB,SAApB,EAA+BC,OAA/B,CAAuC,EAAvC,CAXjB;AAAA;AAAA,uBAaOgB,qBAAaC,6BAAb,CAA2C,KAAKC,EAAhD,CAbP;;AAAA;AAeChB,6BAAOiB,OAAP,CACCX,2BAASY,QAAT,CAAkB,KAAKV,WAAL,CAAiB,cAAjB,CAAlB,CADD,EAEC,aAFD;;AAfD;AAAA,uBAoBOK,OApBP;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O;;;;;;;;;;EAzCqDM,4B","sourcesContent":["import { diskUtil } from '@sprucelabs/spruce-skill-utils'\nimport { test, assert } from '@sprucelabs/test'\nimport CommandService from '../../services/CommandService'\nimport AbstractCliTest from '../../tests/AbstractCliTest'\nimport uiAssertUtil from '../../tests/utilities/uiAssert.utility'\n\nexport default class UpgradingANodeModuleTest extends AbstractCliTest {\n\tprotected static async beforeEach() {\n\t\tawait super.beforeEach()\n\n\t\tawait this.FeatureFixture().installCachedFeatures('everythingInNode')\n\n\t\tconst featureInstaller = this.getFeatureInstaller()\n\t\tfeatureInstaller.markAsPermanentlySkipped('skill')\n\t}\n\n\t@test()\n\tprotected static async buildErrorsGetPassedThroughToResults() {\n\t\tCommandService.setMockResponse(/yarn (add|install)/gis, { code: 0 })\n\t\tCommandService.setMockResponse(/yarn clean.build/gis, { code: 1 })\n\t\tCommandService.setMockResponse(/yarn build.dev/gis, { code: 0 })\n\n\t\tawait this.getEmitter().on('feature.did-execute', () => {\n\t\t\treturn {\n\t\t\t\terrors: undefined,\n\t\t\t}\n\t\t})\n\n\t\tconst results = await this.Action('node', 'upgrade').execute({})\n\n\t\tassert.isTruthy(results.errors)\n\t}\n\n\t@test()\n\tprotected static async upgradingWritesExpectedFiles() {\n\t\tconst shouldNotBeFound = ['src/.spruce/skill.ts', 'src/.spruce/features']\n\n\t\tconst results = await this.Action('node', 'upgrade').execute({})\n\n\t\tassert.isFalsy(results.errors)\n\n\t\tfor (const search of shouldNotBeFound) {\n\t\t\tconst doesExist = diskUtil.doesFileExist(this.resolvePath(search))\n\t\t\tassert.isFalse(doesExist, `Should not have found ${search}`)\n\t\t}\n\t}\n\n\t@test()\n\tprotected static async shouldReWriteNodeDirsAndSkipIndx() {\n\t\tfor (const file of ['tsconfig.json', 'src/index.ts']) {\n\t\t\tconst tsConfig = this.resolvePath(file)\n\t\t\tdiskUtil.writeFile(tsConfig, 'beenChanged')\n\t\t}\n\n\t\tCommandService.setMockResponse(/yarn/gi, {\n\t\t\tcode: 0,\n\t\t})\n\n\t\tconst promise = this.Action('node', 'upgrade').execute({})\n\n\t\tawait uiAssertUtil.assertRendersConfirmWriteFile(this.ui)\n\n\t\tassert.isEqual(\n\t\t\tdiskUtil.readFile(this.resolvePath('src/index.ts')),\n\t\t\t'beenChanged'\n\t\t)\n\n\t\tawait promise\n\t}\n}\n"],"file":"UpgradingANodeModule.test.js"}
|
|
@@ -49,6 +49,7 @@ export default class NodeFeature<S extends OptionsSchema = OptionsSchema> extend
|
|
|
49
49
|
readonly fileDescriptions: FileDescription[];
|
|
50
50
|
actionsDir: string;
|
|
51
51
|
constructor(options: ActionOptions);
|
|
52
|
+
private handleUpgrade;
|
|
52
53
|
beforePackageInstall(options: Options): Promise<{
|
|
53
54
|
files: SpruceSchemas.SpruceCli.v2020_07_22.GeneratedFile[];
|
|
54
55
|
cwd: string;
|
|
@@ -89,50 +89,21 @@ var NodeFeature = /*#__PURE__*/function (_AbstractFeature) {
|
|
|
89
89
|
switch (_context2.prev = _context2.next) {
|
|
90
90
|
case 0:
|
|
91
91
|
if (!(payload.featureCode === 'node' && payload.actionCode === 'upgrade')) {
|
|
92
|
-
_context2.next =
|
|
92
|
+
_context2.next = 2;
|
|
93
93
|
break;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
_context2.
|
|
96
|
+
return _context2.abrupt("return", _this.handleUpgrade());
|
|
97
97
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
_context2.next = 5;
|
|
101
|
-
return _this.Service('command').execute('yarn clean.build');
|
|
102
|
-
|
|
103
|
-
case 5:
|
|
104
|
-
_this.ui.startLoading('Applying lint rules to all files...');
|
|
105
|
-
|
|
106
|
-
_context2.next = 8;
|
|
107
|
-
return _this.Service('command').execute('yarn fix.lint');
|
|
108
|
-
|
|
109
|
-
case 8:
|
|
110
|
-
_this.ui.startLoading('Rebuilding...');
|
|
111
|
-
|
|
112
|
-
_context2.next = 11;
|
|
113
|
-
return _this.Service('command').execute('yarn build.dev');
|
|
114
|
-
|
|
115
|
-
case 11:
|
|
116
|
-
return _context2.abrupt("return", {
|
|
117
|
-
summaryLines: ['Build cleared.', 'Lint rules applied to source.', 'Code rebuilt successfully.']
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
case 14:
|
|
121
|
-
_context2.prev = 14;
|
|
122
|
-
_context2.t0 = _context2["catch"](1);
|
|
123
|
-
return _context2.abrupt("return", {
|
|
124
|
-
errors: [_context2.t0]
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
case 17:
|
|
98
|
+
case 2:
|
|
128
99
|
return _context2.abrupt("return", {});
|
|
129
100
|
|
|
130
|
-
case
|
|
101
|
+
case 3:
|
|
131
102
|
case "end":
|
|
132
103
|
return _context2.stop();
|
|
133
104
|
}
|
|
134
105
|
}
|
|
135
|
-
}, _callee2
|
|
106
|
+
}, _callee2);
|
|
136
107
|
}));
|
|
137
108
|
|
|
138
109
|
return function (_x) {
|
|
@@ -143,13 +114,62 @@ var NodeFeature = /*#__PURE__*/function (_AbstractFeature) {
|
|
|
143
114
|
}
|
|
144
115
|
|
|
145
116
|
(0, _createClass2["default"])(NodeFeature, [{
|
|
146
|
-
key: "
|
|
117
|
+
key: "handleUpgrade",
|
|
147
118
|
value: function () {
|
|
148
|
-
var
|
|
149
|
-
var destination, files, nodeWriter, written;
|
|
119
|
+
var _handleUpgrade = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
|
|
150
120
|
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
|
151
121
|
while (1) {
|
|
152
122
|
switch (_context3.prev = _context3.next) {
|
|
123
|
+
case 0:
|
|
124
|
+
_context3.prev = 0;
|
|
125
|
+
this.ui.startLoading('Cleaning build...');
|
|
126
|
+
_context3.next = 4;
|
|
127
|
+
return this.Service('command').execute('yarn clean.build');
|
|
128
|
+
|
|
129
|
+
case 4:
|
|
130
|
+
this.ui.startLoading('Applying lint rules to all files...');
|
|
131
|
+
_context3.next = 7;
|
|
132
|
+
return this.Service('command').execute('yarn fix.lint');
|
|
133
|
+
|
|
134
|
+
case 7:
|
|
135
|
+
this.ui.startLoading('Rebuilding...');
|
|
136
|
+
_context3.next = 10;
|
|
137
|
+
return this.Service('command').execute('yarn build.dev');
|
|
138
|
+
|
|
139
|
+
case 10:
|
|
140
|
+
return _context3.abrupt("return", {
|
|
141
|
+
summaryLines: ['Build cleared.', 'Lint rules applied to source.', 'Code rebuilt successfully.']
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
case 13:
|
|
145
|
+
_context3.prev = 13;
|
|
146
|
+
_context3.t0 = _context3["catch"](0);
|
|
147
|
+
return _context3.abrupt("return", {
|
|
148
|
+
errors: [_context3.t0]
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
case 16:
|
|
152
|
+
case "end":
|
|
153
|
+
return _context3.stop();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}, _callee3, this, [[0, 13]]);
|
|
157
|
+
}));
|
|
158
|
+
|
|
159
|
+
function handleUpgrade() {
|
|
160
|
+
return _handleUpgrade.apply(this, arguments);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return handleUpgrade;
|
|
164
|
+
}()
|
|
165
|
+
}, {
|
|
166
|
+
key: "beforePackageInstall",
|
|
167
|
+
value: function () {
|
|
168
|
+
var _beforePackageInstall = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(options) {
|
|
169
|
+
var destination, files, written;
|
|
170
|
+
return _regenerator["default"].wrap(function _callee4$(_context4) {
|
|
171
|
+
while (1) {
|
|
172
|
+
switch (_context4.prev = _context4.next) {
|
|
153
173
|
case 0:
|
|
154
174
|
destination = this.resolveDestination(options);
|
|
155
175
|
|
|
@@ -162,32 +182,31 @@ var NodeFeature = /*#__PURE__*/function (_AbstractFeature) {
|
|
|
162
182
|
path: _spruceSkillUtils.diskUtil.resolvePath(destination, 'package.json'),
|
|
163
183
|
action: 'generated'
|
|
164
184
|
}];
|
|
165
|
-
|
|
185
|
+
_context4.next = 5;
|
|
166
186
|
return this.Service('command', destination).execute('yarn init -y');
|
|
167
187
|
|
|
168
188
|
case 5:
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
return nodeWriter.writeNodeModule(destination);
|
|
189
|
+
_context4.next = 7;
|
|
190
|
+
return this.Writer('node').writeNodeModule(destination);
|
|
172
191
|
|
|
173
|
-
case
|
|
174
|
-
written =
|
|
192
|
+
case 7:
|
|
193
|
+
written = _context4.sent;
|
|
175
194
|
files.push.apply(files, (0, _toConsumableArray2["default"])(written));
|
|
176
|
-
|
|
195
|
+
_context4.next = 11;
|
|
177
196
|
return this.installScripts(destination);
|
|
178
197
|
|
|
179
|
-
case
|
|
180
|
-
return
|
|
198
|
+
case 11:
|
|
199
|
+
return _context4.abrupt("return", {
|
|
181
200
|
files: files,
|
|
182
201
|
cwd: destination
|
|
183
202
|
});
|
|
184
203
|
|
|
185
|
-
case
|
|
204
|
+
case 12:
|
|
186
205
|
case "end":
|
|
187
|
-
return
|
|
206
|
+
return _context4.stop();
|
|
188
207
|
}
|
|
189
208
|
}
|
|
190
|
-
},
|
|
209
|
+
}, _callee4, this);
|
|
191
210
|
}));
|
|
192
211
|
|
|
193
212
|
function beforePackageInstall(_x2) {
|
|
@@ -206,11 +225,11 @@ var NodeFeature = /*#__PURE__*/function (_AbstractFeature) {
|
|
|
206
225
|
}, {
|
|
207
226
|
key: "afterPackageInstall",
|
|
208
227
|
value: function () {
|
|
209
|
-
var _afterPackageInstall = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
228
|
+
var _afterPackageInstall = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(options) {
|
|
210
229
|
var cwd, pkg;
|
|
211
|
-
return _regenerator["default"].wrap(function
|
|
230
|
+
return _regenerator["default"].wrap(function _callee5$(_context5) {
|
|
212
231
|
while (1) {
|
|
213
|
-
switch (
|
|
232
|
+
switch (_context5.prev = _context5.next) {
|
|
214
233
|
case 0:
|
|
215
234
|
cwd = this.resolveDestination(options);
|
|
216
235
|
pkg = this.Service('pkg', cwd);
|
|
@@ -228,20 +247,20 @@ var NodeFeature = /*#__PURE__*/function (_AbstractFeature) {
|
|
|
228
247
|
});
|
|
229
248
|
pkg.unset('main');
|
|
230
249
|
pkg.unset('license');
|
|
231
|
-
|
|
250
|
+
_context5.next = 9;
|
|
232
251
|
return this.Store('skill', {
|
|
233
252
|
cwd: cwd
|
|
234
253
|
}).setCurrentSkillsNamespace(options.name);
|
|
235
254
|
|
|
236
255
|
case 9:
|
|
237
|
-
return
|
|
256
|
+
return _context5.abrupt("return", {});
|
|
238
257
|
|
|
239
258
|
case 10:
|
|
240
259
|
case "end":
|
|
241
|
-
return
|
|
260
|
+
return _context5.stop();
|
|
242
261
|
}
|
|
243
262
|
}
|
|
244
|
-
},
|
|
263
|
+
}, _callee5, this);
|
|
245
264
|
}));
|
|
246
265
|
|
|
247
266
|
function afterPackageInstall(_x3) {
|
|
@@ -253,27 +272,27 @@ var NodeFeature = /*#__PURE__*/function (_AbstractFeature) {
|
|
|
253
272
|
}, {
|
|
254
273
|
key: "installScripts",
|
|
255
274
|
value: function () {
|
|
256
|
-
var _installScripts = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function
|
|
275
|
+
var _installScripts = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6() {
|
|
257
276
|
var destination,
|
|
258
277
|
scriptUpdater,
|
|
259
|
-
|
|
260
|
-
return _regenerator["default"].wrap(function
|
|
278
|
+
_args6 = arguments;
|
|
279
|
+
return _regenerator["default"].wrap(function _callee6$(_context6) {
|
|
261
280
|
while (1) {
|
|
262
|
-
switch (
|
|
281
|
+
switch (_context6.prev = _context6.next) {
|
|
263
282
|
case 0:
|
|
264
|
-
destination =
|
|
283
|
+
destination = _args6.length > 0 && _args6[0] !== undefined ? _args6[0] : this.cwd;
|
|
265
284
|
scriptUpdater = _ScriptUpdater["default"].FromFeature(this, {
|
|
266
285
|
cwd: destination
|
|
267
286
|
});
|
|
268
|
-
|
|
287
|
+
_context6.next = 4;
|
|
269
288
|
return scriptUpdater.update();
|
|
270
289
|
|
|
271
290
|
case 4:
|
|
272
291
|
case "end":
|
|
273
|
-
return
|
|
292
|
+
return _context6.stop();
|
|
274
293
|
}
|
|
275
294
|
}
|
|
276
|
-
},
|
|
295
|
+
}, _callee6, this);
|
|
277
296
|
}));
|
|
278
297
|
|
|
279
298
|
function installScripts() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/features/node/NodeFeature.ts"],"names":["NodeFeature","options","nodeFeatureOptionsSchema","universalDevDependencies","universalScripts","universalFileDescriptions","diskUtil","resolvePath","__dirname","doesFileExist","cwd","emitter","on","payload","featureCode","actionCode","ui","startLoading","Service","execute","summaryLines","errors","destination","resolveDestination","doesDirExist","createDir","files","name","path","action","
|
|
1
|
+
{"version":3,"sources":["../../../src/features/node/NodeFeature.ts"],"names":["NodeFeature","options","nodeFeatureOptionsSchema","universalDevDependencies","universalScripts","universalFileDescriptions","diskUtil","resolvePath","__dirname","doesFileExist","cwd","emitter","on","payload","featureCode","actionCode","handleUpgrade","ui","startLoading","Service","execute","summaryLines","errors","destination","resolveDestination","doesDirExist","createDir","files","name","path","action","Writer","writeNodeModule","written","push","installScripts","pkg","set","value","namesUtil","toKebab","description","unset","Store","setCurrentSkillsNamespace","scriptUpdater","ScriptUpdater","FromFeature","update","AbstractFeature"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;;AACA;;AAEA;;AACA;;AAMA;;AACA;;AACA;;;;;;;;;;IAgBqBA,W;;;;;AAoBpB,uBAAmBC,OAAnB,EAA2C;AAAA;;AAAA;AAC1C,8BAAMA,OAAN;AAD0C,6FAjBhB,MAiBgB;AAAA,qGAhBrB,gBAgBqB;AAAA,oGAftB,EAesB;AAAA,qGAdA,EAcA;AAAA,sGAbpBC,8BAaoB;AAAA,gJAZVC,oCAYU;AAAA,kHATvCC,4BASuC;AAAA,6IALvCC,qCAKuC;AAAA,mGAFvBC,2BAASC,WAAT,CAAqBC,SAArB,EAAgC,SAAhC,CAEuB;AAAA,+LA4FtB;AAAA;AAAA;AAAA;AAAA;AAAA,+CACbF,2BAASG,aAAT,CACNH,2BAASC,WAAT,CAAqB,MAAKG,GAA1B,EAA+B,cAA/B,CADM,CADa;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,KA5FsB;AAG1C,SAAK,MAAKC,OAAL,CAAaC,EAAb,CAAgB,qBAAhB;AAAA,gGAAuC,kBAAOC,OAAP;AAAA;AAAA;AAAA;AAAA;AAAA,sBACvCA,OAAO,CAACC,WAAR,KAAwB,MAAxB,IAAkCD,OAAO,CAACE,UAAR,KAAuB,SADlB;AAAA;AA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,SAAR;AAAmBS,kBAAAA,KAAK,EAAE;AAA1B,iBAAR;AAEAF,gBAAAA,GAAG,CAACM,KAAJ,CAAU,MAAV;AACAN,gBAAAA,GAAG,CAACM,KAAJ,CAAU,SAAV;AAXD;AAAA,uBAaO,KAAKC,KAAL,CAAW,OAAX,EAAoB;AAAEjC,kBAAAA,GAAG,EAAHA;AAAF,iBAApB,EAA6BkC,yBAA7B,CAAuD3C,OAAO,CAAC2B,IAA/D,CAbP;;AAAA;AAAA,kDAeQ,EAfR;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O;;;;;;;;;;;0GAkBA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA6BL,gBAAAA,WAA7B,8DAA2C,KAAKb,GAAhD;AACOmC,gBAAAA,aADP,GACuBC,0BAAcC,WAAd,CAA0B,IAA1B,EAAgC;AACrDrC,kBAAAA,GAAG,EAAEa;AADgD,iBAAhC,CADvB;AAAA;AAAA,uBAKOsB,aAAa,CAACG,MAAd,EALP;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O;;;;;;;;;;EAtGSC,4B","sourcesContent":["import { Schema, SchemaValues } from '@sprucelabs/schema'\nimport { SpruceSchemas } from '@sprucelabs/spruce-core-schemas'\nimport { diskUtil, namesUtil } from '@sprucelabs/spruce-skill-utils'\nimport nodeFeatureOptionsSchema from '#spruce/schemas/spruceCli/v2020_07_22/nodeFeatureOptions.schema'\nimport { FileDescription, GeneratedFile } from '../../types/cli.types'\nimport ScriptUpdater from '../../updaters/ScriptUpdater'\nimport AbstractFeature, { FeatureDependency } from '../AbstractFeature'\nimport {\n\tActionOptions,\n\tFeatureActionResponse,\n\tFeatureCode,\n} from '../features.types'\nimport universalDevDependencies from '../universalDevDependencies'\nimport universalFileDescriptions from '../universalFileDescriptions'\nimport universalScripts from '../universalScripts'\n\ntype OptionsSchema =\n\tSpruceSchemas.SpruceCli.v2020_07_22.NodeFeatureOptionsSchema\ntype Options = SpruceSchemas.SpruceCli.v2020_07_22.NodeFeatureOptions\n\ndeclare module '../../features/features.types' {\n\tinterface FeatureMap {\n\t\tnode: NodeFeature\n\t}\n\n\tinterface FeatureOptionsMap {\n\t\tnode: SchemaValues<OptionsSchema>\n\t}\n}\n\nexport default class NodeFeature<\n\tS extends OptionsSchema = OptionsSchema\n> extends AbstractFeature<S> {\n\tpublic code: FeatureCode = 'node'\n\tpublic nameReadable = 'nodejs support'\n\tpublic description = ''\n\tpublic dependencies: FeatureDependency[] = []\n\tpublic optionsSchema = nodeFeatureOptionsSchema as S\n\tpublic packageDependencies = [...universalDevDependencies]\n\n\tpublic scripts = {\n\t\t...universalScripts,\n\t}\n\n\tpublic readonly fileDescriptions: FileDescription[] = [\n\t\t...universalFileDescriptions,\n\t]\n\n\tpublic actionsDir = diskUtil.resolvePath(__dirname, 'actions')\n\n\tpublic constructor(options: ActionOptions) {\n\t\tsuper(options)\n\n\t\tvoid this.emitter.on('feature.did-execute', async (payload) => {\n\t\t\tif (payload.featureCode === 'node' && payload.actionCode === 'upgrade') {\n\t\t\t\treturn this.handleUpgrade()\n\t\t\t}\n\n\t\t\treturn {}\n\t\t})\n\t}\n\tprivate async handleUpgrade(): Promise<FeatureActionResponse> {\n\t\ttry {\n\t\t\tthis.ui.startLoading('Cleaning build...')\n\t\t\tawait this.Service('command').execute('yarn clean.build')\n\n\t\t\tthis.ui.startLoading('Applying lint rules to all files...')\n\t\t\tawait this.Service('command').execute('yarn fix.lint')\n\n\t\t\tthis.ui.startLoading('Rebuilding...')\n\t\t\tawait this.Service('command').execute('yarn build.dev')\n\n\t\t\treturn {\n\t\t\t\tsummaryLines: [\n\t\t\t\t\t'Build cleared.',\n\t\t\t\t\t'Lint rules applied to source.',\n\t\t\t\t\t'Code rebuilt successfully.',\n\t\t\t\t],\n\t\t\t}\n\t\t} catch (err) {\n\t\t\treturn {\n\t\t\t\terrors: [err],\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic async beforePackageInstall(options: Options) {\n\t\tconst destination = this.resolveDestination(options)\n\n\t\tif (!diskUtil.doesDirExist(destination)) {\n\t\t\tdiskUtil.createDir(destination)\n\t\t}\n\n\t\tconst files: GeneratedFile[] = [\n\t\t\t{\n\t\t\t\tname: 'package.json',\n\t\t\t\tpath: diskUtil.resolvePath(destination, 'package.json'),\n\t\t\t\taction: 'generated',\n\t\t\t},\n\t\t]\n\n\t\tawait this.Service('command', destination).execute('yarn init -y')\n\n\t\tconst written = await this.Writer('node').writeNodeModule(destination)\n\n\t\tfiles.push(...written)\n\n\t\tawait this.installScripts(destination)\n\n\t\treturn { files, cwd: destination }\n\t}\n\n\tprivate resolveDestination(options: Options) {\n\t\treturn diskUtil.resolvePath(this.cwd, options.destination ?? '')\n\t}\n\n\tpublic async afterPackageInstall(\n\t\toptions: S extends Schema ? SchemaValues<S> : undefined\n\t) {\n\t\tconst cwd = this.resolveDestination(options)\n\t\tconst pkg = this.Service('pkg', cwd)\n\n\t\tpkg.set({ path: 'name', value: namesUtil.toKebab(options.name) })\n\t\tpkg.set({ path: 'description', value: options.description })\n\t\tpkg.set({ path: 'version', value: '0.0.1' })\n\n\t\tpkg.unset('main')\n\t\tpkg.unset('license')\n\n\t\tawait this.Store('skill', { cwd }).setCurrentSkillsNamespace(options.name)\n\n\t\treturn {}\n\t}\n\n\tprivate async installScripts(destination = this.cwd) {\n\t\tconst scriptUpdater = ScriptUpdater.FromFeature(this, {\n\t\t\tcwd: destination,\n\t\t})\n\n\t\tawait scriptUpdater.update()\n\t}\n\n\tpublic isInstalled = async (): Promise<boolean> => {\n\t\treturn diskUtil.doesFileExist(\n\t\t\tdiskUtil.resolvePath(this.cwd, 'package.json')\n\t\t)\n\t}\n}\n"],"file":"NodeFeature.js"}
|
|
@@ -74,7 +74,7 @@ var UpgradeAction = /*#__PURE__*/function (_AbstractAction) {
|
|
|
74
74
|
key: "execute",
|
|
75
75
|
value: function () {
|
|
76
76
|
var _execute = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(options) {
|
|
77
|
-
var normalizedOptions, dependencyResults;
|
|
77
|
+
var normalizedOptions, files, dependencyResults;
|
|
78
78
|
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
79
79
|
while (1) {
|
|
80
80
|
switch (_context.prev = _context.next) {
|
|
@@ -87,32 +87,43 @@ var UpgradeAction = /*#__PURE__*/function (_AbstractAction) {
|
|
|
87
87
|
|
|
88
88
|
case 3:
|
|
89
89
|
_context.prev = 3;
|
|
90
|
+
_context.next = 6;
|
|
91
|
+
return this.Writer('node', {
|
|
92
|
+
upgradeMode: normalizedOptions.upgradeMode
|
|
93
|
+
}).writeNodeModule(this.cwd, {
|
|
94
|
+
shouldConfirmBeforeWriting: true,
|
|
95
|
+
shouldWriteIndex: false
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
case 6:
|
|
99
|
+
files = _context.sent;
|
|
90
100
|
|
|
91
101
|
_InFlightEntertainment["default"].start(["Let's start the upgrade!", 'While things are going, see if you can beat 1k points!', 'Go!!!!']);
|
|
92
102
|
|
|
93
|
-
_context.next =
|
|
103
|
+
_context.next = 10;
|
|
94
104
|
return this.reInstallPackageDependencies();
|
|
95
105
|
|
|
96
|
-
case
|
|
106
|
+
case 10:
|
|
97
107
|
dependencyResults = _context.sent;
|
|
98
108
|
return _context.abrupt("return", _action["default"].mergeActionResults(dependencyResults, {
|
|
99
|
-
headline: 'Upgrade'
|
|
109
|
+
headline: 'Upgrade',
|
|
110
|
+
files: files
|
|
100
111
|
}));
|
|
101
112
|
|
|
102
|
-
case
|
|
103
|
-
_context.prev =
|
|
113
|
+
case 12:
|
|
114
|
+
_context.prev = 12;
|
|
104
115
|
|
|
105
116
|
_InFlightEntertainment["default"].stop();
|
|
106
117
|
|
|
107
118
|
this.ui.renderHero('Upgrade');
|
|
108
|
-
return _context.finish(
|
|
119
|
+
return _context.finish(12);
|
|
109
120
|
|
|
110
|
-
case
|
|
121
|
+
case 16:
|
|
111
122
|
case "end":
|
|
112
123
|
return _context.stop();
|
|
113
124
|
}
|
|
114
125
|
}
|
|
115
|
-
}, _callee, this, [[3,,
|
|
126
|
+
}, _callee, this, [[3,, 12, 16]]);
|
|
116
127
|
}));
|
|
117
128
|
|
|
118
129
|
function execute(_x) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/features/node/actions/UpgradeAction.ts"],"names":["UpgradeAction","upgradeSkillActionSchema","options","normalizedOptions","validateAndNormalizeOptions","updateScripts","shouldConfirm","upgradeMode","InFlightEntertainment","start","reInstallPackageDependencies","dependencyResults","actionUtil","mergeActionResults","headline","stop","ui","renderHero","Action","execute","featureInstaller","getInstalledFeatures","features","scripts","feature","scriptUpdater","ScriptUpdater","FromFeature","parent","latestScripts","update","shouldConfirmIfScriptExistsButIsDifferent","AbstractAction"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;IAOqBA,a;;;;;;;;;;;;;;;0GACO,4B;sGACJC,+B;uGACC,CAAC,SAAD,EAAY,QAAZ,C;;;;;;;mGAExB,iBAAqBC,OAArB;AAAA;AAAA;AAAA;AAAA;AAAA;AACOC,gBAAAA,iBADP,GAC2B,KAAKC,2BAAL,CAAiCF,OAAjC,CAD3B;AAAA;AAAA,uBAGO,KAAKG,aAAL,CAAmB;AACxBC,kBAAAA,aAAa,EAAEH,iBAAiB,CAACI,WAAlB,KAAkC;AADzB,iBAAnB,CAHP;;AAAA;AAAA;;
|
|
1
|
+
{"version":3,"sources":["../../../../src/features/node/actions/UpgradeAction.ts"],"names":["UpgradeAction","upgradeSkillActionSchema","options","normalizedOptions","validateAndNormalizeOptions","updateScripts","shouldConfirm","upgradeMode","Writer","writeNodeModule","cwd","shouldConfirmBeforeWriting","shouldWriteIndex","files","InFlightEntertainment","start","reInstallPackageDependencies","dependencyResults","actionUtil","mergeActionResults","headline","stop","ui","renderHero","Action","execute","featureInstaller","getInstalledFeatures","features","scripts","feature","scriptUpdater","ScriptUpdater","FromFeature","parent","latestScripts","update","shouldConfirmIfScriptExistsButIsDifferent","AbstractAction"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;IAOqBA,a;;;;;;;;;;;;;;;0GACO,4B;sGACJC,+B;uGACC,CAAC,SAAD,EAAY,QAAZ,C;;;;;;;mGAExB,iBAAqBC,OAArB;AAAA;AAAA;AAAA;AAAA;AAAA;AACOC,gBAAAA,iBADP,GAC2B,KAAKC,2BAAL,CAAiCF,OAAjC,CAD3B;AAAA;AAAA,uBAGO,KAAKG,aAAL,CAAmB;AACxBC,kBAAAA,aAAa,EAAEH,iBAAiB,CAACI,WAAlB,KAAkC;AADzB,iBAAnB,CAHP;;AAAA;AAAA;AAAA;AAAA,uBAQsB,KAAKC,MAAL,CAAY,MAAZ,EAAoB;AACvCD,kBAAAA,WAAW,EAAEJ,iBAAiB,CAACI;AADQ,iBAApB,EAEjBE,eAFiB,CAED,KAAKC,GAFJ,EAES;AAC5BC,kBAAAA,0BAA0B,EAAE,IADA;AAE5BC,kBAAAA,gBAAgB,EAAE;AAFU,iBAFT,CARtB;;AAAA;AAQQC,gBAAAA,KARR;;AAeEC,kDAAsBC,KAAtB,CAA4B,CAC3B,0BAD2B,EAE3B,wDAF2B,EAG3B,QAH2B,CAA5B;;AAfF;AAAA,uBAqBkC,KAAKC,4BAAL,EArBlC;;AAAA;AAqBQC,gBAAAA,iBArBR;AAAA,iDAuBSC,mBAAWC,kBAAX,CAA8BF,iBAA9B,EAAiD;AACvDG,kBAAAA,QAAQ,EAAE,SAD6C;AAEvDP,kBAAAA,KAAK,EAALA;AAFuD,iBAAjD,CAvBT;;AAAA;AAAA;;AA4BEC,kDAAsBO,IAAtB;;AACA,qBAAKC,EAAL,CAAQC,UAAR,CAAmB,SAAnB;AA7BF;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O;;;;;;;;;;;wHAiCA;AAAA;AAAA;AAAA;AAAA;AAAA,kDACQ,KAAKC,MAAL,CAAY,MAAZ,EAAoB,oBAApB,EAA0CC,OAA1C,CAAkD,EAAlD,CADR;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O;;;;;;;;;;;yGAIA,kBAA4BvB,OAA5B;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBACwB,KAAKwB,gBAAL,CAAsBC,oBAAtB,EADxB;;AAAA;AACOC,gBAAAA,QADP;AAGKC,gBAAAA,OAHL,GAGoC,EAHpC;AAAA,uDAKuBD,QALvB;;AAAA;AAKC,sEAAgC;AAArBE,oBAAAA,OAAqB;AAC/BD,oBAAAA,OAAO,mCACHA,OADG,GAEHC,OAAO,CAACD,OAFL,CAAP;AAIA;AAVF;AAAA;AAAA;AAAA;AAAA;;AAYOE,gBAAAA,aAZP,GAYuBC,0BAAcC,WAAd,CAA0B,KAAKC,MAA/B,EAAuC;AAC5DC,kBAAAA,aAAa,EAAEN;AAD6C,iBAAvC,CAZvB;AAAA;AAAA,uBAgBOE,aAAa,CAACK,MAAd,CAAqB;AAC1BC,kBAAAA,yCAAyC,EAAEnC,OAAO,CAACI;AADzB,iBAArB,CAhBP;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O;;;;;;;;;;EA1C0CgC,2B","sourcesContent":["import { SchemaValues } from '@sprucelabs/schema'\nimport { SpruceSchemas } from '#spruce/schemas/schemas.types'\nimport upgradeSkillActionSchema from '#spruce/schemas/spruceCli/v2020_07_22/upgradeSkillOptions.schema'\nimport InFlightEntertainment from '../../../InFlightEntertainment'\nimport ScriptUpdater from '../../../updaters/ScriptUpdater'\nimport actionUtil from '../../../utilities/action.utility'\nimport AbstractAction from '../../AbstractAction'\nimport { FeatureActionResponse } from '../../features.types'\n\ntype OptionsSchema =\n\tSpruceSchemas.SpruceCli.v2020_07_22.UpgradeSkillOptionsSchema\ntype Options = SchemaValues<OptionsSchema>\n\nexport default class UpgradeAction extends AbstractAction<OptionsSchema> {\n\tpublic invocationMessage = 'Upgrading your skill... 💪'\n\tpublic optionsSchema = upgradeSkillActionSchema\n\tpublic commandAliases = ['upgrade', 'update']\n\n\tpublic async execute(options: Options): Promise<FeatureActionResponse> {\n\t\tconst normalizedOptions = this.validateAndNormalizeOptions(options)\n\n\t\tawait this.updateScripts({\n\t\t\tshouldConfirm: normalizedOptions.upgradeMode !== 'forceEverything',\n\t\t})\n\n\t\ttry {\n\t\t\tconst files = await this.Writer('node', {\n\t\t\t\tupgradeMode: normalizedOptions.upgradeMode,\n\t\t\t}).writeNodeModule(this.cwd, {\n\t\t\t\tshouldConfirmBeforeWriting: true,\n\t\t\t\tshouldWriteIndex: false,\n\t\t\t})\n\n\t\t\tInFlightEntertainment.start([\n\t\t\t\t\"Let's start the upgrade!\",\n\t\t\t\t'While things are going, see if you can beat 1k points!',\n\t\t\t\t'Go!!!!',\n\t\t\t])\n\n\t\t\tconst dependencyResults = await this.reInstallPackageDependencies()\n\n\t\t\treturn actionUtil.mergeActionResults(dependencyResults, {\n\t\t\t\theadline: 'Upgrade',\n\t\t\t\tfiles,\n\t\t\t})\n\t\t} finally {\n\t\t\tInFlightEntertainment.stop()\n\t\t\tthis.ui.renderHero('Upgrade')\n\t\t}\n\t}\n\n\tprivate async reInstallPackageDependencies() {\n\t\treturn this.Action('node', 'updateDependencies').execute({})\n\t}\n\n\tprivate async updateScripts(options: { shouldConfirm: boolean }) {\n\t\tconst features = await this.featureInstaller.getInstalledFeatures()\n\n\t\tlet scripts: Record<string, any> = {}\n\n\t\tfor (const feature of features) {\n\t\t\tscripts = {\n\t\t\t\t...scripts,\n\t\t\t\t...feature.scripts,\n\t\t\t}\n\t\t}\n\n\t\tconst scriptUpdater = ScriptUpdater.FromFeature(this.parent, {\n\t\t\tlatestScripts: scripts,\n\t\t})\n\n\t\tawait scriptUpdater.update({\n\t\t\tshouldConfirmIfScriptExistsButIsDifferent: options.shouldConfirm,\n\t\t})\n\t}\n}\n"],"file":"UpgradeAction.js"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import AbstractWriter, { WriteResults } from '../../../writers/AbstractWriter';
|
|
1
|
+
import AbstractWriter, { WriteDirectoryTemplateOptions, WriteResults } from '../../../writers/AbstractWriter';
|
|
2
|
+
export declare const NODE_FILES_TO_UPGRADE: string[];
|
|
2
3
|
export default class NodeWriter extends AbstractWriter {
|
|
3
|
-
writeNodeModule(destinationDir: string
|
|
4
|
+
writeNodeModule(destinationDir: string, options?: Partial<WriteDirectoryTemplateOptions> & {
|
|
5
|
+
shouldWriteIndex?: boolean;
|
|
6
|
+
}): Promise<WriteResults>;
|
|
4
7
|
}
|
|
@@ -5,12 +5,14 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports["default"] = void 0;
|
|
8
|
+
exports["default"] = exports.NODE_FILES_TO_UPGRADE = void 0;
|
|
9
9
|
|
|
10
10
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
11
|
|
|
12
12
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
13
13
|
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
+
|
|
14
16
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
15
17
|
|
|
16
18
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
@@ -29,10 +31,17 @@ var _spruceTemplates = require("@sprucelabs/spruce-templates");
|
|
|
29
31
|
|
|
30
32
|
var _AbstractWriter2 = _interopRequireDefault(require("../../../writers/AbstractWriter"));
|
|
31
33
|
|
|
34
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
35
|
+
|
|
36
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
37
|
+
|
|
32
38
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
33
39
|
|
|
34
40
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
35
41
|
|
|
42
|
+
var NODE_FILES_TO_UPGRADE = ['tsconfig.json', '.eslintrc.js', '.eslintignore', '.gitignore', '.nvmrc'];
|
|
43
|
+
exports.NODE_FILES_TO_UPGRADE = NODE_FILES_TO_UPGRADE;
|
|
44
|
+
|
|
36
45
|
var NodeWriter = /*#__PURE__*/function (_AbstractWriter) {
|
|
37
46
|
(0, _inherits2["default"])(NodeWriter, _AbstractWriter);
|
|
38
47
|
|
|
@@ -46,38 +55,44 @@ var NodeWriter = /*#__PURE__*/function (_AbstractWriter) {
|
|
|
46
55
|
(0, _createClass2["default"])(NodeWriter, [{
|
|
47
56
|
key: "writeNodeModule",
|
|
48
57
|
value: function () {
|
|
49
|
-
var _writeNodeModule = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(destinationDir) {
|
|
50
|
-
var contents, destination,
|
|
58
|
+
var _writeNodeModule = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(destinationDir, options) {
|
|
59
|
+
var files, contents, destination, directoryTemplateFiles;
|
|
51
60
|
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
52
61
|
while (1) {
|
|
53
62
|
switch (_context.prev = _context.next) {
|
|
54
63
|
case 0:
|
|
55
|
-
|
|
56
|
-
destination = _spruceSkillUtils.diskUtil.resolvePath(destinationDir, 'src', 'index.ts');
|
|
64
|
+
files = [];
|
|
57
65
|
|
|
58
|
-
|
|
66
|
+
if ((options === null || options === void 0 ? void 0 : options.shouldWriteIndex) !== false) {
|
|
67
|
+
contents = '//exports go here\n';
|
|
68
|
+
destination = _spruceSkillUtils.diskUtil.resolvePath(destinationDir, 'src', 'index.ts');
|
|
59
69
|
|
|
60
|
-
|
|
61
|
-
|
|
70
|
+
_spruceSkillUtils.diskUtil.writeFile(destination, contents);
|
|
71
|
+
|
|
72
|
+
files.push({
|
|
73
|
+
name: 'src/index.ts',
|
|
74
|
+
description: 'Placeholder entry file!',
|
|
75
|
+
action: 'generated',
|
|
76
|
+
path: destination
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
_context.next = 4;
|
|
81
|
+
return this.writeDirectoryTemplate(_objectSpread({
|
|
62
82
|
destinationDir: destinationDir,
|
|
63
83
|
code: _spruceTemplates.DirectoryTemplateCode.Skill,
|
|
64
|
-
filesToWrite:
|
|
84
|
+
filesToWrite: NODE_FILES_TO_UPGRADE,
|
|
65
85
|
context: {
|
|
66
86
|
name: 'ignored',
|
|
67
87
|
description: 'ignored'
|
|
68
88
|
}
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
case
|
|
72
|
-
|
|
73
|
-
return _context.abrupt("return", [
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
action: 'generated',
|
|
77
|
-
path: destination
|
|
78
|
-
}].concat((0, _toConsumableArray2["default"])(files)));
|
|
79
|
-
|
|
80
|
-
case 7:
|
|
89
|
+
}, options));
|
|
90
|
+
|
|
91
|
+
case 4:
|
|
92
|
+
directoryTemplateFiles = _context.sent;
|
|
93
|
+
return _context.abrupt("return", [].concat(files, (0, _toConsumableArray2["default"])(directoryTemplateFiles)));
|
|
94
|
+
|
|
95
|
+
case 6:
|
|
81
96
|
case "end":
|
|
82
97
|
return _context.stop();
|
|
83
98
|
}
|
|
@@ -85,7 +100,7 @@ var NodeWriter = /*#__PURE__*/function (_AbstractWriter) {
|
|
|
85
100
|
}, _callee, this);
|
|
86
101
|
}));
|
|
87
102
|
|
|
88
|
-
function writeNodeModule(_x) {
|
|
103
|
+
function writeNodeModule(_x, _x2) {
|
|
89
104
|
return _writeNodeModule.apply(this, arguments);
|
|
90
105
|
}
|
|
91
106
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/features/node/writers/NodeWriter.ts"],"names":["NodeWriter","destinationDir","contents","destination","diskUtil","resolvePath","writeFile","
|
|
1
|
+
{"version":3,"sources":["../../../../src/features/node/writers/NodeWriter.ts"],"names":["NODE_FILES_TO_UPGRADE","NodeWriter","destinationDir","options","files","shouldWriteIndex","contents","destination","diskUtil","resolvePath","writeFile","push","name","description","action","path","writeDirectoryTemplate","code","DirectoryTemplateCode","Skill","filesToWrite","context","directoryTemplateFiles","AbstractWriter"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAEA;;;;;;;;;;AAKO,IAAMA,qBAAqB,GAAG,CACpC,eADoC,EAEpC,cAFoC,EAGpC,eAHoC,EAIpC,YAJoC,EAKpC,QALoC,CAA9B;;;IAOcC,U;;;;;;;;;;;;;2GACpB,iBACCC,cADD,EAECC,OAFD;AAAA;AAAA;AAAA;AAAA;AAAA;AAMKC,gBAAAA,KANL,GAM8B,EAN9B;;AAOC,oBAAI,CAAAD,OAAO,SAAP,IAAAA,OAAO,WAAP,YAAAA,OAAO,CAAEE,gBAAT,MAA8B,KAAlC,EAAyC;AAClCC,kBAAAA,QADkC,GACvB,qBADuB;AAElCC,kBAAAA,WAFkC,GAEpBC,2BAASC,WAAT,CACnBP,cADmB,EAEnB,KAFmB,EAGnB,UAHmB,CAFoB;;AAOxCM,6CAASE,SAAT,CAAmBH,WAAnB,EAAgCD,QAAhC;;AACAF,kBAAAA,KAAK,CAACO,IAAN,CAAW;AACVC,oBAAAA,IAAI,EAAE,cADI;AAEVC,oBAAAA,WAAW,EAAE,yBAFH;AAGVC,oBAAAA,MAAM,EAAE,WAHE;AAIVC,oBAAAA,IAAI,EAAER;AAJI,mBAAX;AAMA;;AArBF;AAAA,uBAuBsC,KAAKS,sBAAL;AACpCd,kBAAAA,cAAc,EAAdA,cADoC;AAEpCe,kBAAAA,IAAI,EAAEC,uCAAsBC,KAFQ;AAGpCC,kBAAAA,YAAY,EAAEpB,qBAHsB;AAIpCqB,kBAAAA,OAAO,EAAE;AAAET,oBAAAA,IAAI,EAAE,SAAR;AAAmBC,oBAAAA,WAAW,EAAE;AAAhC;AAJ2B,mBAKjCV,OALiC,EAvBtC;;AAAA;AAuBOmB,gBAAAA,sBAvBP;AAAA,2DA+BYlB,KA/BZ,sCA+BsBkB,sBA/BtB;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O;;;;;;;;;;EADuCC,2B","sourcesContent":["import { diskUtil } from '@sprucelabs/spruce-skill-utils'\nimport { DirectoryTemplateCode } from '@sprucelabs/spruce-templates'\nimport { GeneratedFile } from '../../../types/cli.types'\nimport AbstractWriter, {\n\tWriteDirectoryTemplateOptions,\n\tWriteResults,\n} from '../../../writers/AbstractWriter'\n\nexport const NODE_FILES_TO_UPGRADE = [\n\t'tsconfig.json',\n\t'.eslintrc.js',\n\t'.eslintignore',\n\t'.gitignore',\n\t'.nvmrc',\n]\nexport default class NodeWriter extends AbstractWriter {\n\tpublic async writeNodeModule(\n\t\tdestinationDir: string,\n\t\toptions?: Partial<WriteDirectoryTemplateOptions> & {\n\t\t\tshouldWriteIndex?: boolean\n\t\t}\n\t): Promise<WriteResults> {\n\t\tlet files: GeneratedFile[] = []\n\t\tif (options?.shouldWriteIndex !== false) {\n\t\t\tconst contents = '//exports go here\\n'\n\t\t\tconst destination = diskUtil.resolvePath(\n\t\t\t\tdestinationDir,\n\t\t\t\t'src',\n\t\t\t\t'index.ts'\n\t\t\t)\n\t\t\tdiskUtil.writeFile(destination, contents)\n\t\t\tfiles.push({\n\t\t\t\tname: 'src/index.ts',\n\t\t\t\tdescription: 'Placeholder entry file!',\n\t\t\t\taction: 'generated',\n\t\t\t\tpath: destination,\n\t\t\t})\n\t\t}\n\n\t\tconst directoryTemplateFiles = await this.writeDirectoryTemplate({\n\t\t\tdestinationDir,\n\t\t\tcode: DirectoryTemplateCode.Skill,\n\t\t\tfilesToWrite: NODE_FILES_TO_UPGRADE,\n\t\t\tcontext: { name: 'ignored', description: 'ignored' },\n\t\t\t...options,\n\t\t})\n\n\t\treturn [...files, ...directoryTemplateFiles]\n\t}\n}\n"],"file":"NodeWriter.js"}
|
|
@@ -23,6 +23,8 @@ var _spruceEventUtils = require("@sprucelabs/spruce-event-utils");
|
|
|
23
23
|
|
|
24
24
|
var _SpruceError = _interopRequireDefault(require("../../../errors/SpruceError"));
|
|
25
25
|
|
|
26
|
+
var _NodeWriter = require("../../node/writers/NodeWriter");
|
|
27
|
+
|
|
26
28
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
27
29
|
|
|
28
30
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -60,7 +62,7 @@ var Updater = /*#__PURE__*/function () {
|
|
|
60
62
|
case 6:
|
|
61
63
|
results = _context.sent;
|
|
62
64
|
_eventResponseUtil$ge = _spruceEventUtils.eventResponseUtil.getAllResponsePayloadsAndErrors(results, _SpruceError["default"]), payloads = _eventResponseUtil$ge.payloads;
|
|
63
|
-
filesToSkip = ['package.json'];
|
|
65
|
+
filesToSkip = [].concat((0, _toConsumableArray2["default"])(_NodeWriter.NODE_FILES_TO_UPGRADE), ['package.json']);
|
|
64
66
|
_iterator = _createForOfIteratorHelper(payloads);
|
|
65
67
|
|
|
66
68
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/features/skill/updaters/Updater.ts"],"names":["Updater","skill","emitter","feature","normalizedOptions","skillWriter","Writer","upgradeMode","pkgService","Service","name","get","description","emit","results","eventResponseUtil","getAllResponsePayloadsAndErrors","SpruceError","payloads","filesToSkip","payload","push","writeSkill","cwd","generatedFiles"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AAEA;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../../../../src/features/skill/updaters/Updater.ts"],"names":["Updater","skill","emitter","feature","normalizedOptions","skillWriter","Writer","upgradeMode","pkgService","Service","name","get","description","emit","results","eventResponseUtil","getAllResponsePayloadsAndErrors","SpruceError","payloads","filesToSkip","NODE_FILES_TO_UPGRADE","payload","push","writeSkill","cwd","generatedFiles"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AAEA;;AAGA;;;;;;;;IAOqBA,O;AAIpB,mBAAmBC,KAAnB,EAAmCC,OAAnC,EAA2D;AAAA;AAAA;AAAA;AAC1D,SAAKA,OAAL,GAAeA,OAAf;AACA,SAAKC,OAAL,GAAeF,KAAf;AACA;;;;;uGAED,iBAAyBG,iBAAzB;AAAA;;AAAA;AAAA;AAAA;AAAA;AACOC,gBAAAA,WADP,GACqB,KAAKF,OAAL,CAAaG,MAAb,CAAoB,OAApB,EAA6B;AAChDC,kBAAAA,WAAW,EAAEH,iBAAiB,CAACG;AADiB,iBAA7B,CADrB;AAIOC,gBAAAA,UAJP,GAIoB,KAAKL,OAAL,CAAaM,OAAb,CAAqB,KAArB,CAJpB;AAKOC,gBAAAA,IALP,GAKcF,UAAU,CAACG,GAAX,CAAe,MAAf,CALd;AAMOC,gBAAAA,WANP,GAMqBJ,UAAU,CAACG,GAAX,CAAe,aAAf,CANrB;AAAA;AAAA,uBAQuB,KAAKT,OAAL,CAAaW,IAAb,CACrB,qCADqB,CARvB;;AAAA;AAQOC,gBAAAA,OARP;AAAA,wCAYsBC,oCAAkBC,+BAAlB,CACpBF,OADoB,EAEpBG,uBAFoB,CAZtB,EAYSC,QAZT,yBAYSA,QAZT;AAiBOC,gBAAAA,WAjBP,iDAiByBC,iCAjBzB,IAiBgD,cAjBhD;AAAA,uDAmBuBF,QAnBvB;;AAAA;AAmBC,sEAAgC;AAArBG,oBAAAA,OAAqB;;AAC/B,wBAAIA,OAAO,CAACF,WAAZ,EAAyB;AACxBA,sBAAAA,WAAW,CAACG,IAAZ,OAAAH,WAAW,sCAASE,OAAO,CAACF,WAAjB,EAAX;AACA;AACD;AAvBF;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA,uBAyB8Bd,WAAW,CAACkB,UAAZ,CAAuB,KAAKpB,OAAL,CAAaqB,GAApC,EAAyC;AACrEd,kBAAAA,IAAI,EAAJA,IADqE;AAErEE,kBAAAA,WAAW,EAAXA,WAFqE;AAGrEO,kBAAAA,WAAW,EAAXA;AAHqE,iBAAzC,CAzB9B;;AAAA;AAyBOM,gBAAAA,cAzBP;AAAA,iDA+BQA,cA/BR;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O","sourcesContent":["import { eventResponseUtil } from '@sprucelabs/spruce-event-utils'\nimport { SpruceSchemas } from '#spruce/schemas/schemas.types'\nimport SpruceError from '../../../errors/SpruceError'\nimport { GlobalEmitter } from '../../../GlobalEmitter'\nimport AbstractFeature from '../../AbstractFeature'\nimport { NODE_FILES_TO_UPGRADE } from '../../node/writers/NodeWriter'\n\ntype UpgradeOptions = SpruceSchemas.SpruceCli.v2020_07_22.UpgradeSkillOptions\n\ntype Feature =\n\tAbstractFeature<SpruceSchemas.SpruceCli.v2020_07_22.SkillFeatureSchema>\n\nexport default class Updater {\n\tprivate feature: Feature\n\tprivate emitter: GlobalEmitter\n\n\tpublic constructor(skill: Feature, emitter: GlobalEmitter) {\n\t\tthis.emitter = emitter\n\t\tthis.feature = skill\n\t}\n\n\tpublic async updateFiles(normalizedOptions: UpgradeOptions) {\n\t\tconst skillWriter = this.feature.Writer('skill', {\n\t\t\tupgradeMode: normalizedOptions.upgradeMode,\n\t\t})\n\t\tconst pkgService = this.feature.Service('pkg')\n\t\tconst name = pkgService.get('name')\n\t\tconst description = pkgService.get('description')\n\n\t\tconst results = await this.emitter.emit(\n\t\t\t'skill.will-write-directory-template'\n\t\t)\n\n\t\tconst { payloads } = eventResponseUtil.getAllResponsePayloadsAndErrors(\n\t\t\tresults,\n\t\t\tSpruceError\n\t\t)\n\n\t\tconst filesToSkip = [...NODE_FILES_TO_UPGRADE, 'package.json']\n\n\t\tfor (const payload of payloads) {\n\t\t\tif (payload.filesToSkip) {\n\t\t\t\tfilesToSkip.push(...payload.filesToSkip)\n\t\t\t}\n\t\t}\n\n\t\tconst generatedFiles = await skillWriter.writeSkill(this.feature.cwd, {\n\t\t\tname,\n\t\t\tdescription,\n\t\t\tfilesToSkip,\n\t\t})\n\n\t\treturn generatedFiles\n\t}\n}\n"],"file":"Updater.js"}
|
|
@@ -2,5 +2,6 @@ import SpyInterface from '../../interfaces/SpyInterface';
|
|
|
2
2
|
declare const uiAssertUtil: {
|
|
3
3
|
assertRendersSelect(ui: SpyInterface): Promise<void>;
|
|
4
4
|
assertSelectDidNotRenderChoice(ui: SpyInterface, value: string, label: string): void;
|
|
5
|
+
assertRendersConfirmWriteFile(ui: SpyInterface): Promise<void>;
|
|
5
6
|
};
|
|
6
7
|
export default uiAssertUtil;
|
|
@@ -44,6 +44,40 @@ var uiAssertUtil = {
|
|
|
44
44
|
value: value,
|
|
45
45
|
label: label
|
|
46
46
|
});
|
|
47
|
+
},
|
|
48
|
+
assertRendersConfirmWriteFile: function assertRendersConfirmWriteFile(ui) {
|
|
49
|
+
return (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
|
|
50
|
+
var last;
|
|
51
|
+
return _regenerator["default"].wrap(function _callee2$(_context2) {
|
|
52
|
+
while (1) {
|
|
53
|
+
switch (_context2.prev = _context2.next) {
|
|
54
|
+
case 0:
|
|
55
|
+
_context2.next = 2;
|
|
56
|
+
return ui.waitForInput();
|
|
57
|
+
|
|
58
|
+
case 2:
|
|
59
|
+
last = ui.getLastInvocation();
|
|
60
|
+
|
|
61
|
+
_test.assert.isEqual(last.options.type, 'select');
|
|
62
|
+
|
|
63
|
+
_test.assert.isEqualDeep(last.options.options.choices, [{
|
|
64
|
+
label: 'Overwrite',
|
|
65
|
+
value: 'overwrite'
|
|
66
|
+
}, {
|
|
67
|
+
value: 'skip',
|
|
68
|
+
label: 'Skip'
|
|
69
|
+
}, {
|
|
70
|
+
value: 'alwaysSkip',
|
|
71
|
+
label: 'Always skip'
|
|
72
|
+
}]);
|
|
73
|
+
|
|
74
|
+
case 5:
|
|
75
|
+
case "end":
|
|
76
|
+
return _context2.stop();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}, _callee2);
|
|
80
|
+
}))();
|
|
47
81
|
}
|
|
48
82
|
};
|
|
49
83
|
var _default = uiAssertUtil;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/tests/utilities/uiAssert.utility.ts"],"names":["uiAssertUtil","assertRendersSelect","ui","waitForInput","last","getLastInvocation","assert","isTruthy","options","choices","assertSelectDidNotRenderChoice","value","label","doesNotInclude"],"mappings":";;;;;;;;;;;;;AAAA;;AAGA,IAAMA,YAAY,GAAG;AACdC,EAAAA,mBADc,+BACMC,EADN,EACwB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBACrCA,EAAE,CAACC,YAAH,EADqC;;AAAA;AAGrCC,cAAAA,IAHqC,GAG9BF,EAAE,CAACG,iBAAH,EAH8B;;AAI3CC,2BAAOC,QAAP,CACCH,IAAI,CAACI,OAAL,CAAaA,OAAb,CAAqBC,OADtB;;AAJ2C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQ3C,GATmB;AAWpBC,EAAAA,8BAXoB,0CAYnBR,EAZmB,EAanBS,KAbmB,EAcnBC,KAdmB,EAelB;AACD,QAAMR,IAAI,GAAGF,EAAE,CAACG,iBAAH,EAAb;;AAEAC,iBAAOO,cAAP,CAAsBT,IAAI,CAACI,OAAL,CAAaA,OAAb,CAAqBC,OAA3C,EAAoD;AACnDE,MAAAA,KAAK,EAALA,KADmD;AAEnDC,MAAAA,KAAK,EAALA;AAFmD,KAApD;AAIA;
|
|
1
|
+
{"version":3,"sources":["../../../src/tests/utilities/uiAssert.utility.ts"],"names":["uiAssertUtil","assertRendersSelect","ui","waitForInput","last","getLastInvocation","assert","isTruthy","options","choices","assertSelectDidNotRenderChoice","value","label","doesNotInclude","assertRendersConfirmWriteFile","isEqual","type","isEqualDeep"],"mappings":";;;;;;;;;;;;;AAAA;;AAGA,IAAMA,YAAY,GAAG;AACdC,EAAAA,mBADc,+BACMC,EADN,EACwB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBACrCA,EAAE,CAACC,YAAH,EADqC;;AAAA;AAGrCC,cAAAA,IAHqC,GAG9BF,EAAE,CAACG,iBAAH,EAH8B;;AAI3CC,2BAAOC,QAAP,CACCH,IAAI,CAACI,OAAL,CAAaA,OAAb,CAAqBC,OADtB;;AAJ2C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQ3C,GATmB;AAWpBC,EAAAA,8BAXoB,0CAYnBR,EAZmB,EAanBS,KAbmB,EAcnBC,KAdmB,EAelB;AACD,QAAMR,IAAI,GAAGF,EAAE,CAACG,iBAAH,EAAb;;AAEAC,iBAAOO,cAAP,CAAsBT,IAAI,CAACI,OAAL,CAAaA,OAAb,CAAqBC,OAA3C,EAAoD;AACnDE,MAAAA,KAAK,EAALA,KADmD;AAEnDC,MAAAA,KAAK,EAALA;AAFmD,KAApD;AAIA,GAtBmB;AAwBdE,EAAAA,6BAxBc,yCAwBgBZ,EAxBhB,EAwBkC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAC/CA,EAAE,CAACC,YAAH,EAD+C;;AAAA;AAG/CC,cAAAA,IAH+C,GAGxCF,EAAE,CAACG,iBAAH,EAHwC;;AAKrDC,2BAAOS,OAAP,CAAeX,IAAI,CAACI,OAAL,CAAaQ,IAA5B,EAAkC,QAAlC;;AACAV,2BAAOW,WAAP,CAAmBb,IAAI,CAACI,OAAL,CAAaA,OAAb,CAAqBC,OAAxC,EAAiD,CAChD;AACCG,gBAAAA,KAAK,EAAE,WADR;AAECD,gBAAAA,KAAK,EAAE;AAFR,eADgD,EAKhD;AAAEA,gBAAAA,KAAK,EAAE,MAAT;AAAiBC,gBAAAA,KAAK,EAAE;AAAxB,eALgD,EAMhD;AAAED,gBAAAA,KAAK,EAAE,YAAT;AAAuBC,gBAAAA,KAAK,EAAE;AAA9B,eANgD,CAAjD;;AANqD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAcrD;AAtCmB,CAArB;eAyCeZ,Y","sourcesContent":["import { assert } from '@sprucelabs/test'\nimport SpyInterface from '../../interfaces/SpyInterface'\n\nconst uiAssertUtil = {\n\tasync assertRendersSelect(ui: SpyInterface) {\n\t\tawait ui.waitForInput()\n\n\t\tconst last = ui.getLastInvocation()\n\t\tassert.isTruthy(\n\t\t\tlast.options.options.choices,\n\t\t\t`I expected a select, I did not find one!`\n\t\t)\n\t},\n\n\tassertSelectDidNotRenderChoice(\n\t\tui: SpyInterface,\n\t\tvalue: string,\n\t\tlabel: string\n\t) {\n\t\tconst last = ui.getLastInvocation()\n\n\t\tassert.doesNotInclude(last.options.options.choices, {\n\t\t\tvalue,\n\t\t\tlabel,\n\t\t})\n\t},\n\n\tasync assertRendersConfirmWriteFile(ui: SpyInterface) {\n\t\tawait ui.waitForInput()\n\n\t\tconst last = ui.getLastInvocation()\n\n\t\tassert.isEqual(last.options.type, 'select')\n\t\tassert.isEqualDeep(last.options.options.choices, [\n\t\t\t{\n\t\t\t\tlabel: 'Overwrite',\n\t\t\t\tvalue: 'overwrite',\n\t\t\t},\n\t\t\t{ value: 'skip', label: 'Skip' },\n\t\t\t{ value: 'alwaysSkip', label: 'Always skip' },\n\t\t])\n\t},\n}\n\nexport default uiAssertUtil\n"],"file":"uiAssert.utility.js"}
|
|
@@ -7,12 +7,20 @@ export declare type WriteResults = GeneratedFile[];
|
|
|
7
7
|
export interface WriterOptions {
|
|
8
8
|
templates: Templates;
|
|
9
9
|
term: GraphicsInterface;
|
|
10
|
-
askBeforeUpdating?: boolean;
|
|
11
10
|
upgradeMode?: UpgradeMode;
|
|
12
11
|
fileDescriptions: FileDescription[];
|
|
13
12
|
linter?: LintService;
|
|
14
13
|
settings: SettingsService;
|
|
15
14
|
}
|
|
15
|
+
export interface WriteDirectoryTemplateOptions {
|
|
16
|
+
destinationDir: string;
|
|
17
|
+
code: DirectoryTemplateCode;
|
|
18
|
+
filesToWrite?: string[];
|
|
19
|
+
filesToSkip?: string[];
|
|
20
|
+
context: any;
|
|
21
|
+
shouldConfirmBeforeWriting?: boolean;
|
|
22
|
+
firstFileWriteMessage?: string;
|
|
23
|
+
}
|
|
16
24
|
export default abstract class AbstractWriter {
|
|
17
25
|
protected templates: Templates;
|
|
18
26
|
protected ui: GraphicsInterface;
|
|
@@ -28,15 +36,7 @@ export default abstract class AbstractWriter {
|
|
|
28
36
|
protected lint(file: string): Promise<void>;
|
|
29
37
|
static disableLinting(): void;
|
|
30
38
|
static enableLinting(): void;
|
|
31
|
-
protected writeDirectoryTemplate(options:
|
|
32
|
-
destinationDir: string;
|
|
33
|
-
code: DirectoryTemplateCode;
|
|
34
|
-
filesToWrite?: string[];
|
|
35
|
-
filesToSkip?: string[];
|
|
36
|
-
context: any;
|
|
37
|
-
shouldConfirmBeforeWriting?: boolean;
|
|
38
|
-
firstFileWriteMessage?: string;
|
|
39
|
-
}): Promise<WriteResults>;
|
|
39
|
+
protected writeDirectoryTemplate(options: WriteDirectoryTemplateOptions): Promise<WriteResults>;
|
|
40
40
|
protected writeFileIfChangedMixinResults(destination: string, contents: string, description: string, results?: WriteResults, cwd?: string): Promise<WriteResults>;
|
|
41
41
|
private isFileDifferent;
|
|
42
42
|
private cleanFilename;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/writers/AbstractWriter.ts"],"names":["AbstractWriter","options","templates","ui","term","upgradeMode","fileDescriptions","linter","settings","file","isLintingEnabled","startLoading","pathUtil","basename","fix","context","destinationDir","filesToWrite","filesToSkip","shouldConfirmBeforeWriting","firstFileWriteMessage","hasShownFirstWriteMessage","directoryTemplate","kind","code","files","results","generated","shouldWrite","indexOf","filename","shouldSkip","writeFileIfChangedMixinResults","join","relativePath","contents","destination","description","cwd","myResults","desc","name","action","diskUtil","isDir","Error","fileDescription","getFileDescription","doesFileExist","write","confirmPromptOnFirstWrite","stopLoading","confirm","writeFile","isFileDifferent","shouldOverwriteIfChanged","cleanedName","cleanFilename","skipped","get","isAlwaysSkipped","shouldAskForOverwrite","renderLine","prompt","type","label","choices","value","FILE_ACTION_OVERWRITE","FILE_ACTION_SKIP","FILE_ACTION_ALWAYS_SKIP","answer","push","set","replace","path","relativeFile","sep","substr","shouldOverwriteWhenChanged","lower","toLowerCase","d","search","undefined","dirOrFile","fallbackFileName","doesDirExist","fs","lstatSync","isDirectory","extname","length","resolvePath"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAEA;;;;;;;;;;;;IAqB8BA,c;AAY7B,0BAAmBC,OAAnB,EAA2C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,+DAPG,EAOH;AAAA,yEANN,IAMM;AAAA;AAAA,wEAHP,KAGO;AAAA;AAC1C,SAAKC,SAAL,GAAiBD,OAAO,CAACC,SAAzB;AACA,SAAKC,EAAL,GAAUF,OAAO,CAACG,IAAlB;AACA,SAAKC,WAAL,GAAmBJ,OAAO,CAACI,WAA3B;AACA,SAAKC,gBAAL,GAAwBL,OAAO,CAACK,gBAAhC;AACA,SAAKC,MAAL,GAAcN,OAAO,CAACM,MAAtB;AACA,SAAKC,QAAL,GAAgBP,OAAO,CAACO,QAAxB;AACA;;;;;gGAED,iBAAqBC,IAArB;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA,qBACKT,cAAc,CAACU,gBADpB;AAAA;AAAA;AAAA;;AAEE,qBAAKP,EAAL,CAAQQ,YAAR,mBAAgCC,iBAASC,QAAT,CAAkBJ,IAAlB,CAAhC;AAFF;AAAA,uCAGQ,KAAKF,MAHb,iDAGQ,aAAaO,GAAb,CAAiBL,IAAjB,WAA6B,YAAM,CAAE,CAArC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AP;AACA;;;WAED,qCACCgF,SADD,EAECC,gBAFD,EAGE;AACD,UAAM1C,KAAK,GACVD,2BAAS4C,YAAT,CAAsBF,SAAtB,KACAG,eAAGC,SAAH,CAAaJ,SAAb,EAAwBK,WAAxB,EADA,IAEA9E,iBAAS+E,OAAT,CAAiBN,SAAjB,EAA4BO,MAA5B,KAAuC,CAHxC;AAIA,aAAOhD,KAAK,GAAGD,2BAASkD,WAAT,CAAqBR,SAArB,EAAgCC,gBAAhC,CAAH,GAAuDD,SAAnE;AACA;;;WAxND,0BAA+B;AAC9B,WAAK3E,gBAAL,GAAwB,KAAxB;AACA;;;WAED,yBAA8B;AAC7B,WAAKA,gBAAL,GAAwB,IAAxB;AACA;;;;;;iCAlC4BV,c,sBAOK,I","sourcesContent":["import fs from 'fs'\nimport pathUtil from 'path'\nimport { diskUtil, SettingsService } from '@sprucelabs/spruce-skill-utils'\nimport { DirectoryTemplateCode, Templates } from '@sprucelabs/spruce-templates'\nimport {\n\tFILE_ACTION_ALWAYS_SKIP,\n\tFILE_ACTION_OVERWRITE,\n\tFILE_ACTION_SKIP,\n} from '../constants'\nimport LintService from '../services/LintService'\nimport { FileDescription, GeneratedFile, UpgradeMode } from '../types/cli.types'\nimport { GraphicsInterface } from '../types/cli.types'\n\nexport type WriteResults = GeneratedFile[]\n\nexport interface WriterOptions {\n\ttemplates: Templates\n\tterm: GraphicsInterface\n\taskBeforeUpdating?: boolean\n\tupgradeMode?: UpgradeMode\n\tfileDescriptions: FileDescription[]\n\tlinter?: LintService\n\tsettings: SettingsService\n}\n\nexport default abstract class AbstractWriter {\n\tprotected templates: Templates\n\tprotected ui: GraphicsInterface\n\tprivate linter?: LintService\n\tprivate upgradeMode: UpgradeMode\n\tprivate fileDescriptions: FileDescription[] = []\n\tprivate shouldConfirmBeforeWriting = true\n\tprivate static isLintingEnabled = true\n\tprivate firstFileWriteMessage?: string\n\tprivate hasShownFirstWriteMessage = false\n\tprivate settings: SettingsService<string>\n\n\tpublic constructor(options: WriterOptions) {\n\t\tthis.templates = options.templates\n\t\tthis.ui = options.term\n\t\tthis.upgradeMode = options.upgradeMode\n\t\tthis.fileDescriptions = options.fileDescriptions\n\t\tthis.linter = options.linter\n\t\tthis.settings = options.settings\n\t}\n\n\tprotected async lint(file: string) {\n\t\tif (AbstractWriter.isLintingEnabled) {\n\t\t\tthis.ui.startLoading(`Linting ${pathUtil.basename(file)}...`)\n\t\t\tawait this.linter?.fix(file).catch(() => {})\n\t\t}\n\t}\n\n\tpublic static disableLinting() {\n\t\tthis.isLintingEnabled = false\n\t}\n\n\tpublic static enableLinting() {\n\t\tthis.isLintingEnabled = true\n\t}\n\n\tprotected async writeDirectoryTemplate(options: {\n\t\tdestinationDir: string\n\t\tcode: DirectoryTemplateCode\n\t\tfilesToWrite?: string[]\n\t\tfilesToSkip?: string[]\n\t\tcontext: any\n\t\tshouldConfirmBeforeWriting?: boolean\n\t\tfirstFileWriteMessage?: string\n\t}) {\n\t\tconst {\n\t\t\tcontext,\n\t\t\tdestinationDir,\n\t\t\tfilesToWrite,\n\t\t\tfilesToSkip,\n\t\t\tshouldConfirmBeforeWriting = true,\n\t\t\tfirstFileWriteMessage,\n\t\t} = options\n\n\t\tthis.shouldConfirmBeforeWriting = shouldConfirmBeforeWriting\n\t\tthis.firstFileWriteMessage = firstFileWriteMessage\n\t\tthis.hasShownFirstWriteMessage = false\n\n\t\tconst files = await this.templates.directoryTemplate({\n\t\t\tkind: options.code,\n\t\t\tcontext: context ?? {},\n\t\t})\n\n\t\tlet results: WriteResults = []\n\n\t\tfor (const generated of files) {\n\t\t\tconst shouldWrite =\n\t\t\t\t!filesToWrite || filesToWrite.indexOf(generated.filename) > -1\n\t\t\tconst shouldSkip =\n\t\t\t\tfilesToSkip && filesToSkip.indexOf(generated.filename) > -1\n\t\t\tif (shouldWrite && !shouldSkip) {\n\t\t\t\tresults = await this.writeFileIfChangedMixinResults(\n\t\t\t\t\tpathUtil.join(destinationDir, generated.relativePath),\n\t\t\t\t\tgenerated.contents,\n\t\t\t\t\t'',\n\t\t\t\t\tresults,\n\t\t\t\t\tdestinationDir\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\treturn results\n\t}\n\n\tprotected async writeFileIfChangedMixinResults(\n\t\tdestination: string,\n\t\tcontents: string,\n\t\tdescription: string,\n\t\tresults?: WriteResults,\n\t\tcwd = ''\n\t): Promise<WriteResults> {\n\t\tconst myResults: WriteResults = results ?? []\n\t\tlet desc: string | undefined = description\n\n\t\tconst name = pathUtil.basename(destination)\n\t\tlet action: GeneratedFile['action'] = 'skipped'\n\n\t\tif (diskUtil.isDir(destination)) {\n\t\t\tthrow new Error(`Can't write to a directory ${destination}.`)\n\t\t}\n\n\t\tconst fileDescription = this.getFileDescription(destination)\n\n\t\tif (!diskUtil.doesFileExist(destination)) {\n\t\t\tlet write = true\n\t\t\tif (\n\t\t\t\tthis.shouldConfirmBeforeWriting &&\n\t\t\t\tfileDescription?.confirmPromptOnFirstWrite\n\t\t\t) {\n\t\t\t\tthis.ui.stopLoading()\n\t\t\t\twrite = await this.ui.confirm(fileDescription.confirmPromptOnFirstWrite)\n\t\t\t}\n\n\t\t\tif (write) {\n\t\t\t\tdiskUtil.writeFile(destination, contents)\n\t\t\t\taction = 'generated'\n\t\t\t}\n\t\t} else if (\n\t\t\tthis.isFileDifferent(destination, contents) &&\n\t\t\tthis.shouldOverwriteIfChanged(destination)\n\t\t) {\n\t\t\tconst cleanedName = this.cleanFilename(destination, cwd)\n\t\t\tconst settings = { skipped: [], ...this.settings.get('writer') }\n\t\t\tconst isAlwaysSkipped = settings.skipped.indexOf(cleanedName) > -1\n\t\t\tlet write = !isAlwaysSkipped\n\n\t\t\tif (!isAlwaysSkipped && this.shouldAskForOverwrite()) {\n\t\t\t\tif (!this.hasShownFirstWriteMessage && this.firstFileWriteMessage) {\n\t\t\t\t\tthis.hasShownFirstWriteMessage = true\n\t\t\t\t\tthis.ui.renderLine(this.firstFileWriteMessage)\n\t\t\t\t\tthis.ui.renderLine('')\n\t\t\t\t}\n\n\t\t\t\tconst answer = await this.ui.prompt({\n\t\t\t\t\ttype: 'select',\n\t\t\t\t\tlabel: `${cleanedName}`,\n\t\t\t\t\toptions: {\n\t\t\t\t\t\tchoices: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tvalue: FILE_ACTION_OVERWRITE,\n\t\t\t\t\t\t\t\tlabel: 'Overwrite',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tvalue: FILE_ACTION_SKIP,\n\t\t\t\t\t\t\t\tlabel: 'Skip',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tvalue: FILE_ACTION_ALWAYS_SKIP,\n\t\t\t\t\t\t\t\tlabel: 'Always skip',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t})\n\n\t\t\t\tif (answer === FILE_ACTION_ALWAYS_SKIP) {\n\t\t\t\t\tsettings.skipped.push(cleanedName)\n\t\t\t\t\tthis.settings.set('writer', settings)\n\t\t\t\t}\n\n\t\t\t\twrite = answer === FILE_ACTION_OVERWRITE\n\t\t\t}\n\n\t\t\tif (write) {\n\t\t\t\tdiskUtil.writeFile(destination, contents)\n\t\t\t\taction = 'updated'\n\t\t\t}\n\t\t}\n\n\t\tif (!desc) {\n\t\t\tdesc = fileDescription?.description\n\t\t}\n\n\t\tif (!desc) {\n\t\t\tthrow new Error(\n\t\t\t\t`No FileDescription provided for ${destination.replace(\n\t\t\t\t\tcwd,\n\t\t\t\t\t''\n\t\t\t\t)}. Check your feature's fileDescriptions property.`\n\t\t\t)\n\t\t}\n\n\t\tmyResults.push({ name, description: desc, path: destination, action })\n\n\t\treturn myResults\n\t}\n\n\tprivate isFileDifferent(destination: string, contents: string) {\n\t\treturn diskUtil.isFileDifferent(destination, contents)\n\t}\n\n\tprivate cleanFilename(destination: string, cwd: string) {\n\t\tlet relativeFile = destination.replace(cwd, '')\n\t\tif (relativeFile[0] === pathUtil.sep) {\n\t\t\trelativeFile = relativeFile.substr(1)\n\t\t}\n\t\treturn relativeFile\n\t}\n\n\tprivate shouldOverwriteIfChanged(destination: string): boolean {\n\t\tif (!this.upgradeMode) {\n\t\t\treturn true\n\t\t}\n\n\t\tif (this.upgradeMode === 'forceEverything') {\n\t\t\treturn true\n\t\t}\n\n\t\tlet description: FileDescription | undefined =\n\t\t\tthis.getFileDescription(destination)\n\n\t\treturn description?.shouldOverwriteWhenChanged ?? false\n\t}\n\n\tprivate getFileDescription(destination: string): FileDescription | undefined {\n\t\tconst lower = destination.toLowerCase()\n\t\tfor (const d of this.fileDescriptions ?? []) {\n\t\t\tif (lower.search(d.path.toLowerCase()) > -1) {\n\t\t\t\treturn d\n\t\t\t}\n\t\t}\n\n\t\treturn undefined\n\t}\n\n\tprivate shouldAskForOverwrite() {\n\t\tif (\n\t\t\tthis.shouldConfirmBeforeWriting &&\n\t\t\tthis.upgradeMode === 'askForChanged'\n\t\t) {\n\t\t\treturn true\n\t\t}\n\n\t\treturn false\n\t}\n\n\tprotected resolveFilenameWithFallback(\n\t\tdirOrFile: string,\n\t\tfallbackFileName: string\n\t) {\n\t\tconst isDir =\n\t\t\tdiskUtil.doesDirExist(dirOrFile) &&\n\t\t\tfs.lstatSync(dirOrFile).isDirectory() &&\n\t\t\tpathUtil.extname(dirOrFile).length === 0\n\t\treturn isDir ? diskUtil.resolvePath(dirOrFile, fallbackFileName) : dirOrFile\n\t}\n}\n"],"file":"AbstractWriter.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/writers/AbstractWriter.ts"],"names":["AbstractWriter","options","templates","ui","term","upgradeMode","fileDescriptions","linter","settings","file","isLintingEnabled","startLoading","pathUtil","basename","fix","context","destinationDir","filesToWrite","filesToSkip","shouldConfirmBeforeWriting","firstFileWriteMessage","hasShownFirstWriteMessage","directoryTemplate","kind","code","files","results","generated","shouldWrite","indexOf","filename","shouldSkip","writeFileIfChangedMixinResults","join","relativePath","contents","destination","description","cwd","myResults","desc","name","action","diskUtil","isDir","Error","fileDescription","getFileDescription","doesFileExist","write","confirmPromptOnFirstWrite","stopLoading","confirm","writeFile","isFileDifferent","shouldOverwriteIfChanged","cleanedName","cleanFilename","skipped","get","isAlwaysSkipped","shouldAskForOverwrite","renderLine","prompt","type","label","choices","value","FILE_ACTION_OVERWRITE","FILE_ACTION_SKIP","FILE_ACTION_ALWAYS_SKIP","answer","push","set","replace","path","relativeFile","sep","substr","shouldOverwriteWhenChanged","lower","toLowerCase","d","search","undefined","dirOrFile","fallbackFileName","doesDirExist","fs","lstatSync","isDirectory","extname","length","resolvePath"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAEA;;;;;;;;;;;;IA8B8BA,c;AAY7B,0BAAmBC,OAAnB,EAA2C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,+DAPG,EAOH;AAAA,yEANN,IAMM;AAAA;AAAA,wEAHP,KAGO;AAAA;AAC1C,SAAKC,SAAL,GAAiBD,OAAO,CAACC,SAAzB;AACA,SAAKC,EAAL,GAAUF,OAAO,CAACG,IAAlB;AACA,SAAKC,WAAL,GAAmBJ,OAAO,CAACI,WAA3B;AACA,SAAKC,gBAAL,GAAwBL,OAAO,CAACK,gBAAhC;AACA,SAAKC,MAAL,GAAcN,OAAO,CAACM,MAAtB;AACA,SAAKC,QAAL,GAAgBP,OAAO,CAACO,QAAxB;AACA;;;;;gGAED,iBAAqBC,IAArB;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA,qBACKT,cAAc,CAACU,gBADpB;AAAA;AAAA;AAAA;;AAEE,qBAAKP,EAAL,CAAQQ,YAAR,mBAAgCC,iBAASC,QAAT,CAAkBJ,IAAlB,CAAhC;AAFF;AAAA,uCAGQ,KAAKF,MAHb,iDAGQ,aAAaO,GAAb,CAAiBL,IAAjB,WAA6B,YAAM,CAAE,CAArC,CAHR;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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4C,YAAT,CAAsBF,SAAtB,KACAG,eAAGC,SAAH,CAAaJ,SAAb,EAAwBK,WAAxB,EADA,IAEA9E,iBAAS+E,OAAT,CAAiBN,SAAjB,EAA4BO,MAA5B,KAAuC,CAHxC;AAIA,aAAOhD,KAAK,GAAGD,2BAASkD,WAAT,CAAqBR,SAArB,EAAgCC,gBAAhC,CAAH,GAAuDD,SAAnE;AACA;;;WApND,0BAA+B;AAC9B,WAAK3E,gBAAL,GAAwB,KAAxB;AACA;;;WAED,yBAA8B;AAC7B,WAAKA,gBAAL,GAAwB,IAAxB;AACA;;;;;;iCAlC4BV,c,sBAOK,I","sourcesContent":["import fs from 'fs'\nimport pathUtil from 'path'\nimport { diskUtil, SettingsService } from '@sprucelabs/spruce-skill-utils'\nimport { DirectoryTemplateCode, Templates } from '@sprucelabs/spruce-templates'\nimport {\n\tFILE_ACTION_ALWAYS_SKIP,\n\tFILE_ACTION_OVERWRITE,\n\tFILE_ACTION_SKIP,\n} from '../constants'\nimport LintService from '../services/LintService'\nimport { FileDescription, GeneratedFile, UpgradeMode } from '../types/cli.types'\nimport { GraphicsInterface } from '../types/cli.types'\n\nexport type WriteResults = GeneratedFile[]\n\nexport interface WriterOptions {\n\ttemplates: Templates\n\tterm: GraphicsInterface\n\tupgradeMode?: UpgradeMode\n\tfileDescriptions: FileDescription[]\n\tlinter?: LintService\n\tsettings: SettingsService\n}\n\nexport interface WriteDirectoryTemplateOptions {\n\tdestinationDir: string\n\tcode: DirectoryTemplateCode\n\tfilesToWrite?: string[]\n\tfilesToSkip?: string[]\n\tcontext: any\n\tshouldConfirmBeforeWriting?: boolean\n\tfirstFileWriteMessage?: string\n}\n\nexport default abstract class AbstractWriter {\n\tprotected templates: Templates\n\tprotected ui: GraphicsInterface\n\tprivate linter?: LintService\n\tprivate upgradeMode: UpgradeMode\n\tprivate fileDescriptions: FileDescription[] = []\n\tprivate shouldConfirmBeforeWriting = true\n\tprivate static isLintingEnabled = true\n\tprivate firstFileWriteMessage?: string\n\tprivate hasShownFirstWriteMessage = false\n\tprivate settings: SettingsService<string>\n\n\tpublic constructor(options: WriterOptions) {\n\t\tthis.templates = options.templates\n\t\tthis.ui = options.term\n\t\tthis.upgradeMode = options.upgradeMode\n\t\tthis.fileDescriptions = options.fileDescriptions\n\t\tthis.linter = options.linter\n\t\tthis.settings = options.settings\n\t}\n\n\tprotected async lint(file: string) {\n\t\tif (AbstractWriter.isLintingEnabled) {\n\t\t\tthis.ui.startLoading(`Linting ${pathUtil.basename(file)}...`)\n\t\t\tawait this.linter?.fix(file).catch(() => {})\n\t\t}\n\t}\n\n\tpublic static disableLinting() {\n\t\tthis.isLintingEnabled = false\n\t}\n\n\tpublic static enableLinting() {\n\t\tthis.isLintingEnabled = true\n\t}\n\n\tprotected async writeDirectoryTemplate(\n\t\toptions: WriteDirectoryTemplateOptions\n\t) {\n\t\tconst {\n\t\t\tcontext,\n\t\t\tdestinationDir,\n\t\t\tfilesToWrite,\n\t\t\tfilesToSkip,\n\t\t\tshouldConfirmBeforeWriting = true,\n\t\t\tfirstFileWriteMessage,\n\t\t} = options\n\n\t\tthis.shouldConfirmBeforeWriting = shouldConfirmBeforeWriting\n\t\tthis.firstFileWriteMessage = firstFileWriteMessage\n\t\tthis.hasShownFirstWriteMessage = false\n\n\t\tconst files = await this.templates.directoryTemplate({\n\t\t\tkind: options.code,\n\t\t\tcontext: context ?? {},\n\t\t})\n\n\t\tlet results: WriteResults = []\n\n\t\tfor (const generated of files) {\n\t\t\tconst shouldWrite =\n\t\t\t\t!filesToWrite || filesToWrite.indexOf(generated.filename) > -1\n\t\t\tconst shouldSkip =\n\t\t\t\tfilesToSkip && filesToSkip.indexOf(generated.filename) > -1\n\n\t\t\tif (shouldWrite && !shouldSkip) {\n\t\t\t\tresults = await this.writeFileIfChangedMixinResults(\n\t\t\t\t\tpathUtil.join(destinationDir, generated.relativePath),\n\t\t\t\t\tgenerated.contents,\n\t\t\t\t\t'',\n\t\t\t\t\tresults,\n\t\t\t\t\tdestinationDir\n\t\t\t\t)\n\t\t\t}\n\t\t}\n\n\t\treturn results\n\t}\n\n\tprotected async writeFileIfChangedMixinResults(\n\t\tdestination: string,\n\t\tcontents: string,\n\t\tdescription: string,\n\t\tresults?: WriteResults,\n\t\tcwd = ''\n\t): Promise<WriteResults> {\n\t\tconst myResults: WriteResults = results ?? []\n\t\tlet desc: string | undefined = description\n\n\t\tconst name = pathUtil.basename(destination)\n\t\tlet action: GeneratedFile['action'] = 'skipped'\n\n\t\tif (diskUtil.isDir(destination)) {\n\t\t\tthrow new Error(`Can't write to a directory ${destination}.`)\n\t\t}\n\n\t\tconst fileDescription = this.getFileDescription(destination)\n\n\t\tif (!diskUtil.doesFileExist(destination)) {\n\t\t\tlet write = true\n\n\t\t\tif (\n\t\t\t\tthis.shouldConfirmBeforeWriting &&\n\t\t\t\tfileDescription?.confirmPromptOnFirstWrite\n\t\t\t) {\n\t\t\t\tthis.ui.stopLoading()\n\t\t\t\twrite = await this.ui.confirm(fileDescription.confirmPromptOnFirstWrite)\n\t\t\t}\n\n\t\t\tif (write) {\n\t\t\t\tdiskUtil.writeFile(destination, contents)\n\t\t\t\taction = 'generated'\n\t\t\t}\n\t\t} else if (\n\t\t\tthis.isFileDifferent(destination, contents) &&\n\t\t\tthis.shouldOverwriteIfChanged(destination)\n\t\t) {\n\t\t\tconst cleanedName = this.cleanFilename(destination, cwd)\n\t\t\tconst settings = { skipped: [], ...this.settings.get('writer') }\n\t\t\tconst isAlwaysSkipped = settings.skipped.indexOf(cleanedName) > -1\n\t\t\tlet write = !isAlwaysSkipped\n\n\t\t\tif (!isAlwaysSkipped && this.shouldAskForOverwrite()) {\n\t\t\t\tif (!this.hasShownFirstWriteMessage && this.firstFileWriteMessage) {\n\t\t\t\t\tthis.hasShownFirstWriteMessage = true\n\t\t\t\t\tthis.ui.renderLine(this.firstFileWriteMessage)\n\t\t\t\t\tthis.ui.renderLine('')\n\t\t\t\t}\n\n\t\t\t\tconst answer = await this.ui.prompt({\n\t\t\t\t\ttype: 'select',\n\t\t\t\t\tlabel: `${cleanedName}`,\n\t\t\t\t\toptions: {\n\t\t\t\t\t\tchoices: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tvalue: FILE_ACTION_OVERWRITE,\n\t\t\t\t\t\t\t\tlabel: 'Overwrite',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tvalue: FILE_ACTION_SKIP,\n\t\t\t\t\t\t\t\tlabel: 'Skip',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tvalue: FILE_ACTION_ALWAYS_SKIP,\n\t\t\t\t\t\t\t\tlabel: 'Always skip',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t})\n\n\t\t\t\tif (answer === FILE_ACTION_ALWAYS_SKIP) {\n\t\t\t\t\tsettings.skipped.push(cleanedName)\n\t\t\t\t\tthis.settings.set('writer', settings)\n\t\t\t\t}\n\n\t\t\t\twrite = answer === FILE_ACTION_OVERWRITE\n\t\t\t}\n\n\t\t\tif (write) {\n\t\t\t\tdiskUtil.writeFile(destination, contents)\n\t\t\t\taction = 'updated'\n\t\t\t}\n\t\t}\n\n\t\tif (!desc) {\n\t\t\tdesc = fileDescription?.description\n\t\t}\n\n\t\tif (!desc) {\n\t\t\tthrow new Error(\n\t\t\t\t`No FileDescription provided for ${destination.replace(\n\t\t\t\t\tcwd,\n\t\t\t\t\t''\n\t\t\t\t)}. Check your feature's fileDescriptions property.`\n\t\t\t)\n\t\t}\n\n\t\tmyResults.push({ name, description: desc, path: destination, action })\n\n\t\treturn myResults\n\t}\n\n\tprivate isFileDifferent(destination: string, contents: string) {\n\t\treturn diskUtil.isFileDifferent(destination, contents)\n\t}\n\n\tprivate cleanFilename(destination: string, cwd: string) {\n\t\tlet relativeFile = destination.replace(cwd, '')\n\t\tif (relativeFile[0] === pathUtil.sep) {\n\t\t\trelativeFile = relativeFile.substr(1)\n\t\t}\n\t\treturn relativeFile\n\t}\n\n\tprivate shouldOverwriteIfChanged(destination: string): boolean {\n\t\tif (!this.upgradeMode) {\n\t\t\treturn true\n\t\t}\n\n\t\tif (this.upgradeMode === 'forceEverything') {\n\t\t\treturn true\n\t\t}\n\n\t\tlet description: FileDescription | undefined =\n\t\t\tthis.getFileDescription(destination)\n\n\t\treturn description?.shouldOverwriteWhenChanged ?? false\n\t}\n\n\tprivate getFileDescription(destination: string): FileDescription | undefined {\n\t\tconst lower = destination.toLowerCase()\n\t\tfor (const d of this.fileDescriptions ?? []) {\n\t\t\tif (lower.search(d.path.toLowerCase()) > -1) {\n\t\t\t\treturn d\n\t\t\t}\n\t\t}\n\n\t\treturn undefined\n\t}\n\n\tprivate shouldAskForOverwrite() {\n\t\tif (\n\t\t\tthis.shouldConfirmBeforeWriting &&\n\t\t\tthis.upgradeMode === 'askForChanged'\n\t\t) {\n\t\t\treturn true\n\t\t}\n\n\t\treturn false\n\t}\n\n\tprotected resolveFilenameWithFallback(\n\t\tdirOrFile: string,\n\t\tfallbackFileName: string\n\t) {\n\t\tconst isDir =\n\t\t\tdiskUtil.doesDirExist(dirOrFile) &&\n\t\t\tfs.lstatSync(dirOrFile).isDirectory() &&\n\t\t\tpathUtil.extname(dirOrFile).length === 0\n\t\treturn isDir ? diskUtil.resolvePath(dirOrFile, fallbackFileName) : dirOrFile\n\t}\n}\n"],"file":"AbstractWriter.js"}
|
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
]
|
|
19
19
|
},
|
|
20
20
|
"license": "MIT",
|
|
21
|
-
"version": "14.
|
|
21
|
+
"version": "14.28.0",
|
|
22
22
|
"bin": {
|
|
23
23
|
"spruce": "./build/index.js"
|
|
24
24
|
},
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"@sprucelabs/spruce-event-utils": "^17.1.187",
|
|
89
89
|
"@sprucelabs/spruce-skill-booter": "^14.1.11",
|
|
90
90
|
"@sprucelabs/spruce-skill-utils": "^22.1.17",
|
|
91
|
-
"@sprucelabs/spruce-templates": "^14.
|
|
91
|
+
"@sprucelabs/spruce-templates": "^14.28.0",
|
|
92
92
|
"cfonts": "^2.10.0",
|
|
93
93
|
"chalk": "^4.1.2",
|
|
94
94
|
"chokidar": "^3.5.2",
|
|
@@ -595,5 +595,5 @@
|
|
|
595
595
|
"ora"
|
|
596
596
|
]
|
|
597
597
|
},
|
|
598
|
-
"gitHead": "
|
|
598
|
+
"gitHead": "ae1f52a84cbae61c1a8c7d10b3560ab17ebdc640"
|
|
599
599
|
}
|
|
@@ -2,6 +2,7 @@ import { diskUtil } from '@sprucelabs/spruce-skill-utils'
|
|
|
2
2
|
import { test, assert } from '@sprucelabs/test'
|
|
3
3
|
import CommandService from '../../services/CommandService'
|
|
4
4
|
import AbstractCliTest from '../../tests/AbstractCliTest'
|
|
5
|
+
import uiAssertUtil from '../../tests/utilities/uiAssert.utility'
|
|
5
6
|
|
|
6
7
|
export default class UpgradingANodeModuleTest extends AbstractCliTest {
|
|
7
8
|
protected static async beforeEach() {
|
|
@@ -43,4 +44,27 @@ export default class UpgradingANodeModuleTest extends AbstractCliTest {
|
|
|
43
44
|
assert.isFalse(doesExist, `Should not have found ${search}`)
|
|
44
45
|
}
|
|
45
46
|
}
|
|
47
|
+
|
|
48
|
+
@test()
|
|
49
|
+
protected static async shouldReWriteNodeDirsAndSkipIndx() {
|
|
50
|
+
for (const file of ['tsconfig.json', 'src/index.ts']) {
|
|
51
|
+
const tsConfig = this.resolvePath(file)
|
|
52
|
+
diskUtil.writeFile(tsConfig, 'beenChanged')
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
CommandService.setMockResponse(/yarn/gi, {
|
|
56
|
+
code: 0,
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
const promise = this.Action('node', 'upgrade').execute({})
|
|
60
|
+
|
|
61
|
+
await uiAssertUtil.assertRendersConfirmWriteFile(this.ui)
|
|
62
|
+
|
|
63
|
+
assert.isEqual(
|
|
64
|
+
diskUtil.readFile(this.resolvePath('src/index.ts')),
|
|
65
|
+
'beenChanged'
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
await promise
|
|
69
|
+
}
|
|
46
70
|
}
|
|
@@ -5,7 +5,11 @@ import nodeFeatureOptionsSchema from '#spruce/schemas/spruceCli/v2020_07_22/node
|
|
|
5
5
|
import { FileDescription, GeneratedFile } from '../../types/cli.types'
|
|
6
6
|
import ScriptUpdater from '../../updaters/ScriptUpdater'
|
|
7
7
|
import AbstractFeature, { FeatureDependency } from '../AbstractFeature'
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
ActionOptions,
|
|
10
|
+
FeatureActionResponse,
|
|
11
|
+
FeatureCode,
|
|
12
|
+
} from '../features.types'
|
|
9
13
|
import universalDevDependencies from '../universalDevDependencies'
|
|
10
14
|
import universalFileDescriptions from '../universalFileDescriptions'
|
|
11
15
|
import universalScripts from '../universalScripts'
|
|
@@ -49,33 +53,36 @@ export default class NodeFeature<
|
|
|
49
53
|
|
|
50
54
|
void this.emitter.on('feature.did-execute', async (payload) => {
|
|
51
55
|
if (payload.featureCode === 'node' && payload.actionCode === 'upgrade') {
|
|
52
|
-
|
|
53
|
-
this.ui.startLoading('Cleaning build...')
|
|
54
|
-
await this.Service('command').execute('yarn clean.build')
|
|
55
|
-
|
|
56
|
-
this.ui.startLoading('Applying lint rules to all files...')
|
|
57
|
-
await this.Service('command').execute('yarn fix.lint')
|
|
58
|
-
|
|
59
|
-
this.ui.startLoading('Rebuilding...')
|
|
60
|
-
await this.Service('command').execute('yarn build.dev')
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
summaryLines: [
|
|
64
|
-
'Build cleared.',
|
|
65
|
-
'Lint rules applied to source.',
|
|
66
|
-
'Code rebuilt successfully.',
|
|
67
|
-
],
|
|
68
|
-
}
|
|
69
|
-
} catch (err) {
|
|
70
|
-
return {
|
|
71
|
-
errors: [err],
|
|
72
|
-
}
|
|
73
|
-
}
|
|
56
|
+
return this.handleUpgrade()
|
|
74
57
|
}
|
|
75
58
|
|
|
76
59
|
return {}
|
|
77
60
|
})
|
|
78
61
|
}
|
|
62
|
+
private async handleUpgrade(): Promise<FeatureActionResponse> {
|
|
63
|
+
try {
|
|
64
|
+
this.ui.startLoading('Cleaning build...')
|
|
65
|
+
await this.Service('command').execute('yarn clean.build')
|
|
66
|
+
|
|
67
|
+
this.ui.startLoading('Applying lint rules to all files...')
|
|
68
|
+
await this.Service('command').execute('yarn fix.lint')
|
|
69
|
+
|
|
70
|
+
this.ui.startLoading('Rebuilding...')
|
|
71
|
+
await this.Service('command').execute('yarn build.dev')
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
summaryLines: [
|
|
75
|
+
'Build cleared.',
|
|
76
|
+
'Lint rules applied to source.',
|
|
77
|
+
'Code rebuilt successfully.',
|
|
78
|
+
],
|
|
79
|
+
}
|
|
80
|
+
} catch (err) {
|
|
81
|
+
return {
|
|
82
|
+
errors: [err],
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
79
86
|
|
|
80
87
|
public async beforePackageInstall(options: Options) {
|
|
81
88
|
const destination = this.resolveDestination(options)
|
|
@@ -94,8 +101,7 @@ export default class NodeFeature<
|
|
|
94
101
|
|
|
95
102
|
await this.Service('command', destination).execute('yarn init -y')
|
|
96
103
|
|
|
97
|
-
const
|
|
98
|
-
const written = await nodeWriter.writeNodeModule(destination)
|
|
104
|
+
const written = await this.Writer('node').writeNodeModule(destination)
|
|
99
105
|
|
|
100
106
|
files.push(...written)
|
|
101
107
|
|
|
@@ -24,6 +24,13 @@ export default class UpgradeAction extends AbstractAction<OptionsSchema> {
|
|
|
24
24
|
})
|
|
25
25
|
|
|
26
26
|
try {
|
|
27
|
+
const files = await this.Writer('node', {
|
|
28
|
+
upgradeMode: normalizedOptions.upgradeMode,
|
|
29
|
+
}).writeNodeModule(this.cwd, {
|
|
30
|
+
shouldConfirmBeforeWriting: true,
|
|
31
|
+
shouldWriteIndex: false,
|
|
32
|
+
})
|
|
33
|
+
|
|
27
34
|
InFlightEntertainment.start([
|
|
28
35
|
"Let's start the upgrade!",
|
|
29
36
|
'While things are going, see if you can beat 1k points!',
|
|
@@ -34,10 +41,10 @@ export default class UpgradeAction extends AbstractAction<OptionsSchema> {
|
|
|
34
41
|
|
|
35
42
|
return actionUtil.mergeActionResults(dependencyResults, {
|
|
36
43
|
headline: 'Upgrade',
|
|
44
|
+
files,
|
|
37
45
|
})
|
|
38
46
|
} finally {
|
|
39
47
|
InFlightEntertainment.stop()
|
|
40
|
-
|
|
41
48
|
this.ui.renderHero('Upgrade')
|
|
42
49
|
}
|
|
43
50
|
}
|
|
@@ -1,35 +1,50 @@
|
|
|
1
1
|
import { diskUtil } from '@sprucelabs/spruce-skill-utils'
|
|
2
2
|
import { DirectoryTemplateCode } from '@sprucelabs/spruce-templates'
|
|
3
|
-
import
|
|
3
|
+
import { GeneratedFile } from '../../../types/cli.types'
|
|
4
|
+
import AbstractWriter, {
|
|
5
|
+
WriteDirectoryTemplateOptions,
|
|
6
|
+
WriteResults,
|
|
7
|
+
} from '../../../writers/AbstractWriter'
|
|
4
8
|
|
|
9
|
+
export const NODE_FILES_TO_UPGRADE = [
|
|
10
|
+
'tsconfig.json',
|
|
11
|
+
'.eslintrc.js',
|
|
12
|
+
'.eslintignore',
|
|
13
|
+
'.gitignore',
|
|
14
|
+
'.nvmrc',
|
|
15
|
+
]
|
|
5
16
|
export default class NodeWriter extends AbstractWriter {
|
|
6
|
-
public async writeNodeModule(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
17
|
+
public async writeNodeModule(
|
|
18
|
+
destinationDir: string,
|
|
19
|
+
options?: Partial<WriteDirectoryTemplateOptions> & {
|
|
20
|
+
shouldWriteIndex?: boolean
|
|
21
|
+
}
|
|
22
|
+
): Promise<WriteResults> {
|
|
23
|
+
let files: GeneratedFile[] = []
|
|
24
|
+
if (options?.shouldWriteIndex !== false) {
|
|
25
|
+
const contents = '//exports go here\n'
|
|
26
|
+
const destination = diskUtil.resolvePath(
|
|
27
|
+
destinationDir,
|
|
28
|
+
'src',
|
|
29
|
+
'index.ts'
|
|
30
|
+
)
|
|
31
|
+
diskUtil.writeFile(destination, contents)
|
|
32
|
+
files.push({
|
|
33
|
+
name: 'src/index.ts',
|
|
34
|
+
description: 'Placeholder entry file!',
|
|
35
|
+
action: 'generated',
|
|
36
|
+
path: destination,
|
|
37
|
+
})
|
|
38
|
+
}
|
|
11
39
|
|
|
12
|
-
const
|
|
40
|
+
const directoryTemplateFiles = await this.writeDirectoryTemplate({
|
|
13
41
|
destinationDir,
|
|
14
42
|
code: DirectoryTemplateCode.Skill,
|
|
15
|
-
filesToWrite:
|
|
16
|
-
'tsconfig.json',
|
|
17
|
-
'.eslintrc.js',
|
|
18
|
-
'.eslintignore',
|
|
19
|
-
'.gitignore',
|
|
20
|
-
'.nvmrc',
|
|
21
|
-
],
|
|
43
|
+
filesToWrite: NODE_FILES_TO_UPGRADE,
|
|
22
44
|
context: { name: 'ignored', description: 'ignored' },
|
|
45
|
+
...options,
|
|
23
46
|
})
|
|
24
47
|
|
|
25
|
-
return [
|
|
26
|
-
{
|
|
27
|
-
name: 'src/index.ts',
|
|
28
|
-
description: 'Placeholder entry file!',
|
|
29
|
-
action: 'generated',
|
|
30
|
-
path: destination,
|
|
31
|
-
},
|
|
32
|
-
...files,
|
|
33
|
-
]
|
|
48
|
+
return [...files, ...directoryTemplateFiles]
|
|
34
49
|
}
|
|
35
50
|
}
|
|
@@ -3,6 +3,7 @@ import { SpruceSchemas } from '#spruce/schemas/schemas.types'
|
|
|
3
3
|
import SpruceError from '../../../errors/SpruceError'
|
|
4
4
|
import { GlobalEmitter } from '../../../GlobalEmitter'
|
|
5
5
|
import AbstractFeature from '../../AbstractFeature'
|
|
6
|
+
import { NODE_FILES_TO_UPGRADE } from '../../node/writers/NodeWriter'
|
|
6
7
|
|
|
7
8
|
type UpgradeOptions = SpruceSchemas.SpruceCli.v2020_07_22.UpgradeSkillOptions
|
|
8
9
|
|
|
@@ -35,7 +36,7 @@ export default class Updater {
|
|
|
35
36
|
SpruceError
|
|
36
37
|
)
|
|
37
38
|
|
|
38
|
-
const filesToSkip = ['package.json']
|
|
39
|
+
const filesToSkip = [...NODE_FILES_TO_UPGRADE, 'package.json']
|
|
39
40
|
|
|
40
41
|
for (const payload of payloads) {
|
|
41
42
|
if (payload.filesToSkip) {
|
|
@@ -24,6 +24,22 @@ const uiAssertUtil = {
|
|
|
24
24
|
label,
|
|
25
25
|
})
|
|
26
26
|
},
|
|
27
|
+
|
|
28
|
+
async assertRendersConfirmWriteFile(ui: SpyInterface) {
|
|
29
|
+
await ui.waitForInput()
|
|
30
|
+
|
|
31
|
+
const last = ui.getLastInvocation()
|
|
32
|
+
|
|
33
|
+
assert.isEqual(last.options.type, 'select')
|
|
34
|
+
assert.isEqualDeep(last.options.options.choices, [
|
|
35
|
+
{
|
|
36
|
+
label: 'Overwrite',
|
|
37
|
+
value: 'overwrite',
|
|
38
|
+
},
|
|
39
|
+
{ value: 'skip', label: 'Skip' },
|
|
40
|
+
{ value: 'alwaysSkip', label: 'Always skip' },
|
|
41
|
+
])
|
|
42
|
+
},
|
|
27
43
|
}
|
|
28
44
|
|
|
29
45
|
export default uiAssertUtil
|
|
@@ -16,13 +16,22 @@ export type WriteResults = GeneratedFile[]
|
|
|
16
16
|
export interface WriterOptions {
|
|
17
17
|
templates: Templates
|
|
18
18
|
term: GraphicsInterface
|
|
19
|
-
askBeforeUpdating?: boolean
|
|
20
19
|
upgradeMode?: UpgradeMode
|
|
21
20
|
fileDescriptions: FileDescription[]
|
|
22
21
|
linter?: LintService
|
|
23
22
|
settings: SettingsService
|
|
24
23
|
}
|
|
25
24
|
|
|
25
|
+
export interface WriteDirectoryTemplateOptions {
|
|
26
|
+
destinationDir: string
|
|
27
|
+
code: DirectoryTemplateCode
|
|
28
|
+
filesToWrite?: string[]
|
|
29
|
+
filesToSkip?: string[]
|
|
30
|
+
context: any
|
|
31
|
+
shouldConfirmBeforeWriting?: boolean
|
|
32
|
+
firstFileWriteMessage?: string
|
|
33
|
+
}
|
|
34
|
+
|
|
26
35
|
export default abstract class AbstractWriter {
|
|
27
36
|
protected templates: Templates
|
|
28
37
|
protected ui: GraphicsInterface
|
|
@@ -59,15 +68,9 @@ export default abstract class AbstractWriter {
|
|
|
59
68
|
this.isLintingEnabled = true
|
|
60
69
|
}
|
|
61
70
|
|
|
62
|
-
protected async writeDirectoryTemplate(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
filesToWrite?: string[]
|
|
66
|
-
filesToSkip?: string[]
|
|
67
|
-
context: any
|
|
68
|
-
shouldConfirmBeforeWriting?: boolean
|
|
69
|
-
firstFileWriteMessage?: string
|
|
70
|
-
}) {
|
|
71
|
+
protected async writeDirectoryTemplate(
|
|
72
|
+
options: WriteDirectoryTemplateOptions
|
|
73
|
+
) {
|
|
71
74
|
const {
|
|
72
75
|
context,
|
|
73
76
|
destinationDir,
|
|
@@ -93,6 +96,7 @@ export default abstract class AbstractWriter {
|
|
|
93
96
|
!filesToWrite || filesToWrite.indexOf(generated.filename) > -1
|
|
94
97
|
const shouldSkip =
|
|
95
98
|
filesToSkip && filesToSkip.indexOf(generated.filename) > -1
|
|
99
|
+
|
|
96
100
|
if (shouldWrite && !shouldSkip) {
|
|
97
101
|
results = await this.writeFileIfChangedMixinResults(
|
|
98
102
|
pathUtil.join(destinationDir, generated.relativePath),
|
|
@@ -128,6 +132,7 @@ export default abstract class AbstractWriter {
|
|
|
128
132
|
|
|
129
133
|
if (!diskUtil.doesFileExist(destination)) {
|
|
130
134
|
let write = true
|
|
135
|
+
|
|
131
136
|
if (
|
|
132
137
|
this.shouldConfirmBeforeWriting &&
|
|
133
138
|
fileDescription?.confirmPromptOnFirstWrite
|