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