particle-commands 0.5.3 → 1.0.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 +3 -0
- package/dist/cmd/command.js +7 -17
- package/dist/cmd/library_add.js +18 -32
- package/dist/cmd/library_init.js +15 -38
- package/dist/cmd/library_migrate.js +35 -40
- package/package.json +3 -6
- package/src/cmd/command.js +7 -7
- package/src/cmd/library_add.js +12 -14
- package/src/cmd/library_init.js +11 -30
- package/src/cmd/library_migrate.js +27 -36
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
|
4
4
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
5
5
|
|
|
6
|
+
### 1.0.0 - 2024-03-13
|
|
7
|
+
- Remove yeoman and use own template engine with particle-library-manager new version
|
|
8
|
+
|
|
6
9
|
### 0.5.3 - 2023-10-18
|
|
7
10
|
- Fix template
|
|
8
11
|
|
package/dist/cmd/command.js
CHANGED
|
@@ -3,16 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.CommandSite = exports.AbstractStatefulCommand = exports.Command = undefined;
|
|
7
6
|
|
|
8
7
|
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
9
8
|
|
|
10
|
-
var _when = require('when');
|
|
11
|
-
|
|
12
|
-
var _when2 = _interopRequireDefault(_when);
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
9
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
17
10
|
|
|
18
11
|
/**
|
|
@@ -45,18 +38,15 @@ var CommandSite = function () {
|
|
|
45
38
|
value: function end(state, cmd) {}
|
|
46
39
|
}, {
|
|
47
40
|
key: 'run',
|
|
48
|
-
value: function run(cmd) {
|
|
49
|
-
var _this = this;
|
|
50
|
-
|
|
41
|
+
value: async function run(cmd) {
|
|
51
42
|
var state = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
52
43
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
});
|
|
44
|
+
try {
|
|
45
|
+
await this.begin(state, this);
|
|
46
|
+
await cmd.run(state, this);
|
|
47
|
+
} finally {
|
|
48
|
+
await this.end(state, this);
|
|
49
|
+
}
|
|
60
50
|
}
|
|
61
51
|
}]);
|
|
62
52
|
|
package/dist/cmd/library_add.js
CHANGED
|
@@ -7,18 +7,12 @@ exports.LibraryAddCommand = exports.LibraryAddCommandSite = undefined;
|
|
|
7
7
|
|
|
8
8
|
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
9
9
|
|
|
10
|
-
var _pipeline = require('when/pipeline');
|
|
11
|
-
|
|
12
|
-
var _pipeline2 = _interopRequireDefault(_pipeline);
|
|
13
|
-
|
|
14
10
|
var _api = require('./api');
|
|
15
11
|
|
|
16
12
|
var _command = require('./command');
|
|
17
13
|
|
|
18
14
|
var _library = require('./library');
|
|
19
15
|
|
|
20
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
|
|
22
16
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
23
17
|
|
|
24
18
|
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
@@ -80,8 +74,6 @@ var LibraryAddCommand = exports.LibraryAddCommand = function () {
|
|
|
80
74
|
* @returns {Promise} Library add process
|
|
81
75
|
*/
|
|
82
76
|
value: function run(state, site) {
|
|
83
|
-
var _this2 = this;
|
|
84
|
-
|
|
85
77
|
this.site = site;
|
|
86
78
|
|
|
87
79
|
var lib = site.libraryIdent();
|
|
@@ -89,25 +81,24 @@ var LibraryAddCommand = exports.LibraryAddCommand = function () {
|
|
|
89
81
|
lib.version = 'latest';
|
|
90
82
|
}
|
|
91
83
|
var directory = this.site.projectDir();
|
|
92
|
-
return (
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}]);
|
|
84
|
+
return this._loadLibrary(directory, lib);
|
|
85
|
+
}
|
|
86
|
+
}, {
|
|
87
|
+
key: '_loadLibrary',
|
|
88
|
+
value: async function _loadLibrary(directory, lib) {
|
|
89
|
+
await this.ensureProjectExists(directory);
|
|
90
|
+
await this.loadProject();
|
|
91
|
+
var library = await this.fetchLibrary(lib.name, lib.version);
|
|
92
|
+
await this.addLibraryToProject(library);
|
|
93
|
+
await this.saveProject();
|
|
103
94
|
}
|
|
104
95
|
}, {
|
|
105
96
|
key: 'ensureProjectExists',
|
|
106
97
|
value: function ensureProjectExists(directory) {
|
|
107
|
-
var
|
|
98
|
+
var _this2 = this;
|
|
108
99
|
|
|
109
100
|
return (0, _library.findProject)(directory, true).then(function (project) {
|
|
110
|
-
|
|
101
|
+
_this2.properties = project;
|
|
111
102
|
return project;
|
|
112
103
|
});
|
|
113
104
|
}
|
|
@@ -125,12 +116,12 @@ var LibraryAddCommand = exports.LibraryAddCommand = function () {
|
|
|
125
116
|
}, {
|
|
126
117
|
key: 'fetchLibrary',
|
|
127
118
|
value: function fetchLibrary(name, version) {
|
|
128
|
-
var
|
|
119
|
+
var _this3 = this;
|
|
129
120
|
|
|
130
121
|
return Promise.resolve(this.site.apiClient()).then(function (apiClient) {
|
|
131
|
-
return Promise.resolve(
|
|
122
|
+
return Promise.resolve(_this3.site.fetchingLibrary(apiClient.library(name, { version: version }), name, version));
|
|
132
123
|
}).catch(function (err) {
|
|
133
|
-
throw
|
|
124
|
+
throw _this3.apiError(err);
|
|
134
125
|
});
|
|
135
126
|
}
|
|
136
127
|
}, {
|
|
@@ -140,14 +131,9 @@ var LibraryAddCommand = exports.LibraryAddCommand = function () {
|
|
|
140
131
|
}
|
|
141
132
|
}, {
|
|
142
133
|
key: 'addLibraryToProject',
|
|
143
|
-
value: function addLibraryToProject(library) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return (0, _pipeline2.default)([function () {
|
|
147
|
-
return _this5.site.addedLibrary(library.name, library.version);
|
|
148
|
-
}, function () {
|
|
149
|
-
return _this5.properties.addDependency(library.name, library.version);
|
|
150
|
-
}]);
|
|
134
|
+
value: async function addLibraryToProject(library) {
|
|
135
|
+
await this.site.addedLibrary(library.name, library.version);
|
|
136
|
+
await this.properties.addDependency(library.name, library.version);
|
|
151
137
|
}
|
|
152
138
|
}, {
|
|
153
139
|
key: 'saveProject',
|
package/dist/cmd/library_init.js
CHANGED
|
@@ -17,13 +17,10 @@ function _possibleConstructorReturn(self, call) { if (!self) { throw new Referen
|
|
|
17
17
|
|
|
18
18
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
19
19
|
|
|
20
|
-
var promisify = require('es6-promisify');
|
|
21
|
-
|
|
22
20
|
/**
|
|
23
21
|
* Specification and base implementation for the site instance expected by
|
|
24
22
|
* the LibraryInitCommand.
|
|
25
23
|
*/
|
|
26
|
-
|
|
27
24
|
var LibraryInitCommandSite = exports.LibraryInitCommandSite = function (_CommandSite) {
|
|
28
25
|
_inherits(LibraryInitCommandSite, _CommandSite);
|
|
29
26
|
|
|
@@ -34,16 +31,6 @@ var LibraryInitCommandSite = exports.LibraryInitCommandSite = function (_Command
|
|
|
34
31
|
}
|
|
35
32
|
|
|
36
33
|
_createClass(LibraryInitCommandSite, [{
|
|
37
|
-
key: 'yeomanAdapter',
|
|
38
|
-
value: function yeomanAdapter() {
|
|
39
|
-
throw new Error('not implemented');
|
|
40
|
-
}
|
|
41
|
-
}, {
|
|
42
|
-
key: 'yeomanEnvironment',
|
|
43
|
-
value: function yeomanEnvironment() {
|
|
44
|
-
throw new Error('not implemented');
|
|
45
|
-
}
|
|
46
|
-
}, {
|
|
47
34
|
key: 'options',
|
|
48
35
|
value: function options() {
|
|
49
36
|
return {};
|
|
@@ -53,6 +40,16 @@ var LibraryInitCommandSite = exports.LibraryInitCommandSite = function (_Command
|
|
|
53
40
|
value: function args() {
|
|
54
41
|
return [];
|
|
55
42
|
}
|
|
43
|
+
}, {
|
|
44
|
+
key: 'prompter',
|
|
45
|
+
value: function prompter() {
|
|
46
|
+
throw new Error('not implemented');
|
|
47
|
+
}
|
|
48
|
+
}, {
|
|
49
|
+
key: 'outputStreamer',
|
|
50
|
+
value: function outputStreamer() {
|
|
51
|
+
throw new Error('not implemented');
|
|
52
|
+
}
|
|
56
53
|
}]);
|
|
57
54
|
|
|
58
55
|
return LibraryInitCommandSite;
|
|
@@ -73,10 +70,8 @@ var LibraryInitCommand = exports.LibraryInitCommand = function (_Command) {
|
|
|
73
70
|
}
|
|
74
71
|
|
|
75
72
|
_createClass(LibraryInitCommand, [{
|
|
76
|
-
key: '
|
|
77
|
-
|
|
78
|
-
return (0, _particleLibraryManager.buildLibraryInitGeneratorClass)();
|
|
79
|
-
}
|
|
73
|
+
key: 'run',
|
|
74
|
+
|
|
80
75
|
|
|
81
76
|
/**
|
|
82
77
|
*
|
|
@@ -84,29 +79,11 @@ var LibraryInitCommand = exports.LibraryInitCommand = function (_Command) {
|
|
|
84
79
|
* @param {LibraryInitCommandSite} site external services.
|
|
85
80
|
* @returns {Promise} To run the library initialization command.
|
|
86
81
|
*/
|
|
87
|
-
|
|
88
|
-
}, {
|
|
89
|
-
key: 'run',
|
|
90
82
|
value: function run(state, site) {
|
|
91
|
-
var yeoman = site.yeomanEnvironment();
|
|
92
|
-
var args = site.args();
|
|
93
83
|
var opts = site.options();
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return env.run.apply(env, arguments);
|
|
98
|
-
});
|
|
99
|
-
return run(['library:init'], opts);
|
|
100
|
-
|
|
101
|
-
// we ideally want the instance so that we can hook the 'end' event
|
|
102
|
-
// yeoman-evironment doesn't provide the instance with the registration method above
|
|
103
|
-
// so we dive below the covers and do it ourselves...
|
|
104
|
-
// const generator = env.instantiate(LibraryInitGenerator, opts);
|
|
105
|
-
// return new Promise((fulfill, reject) => {
|
|
106
|
-
// generator.on('end', fulfill);
|
|
107
|
-
// generator.on('error', reject);
|
|
108
|
-
// generator.run();
|
|
109
|
-
// });
|
|
84
|
+
|
|
85
|
+
var generator = new _particleLibraryManager.LibraryInitGenerator({ prompt: site.prompter(), stdout: site.outputStreamer() });
|
|
86
|
+
return generator.run({ options: opts });
|
|
110
87
|
}
|
|
111
88
|
}]);
|
|
112
89
|
|
|
@@ -17,14 +17,6 @@ var _path = require('path');
|
|
|
17
17
|
|
|
18
18
|
var _path2 = _interopRequireDefault(_path);
|
|
19
19
|
|
|
20
|
-
var _when = require('when');
|
|
21
|
-
|
|
22
|
-
var _when2 = _interopRequireDefault(_when);
|
|
23
|
-
|
|
24
|
-
var _pipeline = require('when/pipeline');
|
|
25
|
-
|
|
26
|
-
var _pipeline2 = _interopRequireDefault(_pipeline);
|
|
27
|
-
|
|
28
20
|
var _library_install = require('./library_install');
|
|
29
21
|
|
|
30
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -105,25 +97,29 @@ var AbstractLibraryMigrateCommand = function (_Command) {
|
|
|
105
97
|
* - result: result of running `processLibrary()` if no errors were produced.
|
|
106
98
|
* - err: any error that was produced.
|
|
107
99
|
*/
|
|
108
|
-
value: function run(state, site) {
|
|
100
|
+
value: async function run(state, site) {
|
|
109
101
|
var _this3 = this;
|
|
110
102
|
|
|
111
|
-
var
|
|
112
|
-
|
|
113
|
-
return
|
|
114
|
-
var dir = _path2.default.resolve(libdir);
|
|
115
|
-
var repo = new _particleLibraryManager.FileSystemLibraryRepository(dir, _particleLibraryManager.FileSystemNamingStrategy.DIRECT);
|
|
116
|
-
return _this3.processLibrary(repo, '', state, site, libdir).then(function (_ref) {
|
|
117
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
118
|
-
res = _ref2[0],
|
|
119
|
-
err = _ref2[1];
|
|
120
|
-
|
|
121
|
-
return Promise.resolve(site.notifyEnd(libdir, res, err)).then(function () {
|
|
122
|
-
return { libdir: libdir, res: res, err: err };
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
});
|
|
103
|
+
var libraries = await site.getLibraries();
|
|
104
|
+
var promises = libraries.map(function (libdir) {
|
|
105
|
+
return _this3._executeLibrary(libdir, state, site);
|
|
126
106
|
});
|
|
107
|
+
return Promise.all(promises);
|
|
108
|
+
}
|
|
109
|
+
}, {
|
|
110
|
+
key: '_executeLibrary',
|
|
111
|
+
value: async function _executeLibrary(libdir, state, site) {
|
|
112
|
+
await site.notifyStart(libdir);
|
|
113
|
+
var dir = _path2.default.resolve(libdir);
|
|
114
|
+
var repo = new _particleLibraryManager.FileSystemLibraryRepository(dir, _particleLibraryManager.FileSystemNamingStrategy.DIRECT);
|
|
115
|
+
|
|
116
|
+
var _ref = await this.processLibrary(repo, '', state, site, libdir),
|
|
117
|
+
_ref2 = _slicedToArray(_ref, 2),
|
|
118
|
+
res = _ref2[0],
|
|
119
|
+
err = _ref2[1];
|
|
120
|
+
|
|
121
|
+
await site.notifyEnd(libdir, res, err);
|
|
122
|
+
return { libdir: libdir, res: res, err: err };
|
|
127
123
|
}
|
|
128
124
|
|
|
129
125
|
/**
|
|
@@ -180,22 +176,21 @@ var LibraryMigrateCommand = exports.LibraryMigrateCommand = function (_AbstractL
|
|
|
180
176
|
|
|
181
177
|
_createClass(LibraryMigrateCommand, [{
|
|
182
178
|
key: 'processLibrary',
|
|
183
|
-
value: function processLibrary(repo, libname, state, site, libdir) {
|
|
184
|
-
return resultError((
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}]));
|
|
179
|
+
value: async function processLibrary(repo, libname, state, site, libdir) {
|
|
180
|
+
return resultError(this._processLibrary(repo, libname, state, site, libdir));
|
|
181
|
+
}
|
|
182
|
+
}, {
|
|
183
|
+
key: '_processLibrary',
|
|
184
|
+
value: async function _processLibrary(repo, libname, state, site, libdir) {
|
|
185
|
+
var layout = await repo.getLibraryLayout(libname);
|
|
186
|
+
if (layout === 2) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
await repo.setLibraryLayout(libname, 2);
|
|
190
|
+
if (site.isAdaptersRequired()) {
|
|
191
|
+
await (0, _library_install.buildAdapters)(libdir, libname);
|
|
192
|
+
}
|
|
193
|
+
return true;
|
|
199
194
|
}
|
|
200
195
|
}]);
|
|
201
196
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "particle-commands",
|
|
3
3
|
"description": "Library of UX-neutral commands that provide key functionality for developer tools",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "1.0.0",
|
|
5
5
|
"author": "Matthew McGowan",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/particle-iot/particle-commands/issues"
|
|
@@ -17,13 +17,10 @@
|
|
|
17
17
|
"es6-promisify": "^4.1.0",
|
|
18
18
|
"mkdirp": "^0.5.1",
|
|
19
19
|
"particle-api-js": "^6.5.0",
|
|
20
|
-
"particle-library-manager": "^0.
|
|
20
|
+
"particle-library-manager": "^1.0.0",
|
|
21
21
|
"semver": "^5.1.0",
|
|
22
22
|
"underscore": "^1.8.3",
|
|
23
|
-
"
|
|
24
|
-
"winreg": "^1.2.2",
|
|
25
|
-
"yeoman-environment": "^1.6.6",
|
|
26
|
-
"yeoman-generator": "^1.1.1"
|
|
23
|
+
"winreg": "^1.2.2"
|
|
27
24
|
},
|
|
28
25
|
"devDependencies": {
|
|
29
26
|
"babel-cli": "^6.10.1",
|
package/src/cmd/command.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import when from 'when';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Describes the interface expected of objects passed as the command site to a command.
|
|
5
3
|
*/
|
|
@@ -22,11 +20,13 @@ class CommandSite {
|
|
|
22
20
|
end(state, cmd) {}
|
|
23
21
|
|
|
24
22
|
|
|
25
|
-
run(cmd, state = {}) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
async run(cmd, state = {}) {
|
|
24
|
+
try {
|
|
25
|
+
await this.begin(state, this);
|
|
26
|
+
await cmd.run(state, this);
|
|
27
|
+
} finally {
|
|
28
|
+
await this.end(state, this);
|
|
29
|
+
}
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
package/src/cmd/library_add.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
import pipeline from 'when/pipeline';
|
|
3
1
|
import { convertApiError } from './api';
|
|
4
2
|
import { CommandSite } from './command';
|
|
5
3
|
import { findProject } from './library';
|
|
@@ -45,13 +43,15 @@ export class LibraryAddCommand {
|
|
|
45
43
|
lib.version = 'latest';
|
|
46
44
|
}
|
|
47
45
|
const directory = this.site.projectDir();
|
|
48
|
-
return
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
return this._loadLibrary(directory, lib);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async _loadLibrary(directory, lib) {
|
|
50
|
+
await this.ensureProjectExists(directory);
|
|
51
|
+
await this.loadProject();
|
|
52
|
+
const library = await this.fetchLibrary(lib.name, lib.version);
|
|
53
|
+
await this.addLibraryToProject(library);
|
|
54
|
+
await this.saveProject();
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
ensureProjectExists(directory) {
|
|
@@ -86,11 +86,9 @@ export class LibraryAddCommand {
|
|
|
86
86
|
return convertApiError(err);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
addLibraryToProject(library) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
() => this.properties.addDependency(library.name, library.version)
|
|
93
|
-
]);
|
|
89
|
+
async addLibraryToProject(library) {
|
|
90
|
+
await this.site.addedLibrary(library.name, library.version);
|
|
91
|
+
await this.properties.addDependency(library.name, library.version);
|
|
94
92
|
}
|
|
95
93
|
|
|
96
94
|
saveProject() {
|
package/src/cmd/library_init.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Command, CommandSite } from './command';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
const promisify = require('es6-promisify');
|
|
2
|
+
import { LibraryInitGenerator } from 'particle-library-manager';
|
|
5
3
|
|
|
6
4
|
/**
|
|
7
5
|
* Specification and base implementation for the site instance expected by
|
|
@@ -13,14 +11,6 @@ export class LibraryInitCommandSite extends CommandSite {
|
|
|
13
11
|
super();
|
|
14
12
|
}
|
|
15
13
|
|
|
16
|
-
yeomanAdapter() {
|
|
17
|
-
throw new Error('not implemented');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
yeomanEnvironment() {
|
|
21
|
-
throw new Error('not implemented');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
14
|
options() {
|
|
25
15
|
return {};
|
|
26
16
|
}
|
|
@@ -29,6 +19,14 @@ export class LibraryInitCommandSite extends CommandSite {
|
|
|
29
19
|
return [];
|
|
30
20
|
}
|
|
31
21
|
|
|
22
|
+
prompter() {
|
|
23
|
+
throw new Error('not implemented');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
outputStreamer() {
|
|
27
|
+
throw new Error('not implemented');
|
|
28
|
+
}
|
|
29
|
+
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
/**
|
|
@@ -36,10 +34,6 @@ export class LibraryInitCommandSite extends CommandSite {
|
|
|
36
34
|
*/
|
|
37
35
|
export class LibraryInitCommand extends Command {
|
|
38
36
|
|
|
39
|
-
generatorClass() {
|
|
40
|
-
return buildLibraryInitGeneratorClass();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
37
|
/**
|
|
44
38
|
*
|
|
45
39
|
* @param {object} state The current conversation state.
|
|
@@ -47,23 +41,10 @@ export class LibraryInitCommand extends Command {
|
|
|
47
41
|
* @returns {Promise} To run the library initialization command.
|
|
48
42
|
*/
|
|
49
43
|
run(state, site) {
|
|
50
|
-
const yeoman = site.yeomanEnvironment();
|
|
51
|
-
const args = site.args();
|
|
52
44
|
const opts = site.options();
|
|
53
|
-
const env = yeoman.createEnv(args, opts, site.yeomanAdapter());
|
|
54
|
-
env.registerStub(this.generatorClass(), 'library:init');
|
|
55
|
-
const run = promisify((...args) => env.run(...args));
|
|
56
|
-
return run(['library:init'], opts);
|
|
57
45
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
// so we dive below the covers and do it ourselves...
|
|
61
|
-
// const generator = env.instantiate(LibraryInitGenerator, opts);
|
|
62
|
-
// return new Promise((fulfill, reject) => {
|
|
63
|
-
// generator.on('end', fulfill);
|
|
64
|
-
// generator.on('error', reject);
|
|
65
|
-
// generator.run();
|
|
66
|
-
// });
|
|
46
|
+
const generator = new LibraryInitGenerator({ prompt: site.prompter(), stdout: site.outputStreamer() });
|
|
47
|
+
return generator.run({ options: opts });
|
|
67
48
|
}
|
|
68
49
|
}
|
|
69
50
|
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { Command, CommandSite } from './command';
|
|
2
|
-
|
|
3
2
|
import { FileSystemLibraryRepository, FileSystemNamingStrategy } from 'particle-library-manager';
|
|
4
3
|
import path from 'path';
|
|
5
|
-
import when from 'when';
|
|
6
|
-
import pipeline from 'when/pipeline';
|
|
7
4
|
import { buildAdapters } from './library_install';
|
|
8
5
|
|
|
9
6
|
export class LibraryMigrateCommandSite extends CommandSite {
|
|
@@ -46,22 +43,19 @@ class AbstractLibraryMigrateCommand extends Command {
|
|
|
46
43
|
* - result: result of running `processLibrary()` if no errors were produced.
|
|
47
44
|
* - err: any error that was produced.
|
|
48
45
|
*/
|
|
49
|
-
run(state, site) {
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
});
|
|
46
|
+
async run(state, site) {
|
|
47
|
+
const libraries = await site.getLibraries();
|
|
48
|
+
const promises = libraries.map(libdir => this._executeLibrary(libdir, state, site));
|
|
49
|
+
return Promise.all(promises);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async _executeLibrary(libdir, state, site){
|
|
53
|
+
await site.notifyStart(libdir);
|
|
54
|
+
const dir = path.resolve(libdir);
|
|
55
|
+
const repo = new FileSystemLibraryRepository(dir, FileSystemNamingStrategy.DIRECT);
|
|
56
|
+
const [res, err] = await this.processLibrary(repo, '', state, site, libdir);
|
|
57
|
+
await site.notifyEnd(libdir, res, err);
|
|
58
|
+
return { libdir, res, err };
|
|
65
59
|
}
|
|
66
60
|
|
|
67
61
|
/**
|
|
@@ -89,22 +83,19 @@ export class LibraryMigrateTestCommand extends AbstractLibraryMigrateCommand {
|
|
|
89
83
|
|
|
90
84
|
export class LibraryMigrateCommand extends AbstractLibraryMigrateCommand {
|
|
91
85
|
|
|
92
|
-
processLibrary(repo, libname, state, site, libdir) {
|
|
93
|
-
return resultError(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
]));
|
|
86
|
+
async processLibrary(repo, libname, state, site, libdir) {
|
|
87
|
+
return resultError(this._processLibrary(repo, libname, state, site, libdir));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async _processLibrary(repo, libname, state, site, libdir) {
|
|
91
|
+
const layout = await repo.getLibraryLayout(libname);
|
|
92
|
+
if (layout === 2) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
await repo.setLibraryLayout(libname, 2);
|
|
96
|
+
if (site.isAdaptersRequired()) {
|
|
97
|
+
await buildAdapters(libdir, libname);
|
|
98
|
+
}
|
|
99
|
+
return true;
|
|
109
100
|
}
|
|
110
101
|
}
|