adapt-cli 3.0.0 → 3.0.7
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/.bowerrc +2 -2
- package/.eslintignore +1 -1
- package/.eslintrc.json +14 -14
- package/.github/CONTRIBUTING.md +8 -0
- package/.github/ISSUE_TEMPLATE.md +17 -0
- package/.github/pull_request_template.md +25 -0
- package/.github/workflows/addtomainproject.yml +19 -0
- package/.github/workflows/releases.yml +25 -0
- package/.travis.yml +46 -46
- package/README.md +266 -266
- package/bin/adapt.js +3 -3
- package/json/help-create/component.json +9 -9
- package/json/help-create/course.json +9 -9
- package/json/help-create/question.json +9 -9
- package/json/help-create.json +12 -12
- package/json/help-devinstall.json +9 -9
- package/json/help-install.json +10 -10
- package/json/help-ls.json +7 -7
- package/json/help-register.json +7 -7
- package/json/help-rename.json +7 -7
- package/json/help-search.json +8 -8
- package/json/help-uninstall.json +7 -7
- package/json/help-unregister.json +8 -8
- package/json/help-update.json +12 -12
- package/json/help-version.json +7 -7
- package/json/help.json +19 -19
- package/lib/api.js +273 -260
- package/lib/cli.js +70 -69
- package/lib/commands/authenticate.js +18 -18
- package/lib/commands/create/component.js +64 -64
- package/lib/commands/create/course.js +26 -26
- package/lib/commands/create/question.js +18 -18
- package/lib/commands/create.js +94 -85
- package/lib/commands/devinstall.js +35 -35
- package/lib/commands/help.js +31 -31
- package/lib/commands/install.js +16 -16
- package/lib/commands/ls.js +35 -9
- package/lib/commands/register.js +11 -11
- package/lib/commands/rename.js +14 -14
- package/lib/commands/search.js +11 -11
- package/lib/commands/uninstall.js +9 -9
- package/lib/commands/unregister.js +12 -12
- package/lib/commands/update.js +12 -12
- package/lib/commands/version.js +13 -13
- package/lib/econnreset.js +8 -0
- package/lib/integration/AdaptFramework/build.js +42 -39
- package/lib/integration/AdaptFramework/clone.js +27 -27
- package/lib/integration/AdaptFramework/deleteSrcCore.js +9 -9
- package/lib/integration/AdaptFramework/deleteSrcCourse.js +9 -9
- package/lib/integration/AdaptFramework/download.js +21 -21
- package/lib/integration/AdaptFramework/erase.js +34 -34
- package/lib/integration/AdaptFramework/getLatestVersion.js +74 -79
- package/lib/integration/AdaptFramework/npmInstall.js +21 -21
- package/lib/integration/AdaptFramework.js +19 -19
- package/lib/integration/Plugin.js +404 -403
- package/lib/integration/PluginManagement/autenticate.js +47 -56
- package/lib/integration/PluginManagement/install.js +224 -222
- package/lib/integration/PluginManagement/print.js +52 -52
- package/lib/integration/PluginManagement/register.js +130 -130
- package/lib/integration/PluginManagement/rename.js +95 -101
- package/lib/integration/PluginManagement/schemas.js +8 -8
- package/lib/integration/PluginManagement/search.js +37 -46
- package/lib/integration/PluginManagement/uninstall.js +141 -141
- package/lib/integration/PluginManagement/unregister.js +91 -101
- package/lib/integration/PluginManagement/update.js +224 -224
- package/lib/integration/PluginManagement.js +21 -21
- package/lib/integration/Project.js +146 -146
- package/lib/integration/Target.js +299 -296
- package/lib/integration/getBowerRegistryConfig.js +34 -34
- package/lib/logger.js +28 -28
- package/lib/util/JSONReadValidate.js +34 -34
- package/lib/util/constants.js +38 -38
- package/lib/util/createPromptTask.js +7 -7
- package/lib/util/download.js +45 -45
- package/lib/util/errors.js +58 -58
- package/lib/util/extract.js +24 -24
- package/lib/util/getDirNameFromImportMeta.js +6 -6
- package/lib/util/promises.js +36 -36
- package/package.json +74 -40
package/lib/api.js
CHANGED
@@ -1,260 +1,273 @@
|
|
1
|
-
import http from 'http' // api http import, to hold open process for testing
|
2
|
-
import { ADAPT_FRAMEWORK } from './util/constants.js'
|
3
|
-
import {
|
4
|
-
build,
|
5
|
-
download,
|
6
|
-
erase,
|
7
|
-
getLatestVersion,
|
8
|
-
npmInstall,
|
9
|
-
deleteSrcCourse,
|
10
|
-
deleteSrcCore
|
11
|
-
} from './integration/AdaptFramework.js'
|
12
|
-
import {
|
13
|
-
install,
|
14
|
-
uninstall,
|
15
|
-
update,
|
16
|
-
schemas
|
17
|
-
} from './integration/PluginManagement.js'
|
18
|
-
import Plugin from './integration/Plugin.js'
|
19
|
-
import Project from './integration/Project.js'
|
20
|
-
import fs from 'fs-extra'
|
21
|
-
import async from 'async'
|
22
|
-
|
23
|
-
|
24
|
-
// TODO: api,
|
25
|
-
// TODO: api,
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
*
|
31
|
-
* @param {
|
32
|
-
* @param {string} [options.
|
33
|
-
* @param {string} [options.
|
34
|
-
* @
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
cwd
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
*
|
80
|
-
* @param {
|
81
|
-
* @param {
|
82
|
-
* @
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
*
|
174
|
-
*
|
175
|
-
*
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
*
|
189
|
-
* @
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
if (!
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
})
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
}
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
1
|
+
import http from 'http' // api http import, to hold open process for testing
|
2
|
+
import { ADAPT_FRAMEWORK } from './util/constants.js'
|
3
|
+
import {
|
4
|
+
build,
|
5
|
+
download,
|
6
|
+
erase,
|
7
|
+
getLatestVersion,
|
8
|
+
npmInstall,
|
9
|
+
deleteSrcCourse,
|
10
|
+
deleteSrcCore
|
11
|
+
} from './integration/AdaptFramework.js'
|
12
|
+
import {
|
13
|
+
install,
|
14
|
+
uninstall,
|
15
|
+
update,
|
16
|
+
schemas
|
17
|
+
} from './integration/PluginManagement.js'
|
18
|
+
import Plugin from './integration/Plugin.js'
|
19
|
+
import Project from './integration/Project.js'
|
20
|
+
import fs from 'fs-extra'
|
21
|
+
import async from 'async'
|
22
|
+
import './econnreset.js'
|
23
|
+
|
24
|
+
// TODO: api, check no interactivity, should be sorted, will fail silently if it absolutely cannot do what you've asked
|
25
|
+
// TODO: api, console and error output, error on fail when isInteractive: false? or something else? return Targets?
|
26
|
+
// TODO: api, figure out error translations, should probably error with codes?
|
27
|
+
|
28
|
+
class API {
|
29
|
+
/**
|
30
|
+
* Installs a clean copy of the framework
|
31
|
+
* @param {Object} options
|
32
|
+
* @param {string} [options.version=null] Specific version of the framework to install
|
33
|
+
* @param {string} [options.repository] URL to github repo
|
34
|
+
* @param {string} [options.cwd=process.cwd()] Directory to install into
|
35
|
+
* @return {Promise}
|
36
|
+
*/
|
37
|
+
async installFramework ({
|
38
|
+
version = null,
|
39
|
+
repository = ADAPT_FRAMEWORK,
|
40
|
+
cwd = process.cwd(),
|
41
|
+
logger
|
42
|
+
} = {}) {
|
43
|
+
if (!version) version = await getLatestVersion({ repository })
|
44
|
+
await erase({
|
45
|
+
isInteractive: false,
|
46
|
+
cwd,
|
47
|
+
logger
|
48
|
+
})
|
49
|
+
await download({
|
50
|
+
repository,
|
51
|
+
branch: version,
|
52
|
+
cwd,
|
53
|
+
logger
|
54
|
+
})
|
55
|
+
await deleteSrcCourse({
|
56
|
+
cwd
|
57
|
+
})
|
58
|
+
await deleteSrcCore({
|
59
|
+
cwd
|
60
|
+
})
|
61
|
+
await npmInstall({
|
62
|
+
cwd,
|
63
|
+
logger
|
64
|
+
})
|
65
|
+
}
|
66
|
+
|
67
|
+
/**
|
68
|
+
* @param {Object} options
|
69
|
+
* @param {Object} [options.repository=ADAPT_FRAMEWORK] The github repository url
|
70
|
+
* @returns {string}
|
71
|
+
*/
|
72
|
+
async getLatestFrameworkVersion ({
|
73
|
+
repository = ADAPT_FRAMEWORK
|
74
|
+
} = {}) {
|
75
|
+
return getLatestVersion({ repository })
|
76
|
+
}
|
77
|
+
|
78
|
+
/**
|
79
|
+
* Runs build for a current course
|
80
|
+
* @param {Object} options
|
81
|
+
* @param {boolean} [options.sourceMaps=false] Whether to run the build with sourcemaps
|
82
|
+
* @param {boolean} [options.checkJSON=false] Whether to run without checking the json
|
83
|
+
* @param {boolean} [options.cache=true] Whether to clear build caches
|
84
|
+
* @param {string} [options.outputDir="build/"] Root path of the framework installation
|
85
|
+
* @param {string} [options.cachePath="build/.cache"] Path of compilation cache file
|
86
|
+
* @param {string} [options.cwd=process.cwd()] Root path of the framework installation
|
87
|
+
* @return {Promise}
|
88
|
+
*/
|
89
|
+
async buildCourse ({
|
90
|
+
sourceMaps = false,
|
91
|
+
checkJSON = false,
|
92
|
+
cache = true,
|
93
|
+
outputDir = null,
|
94
|
+
cachePath = './build/.cache',
|
95
|
+
cwd = process.cwd(),
|
96
|
+
logger
|
97
|
+
} = {}) {
|
98
|
+
await build({
|
99
|
+
sourceMaps,
|
100
|
+
checkJSON,
|
101
|
+
cache,
|
102
|
+
cwd,
|
103
|
+
outputDir,
|
104
|
+
cachePath,
|
105
|
+
logger
|
106
|
+
})
|
107
|
+
}
|
108
|
+
|
109
|
+
/**
|
110
|
+
* Installs multiple plugins
|
111
|
+
* Can install from source folder or bower registry
|
112
|
+
* @param {Object} options
|
113
|
+
* @param {[string]} [options.plugins=null] An array with name@version or name@path strings
|
114
|
+
* @param {string} [options.cwd=process.cwd()] Root path of the framework installation
|
115
|
+
* @return {Promise<[Target]>}
|
116
|
+
*/
|
117
|
+
async installPlugins ({
|
118
|
+
plugins = null,
|
119
|
+
cwd = process.cwd(),
|
120
|
+
logger
|
121
|
+
} = {}) {
|
122
|
+
return await install({
|
123
|
+
plugins,
|
124
|
+
isInteractive: false,
|
125
|
+
cwd,
|
126
|
+
logger
|
127
|
+
})
|
128
|
+
}
|
129
|
+
|
130
|
+
/**
|
131
|
+
* Uninstalls multiple plugins
|
132
|
+
* @param {Object} options
|
133
|
+
* @param {[string]} [options.plugins=null] An array with name@version or name@path strings
|
134
|
+
* @param {string} [options.cwd=process.cwd()] Root path of the framework installation
|
135
|
+
* @return {Promise<[Target]>}
|
136
|
+
*/
|
137
|
+
async uninstallPlugins ({
|
138
|
+
plugins = null,
|
139
|
+
cwd = process.cwd(),
|
140
|
+
logger
|
141
|
+
} = {}) {
|
142
|
+
return await uninstall({
|
143
|
+
plugins,
|
144
|
+
isInteractive: false,
|
145
|
+
cwd,
|
146
|
+
logger
|
147
|
+
})
|
148
|
+
}
|
149
|
+
|
150
|
+
/**
|
151
|
+
* Updates multiple plugins
|
152
|
+
* Can install from source folder or bower registry
|
153
|
+
* @param {Object} options
|
154
|
+
* @param {[string]} [options.plugins=null] An array with name@version or name@path strings
|
155
|
+
* @param {string} [options.cwd=process.cwd()] Root path of the framework installation
|
156
|
+
* @return {Promise<[Target]>}
|
157
|
+
*/
|
158
|
+
async updatePlugins ({
|
159
|
+
plugins = null,
|
160
|
+
cwd = process.cwd(),
|
161
|
+
logger
|
162
|
+
} = {}) {
|
163
|
+
return await update({
|
164
|
+
plugins,
|
165
|
+
isInteractive: false,
|
166
|
+
cwd,
|
167
|
+
logger
|
168
|
+
})
|
169
|
+
}
|
170
|
+
|
171
|
+
/**
|
172
|
+
* Retrieves all schemas defined in the project
|
173
|
+
* Clears schema cache
|
174
|
+
* @param {string} [options.cwd=process.cwd()] Root path of the framework installation
|
175
|
+
* @return {Promise<[string]>} Resolves with array of JSON schema filepaths
|
176
|
+
*/
|
177
|
+
async getSchemaPaths ({
|
178
|
+
cwd = process.cwd()
|
179
|
+
} = {}) {
|
180
|
+
this._schemaPaths = await schemas({ cwd })
|
181
|
+
this._schemas = {}
|
182
|
+
return this._schemaPaths
|
183
|
+
}
|
184
|
+
|
185
|
+
/**
|
186
|
+
* Retrieves named schema
|
187
|
+
* Caches schemas for subsequent use
|
188
|
+
* Call getSchemaPaths to reset cache
|
189
|
+
* @param {string} options.name Schema filepath as returned from getSchemaPaths
|
190
|
+
* @return {Promise<Object>} Resolves with the JSON schema contents
|
191
|
+
*/
|
192
|
+
async getSchema ({
|
193
|
+
name
|
194
|
+
} = {}) {
|
195
|
+
if (!this._schemaPaths) return new Error('Please run getSchemaPaths first')
|
196
|
+
if (!fs.existsSync(name) || !this._schemaPaths.includes(name)) throw new Error(`Schema does not exist: ${name}`)
|
197
|
+
return (this._schemas[name] = this._schemas[name] ?? await fs.readJSON(name))
|
198
|
+
}
|
199
|
+
|
200
|
+
/**
|
201
|
+
* Returns all installed plugins
|
202
|
+
* @return {Promise<[Plugin]>}
|
203
|
+
*/
|
204
|
+
async getInstalledPlugins ({
|
205
|
+
cwd = process.cwd()
|
206
|
+
} = {}) {
|
207
|
+
const project = new Project({ cwd })
|
208
|
+
if (!project.isAdaptDirectory) throw new Error(`Not in an adapt folder at: ${cwd}`)
|
209
|
+
const installedPlugins = await project.getInstalledPlugins()
|
210
|
+
for (const plugin of installedPlugins) {
|
211
|
+
await plugin.fetchProjectInfo()
|
212
|
+
}
|
213
|
+
return installedPlugins
|
214
|
+
}
|
215
|
+
|
216
|
+
/**
|
217
|
+
* Gets the update information for installed and named plugins
|
218
|
+
* @param {Object} options
|
219
|
+
* @param {[string]} [options.plugins=null] An y of plugin names (if not specified, all plugins are checked)
|
220
|
+
* @param {string} [options.cwd=process.cwd()] Root path of the framework installation
|
221
|
+
* @return {Promise<[Plugin]>}
|
222
|
+
*/
|
223
|
+
async getPluginUpdateInfos ({
|
224
|
+
plugins = null,
|
225
|
+
cwd = process.cwd()
|
226
|
+
} = {}) {
|
227
|
+
/** @type {Project} */
|
228
|
+
const project = new Project({ cwd })
|
229
|
+
if (!project.isAdaptDirectory) throw new Error(`Not in an adapt folder at: ${cwd}`)
|
230
|
+
const frameworkVersion = project.version
|
231
|
+
/** @type {[Plugin]} */
|
232
|
+
const installedPlugins = await project.getInstalledPlugins()
|
233
|
+
const filteredPlugins = !plugins?.length
|
234
|
+
? installedPlugins
|
235
|
+
: plugins
|
236
|
+
.map(name => installedPlugins.find(plugin => plugin.packageName === name))
|
237
|
+
.filter(Boolean)
|
238
|
+
await async.eachOfLimit(filteredPlugins, 8, async plugin => {
|
239
|
+
await plugin.fetchProjectInfo()
|
240
|
+
await plugin.fetchBowerInfo()
|
241
|
+
await plugin.findCompatibleVersion(frameworkVersion)
|
242
|
+
})
|
243
|
+
return filteredPlugins
|
244
|
+
}
|
245
|
+
|
246
|
+
/**
|
247
|
+
* Returns an object representing the plugin at the path specified
|
248
|
+
* @returns {Plugin}
|
249
|
+
*/
|
250
|
+
async getPluginFromPath ({
|
251
|
+
pluginPath,
|
252
|
+
cwd = null
|
253
|
+
} = {}) {
|
254
|
+
const project = cwd ? new Project({ cwd }) : null
|
255
|
+
return Plugin.fromPath({ pluginPath, project })
|
256
|
+
}
|
257
|
+
}
|
258
|
+
|
259
|
+
const api = new API()
|
260
|
+
export default api
|
261
|
+
|
262
|
+
// debugging
|
263
|
+
if (process.argv.includes('--debug-wait')) {
|
264
|
+
// http server to hold open process for testing
|
265
|
+
const a = http.createServer((request, response) => {
|
266
|
+
response.writeHead(200, { 'Content-Type': 'text/plain' })
|
267
|
+
response.end('test', 'utf-8')
|
268
|
+
})
|
269
|
+
a.listen(999)
|
270
|
+
// make api global to debug more easily
|
271
|
+
global.api = api
|
272
|
+
console.log('API Ready')
|
273
|
+
}
|