adapt-cli 3.0.2 → 3.0.6

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 (78) 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 +260 -260
  28. package/lib/cli.js +69 -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 +9 -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/integration/AdaptFramework/build.js +42 -42
  46. package/lib/integration/AdaptFramework/clone.js +27 -27
  47. package/lib/integration/AdaptFramework/deleteSrcCore.js +9 -9
  48. package/lib/integration/AdaptFramework/deleteSrcCourse.js +9 -9
  49. package/lib/integration/AdaptFramework/download.js +21 -21
  50. package/lib/integration/AdaptFramework/erase.js +34 -34
  51. package/lib/integration/AdaptFramework/getLatestVersion.js +79 -79
  52. package/lib/integration/AdaptFramework/npmInstall.js +21 -21
  53. package/lib/integration/AdaptFramework.js +19 -19
  54. package/lib/integration/Plugin.js +404 -404
  55. package/lib/integration/PluginManagement/autenticate.js +56 -56
  56. package/lib/integration/PluginManagement/install.js +224 -224
  57. package/lib/integration/PluginManagement/print.js +52 -52
  58. package/lib/integration/PluginManagement/register.js +130 -130
  59. package/lib/integration/PluginManagement/rename.js +101 -101
  60. package/lib/integration/PluginManagement/schemas.js +8 -8
  61. package/lib/integration/PluginManagement/search.js +46 -46
  62. package/lib/integration/PluginManagement/uninstall.js +141 -141
  63. package/lib/integration/PluginManagement/unregister.js +101 -101
  64. package/lib/integration/PluginManagement/update.js +224 -224
  65. package/lib/integration/PluginManagement.js +21 -21
  66. package/lib/integration/Project.js +146 -146
  67. package/lib/integration/Target.js +299 -299
  68. package/lib/integration/getBowerRegistryConfig.js +34 -34
  69. package/lib/logger.js +28 -28
  70. package/lib/util/JSONReadValidate.js +34 -34
  71. package/lib/util/constants.js +38 -38
  72. package/lib/util/createPromptTask.js +7 -7
  73. package/lib/util/download.js +45 -45
  74. package/lib/util/errors.js +58 -58
  75. package/lib/util/extract.js +24 -24
  76. package/lib/util/getDirNameFromImportMeta.js +6 -6
  77. package/lib/util/promises.js +36 -36
  78. package/package.json +74 -40
@@ -1,146 +1,146 @@
1
- import fs from 'fs-extra'
2
- import path from 'path'
3
- import globs from 'globs'
4
- import { readValidateJSON, readValidateJSONSync } from '../util/JSONReadValidate.js'
5
- import Plugin from './Plugin.js'
6
- import Target from './Target.js'
7
- export const MANIFEST_FILENAME = 'adapt.json'
8
- export const FRAMEWORK_FILENAME = 'package.json'
9
-
10
- /**
11
- * A representation of the target Adapt Framework project
12
- */
13
- export default class Project {
14
- constructor ({
15
- cwd = process.cwd(),
16
- logger
17
- } = {}) {
18
- this.logger = logger
19
- this.cwd = cwd
20
- this.manifestFilePath = path.resolve(this.cwd, MANIFEST_FILENAME)
21
- this.frameworkPackagePath = path.resolve(this.cwd, FRAMEWORK_FILENAME)
22
- }
23
-
24
- /** @returns {boolean} */
25
- get isAdaptDirectory () {
26
- try {
27
- // are we inside an existing adapt_framework project.
28
- const packageJSON = fs.readJSONSync(this.cwd + '/package.json')
29
- return (packageJSON.name === 'adapt_framework')
30
- } catch (err) {
31
- // don't worry, we're not inside a framework directory.
32
- }
33
- return false
34
- }
35
-
36
- /** @returns {boolean} */
37
- get containsManifestFile () {
38
- if (!this.isAdaptDirectory) return false
39
- return fs.existsSync(this.manifestFilePath)
40
- }
41
-
42
- /** @returns {string} */
43
- get version () {
44
- try {
45
- return readValidateJSONSync(this.frameworkPackagePath).version
46
- } catch (ex) {
47
- return null
48
- }
49
- }
50
-
51
- tryThrowInvalidPath () {
52
- if (this.containsManifestFile) return
53
- this.logger?.error('Fatal error: please run above commands in adapt course directory.')
54
- throw new Error('Fatal error: please run above commands in adapt course directory.')
55
- }
56
-
57
- /** @returns {[Target]} */
58
- async getInstallTargets () {
59
- return Object.entries(await this.getManifestDependencies()).map(([name, requestedVersion]) => new Target({ name, requestedVersion, project: this, logger: this.logger }))
60
- }
61
-
62
- /** @returns {[string]} */
63
- async getManifestDependencies () {
64
- const manifest = await readValidateJSON(this.manifestFilePath)
65
- return manifest.dependencies
66
- }
67
-
68
- /** @returns {[Plugin]} */
69
- async getInstalledPlugins () {
70
- return Object.entries(await this.getInstalledDependencies()).map(([name]) => new Plugin({ name, project: this, logger: this.logger }))
71
- }
72
-
73
- /** @returns {[Target]} */
74
- async getUninstallTargets () {
75
- return Object.entries(await this.getInstalledDependencies()).map(([name]) => new Target({ name, project: this, logger: this.logger }))
76
- }
77
-
78
- /** @returns {[Target]} */
79
- async getUpdateTargets () {
80
- return Object.entries(await this.getInstalledDependencies()).map(([name]) => new Target({ name, project: this, logger: this.logger }))
81
- }
82
-
83
- async getInstalledDependencies () {
84
- const getDependencyBowerJSONs = async () => {
85
- const glob = `${this.cwd.replace(/\\/g, '/')}/src/**/bower.json`
86
- const bowerJSONPaths = await new Promise((resolve, reject) => {
87
- globs(glob, (err, matches) => {
88
- if (err) return reject(err)
89
- resolve(matches)
90
- })
91
- })
92
- const bowerJSONs = []
93
- for (const bowerJSONPath of bowerJSONPaths) {
94
- try {
95
- bowerJSONs.push(await fs.readJSON(bowerJSONPath))
96
- } catch (err) {}
97
- }
98
- return bowerJSONs
99
- }
100
- const dependencies = (await getDependencyBowerJSONs())
101
- .filter(bowerJSON => bowerJSON?.name && bowerJSON?.version)
102
- .reduce((dependencies, bowerJSON) => {
103
- dependencies[bowerJSON.name] = bowerJSON.version
104
- return dependencies
105
- }, {})
106
- return dependencies
107
- }
108
-
109
- async getSchemaPaths () {
110
- const glob = `${this.cwd.replace(/\\/g, '/')}/src/**/*.schema.json`
111
- const bowerJSONPaths = await new Promise((resolve, reject) => {
112
- globs(glob, (err, matches) => {
113
- if (err) return reject(err)
114
- resolve(matches)
115
- })
116
- })
117
- return bowerJSONPaths
118
- }
119
-
120
- /**
121
- * @param {Plugin} plugin
122
- */
123
- add (plugin) {
124
- if (typeof Plugin !== 'object' && !(plugin instanceof Plugin)) {
125
- plugin = new Plugin({ name: plugin })
126
- }
127
- let manifest = { version: '0.0.0', dependencies: {} }
128
- if (this.containsManifestFile) {
129
- manifest = readValidateJSONSync(this.manifestFilePath)
130
- }
131
- manifest.dependencies[plugin.packageName] = plugin.sourcePath || plugin.requestedVersion || plugin.version
132
- fs.writeJSONSync(this.manifestFilePath, manifest, { spaces: 2, replacer: null })
133
- }
134
-
135
- /**
136
- * @param {Plugin} plugin
137
- */
138
- remove (plugin) {
139
- if (typeof Plugin !== 'object' && !(plugin instanceof Plugin)) {
140
- plugin = new Plugin({ name: plugin })
141
- }
142
- const manifest = readValidateJSONSync(this.manifestFilePath)
143
- delete manifest.dependencies[plugin.packageName]
144
- fs.writeJSONSync(this.manifestFilePath, manifest, { spaces: 2, replacer: null })
145
- }
146
- }
1
+ import fs from 'fs-extra'
2
+ import path from 'path'
3
+ import globs from 'globs'
4
+ import { readValidateJSON, readValidateJSONSync } from '../util/JSONReadValidate.js'
5
+ import Plugin from './Plugin.js'
6
+ import Target from './Target.js'
7
+ export const MANIFEST_FILENAME = 'adapt.json'
8
+ export const FRAMEWORK_FILENAME = 'package.json'
9
+
10
+ /**
11
+ * A representation of the target Adapt Framework project
12
+ */
13
+ export default class Project {
14
+ constructor ({
15
+ cwd = process.cwd(),
16
+ logger
17
+ } = {}) {
18
+ this.logger = logger
19
+ this.cwd = cwd
20
+ this.manifestFilePath = path.resolve(this.cwd, MANIFEST_FILENAME)
21
+ this.frameworkPackagePath = path.resolve(this.cwd, FRAMEWORK_FILENAME)
22
+ }
23
+
24
+ /** @returns {boolean} */
25
+ get isAdaptDirectory () {
26
+ try {
27
+ // are we inside an existing adapt_framework project.
28
+ const packageJSON = fs.readJSONSync(this.cwd + '/package.json')
29
+ return (packageJSON.name === 'adapt_framework')
30
+ } catch (err) {
31
+ // don't worry, we're not inside a framework directory.
32
+ }
33
+ return false
34
+ }
35
+
36
+ /** @returns {boolean} */
37
+ get containsManifestFile () {
38
+ if (!this.isAdaptDirectory) return false
39
+ return fs.existsSync(this.manifestFilePath)
40
+ }
41
+
42
+ /** @returns {string} */
43
+ get version () {
44
+ try {
45
+ return readValidateJSONSync(this.frameworkPackagePath).version
46
+ } catch (ex) {
47
+ return null
48
+ }
49
+ }
50
+
51
+ tryThrowInvalidPath () {
52
+ if (this.containsManifestFile) return
53
+ this.logger?.error('Fatal error: please run above commands in adapt course directory.')
54
+ throw new Error('Fatal error: please run above commands in adapt course directory.')
55
+ }
56
+
57
+ /** @returns {[Target]} */
58
+ async getInstallTargets () {
59
+ return Object.entries(await this.getManifestDependencies()).map(([name, requestedVersion]) => new Target({ name, requestedVersion, project: this, logger: this.logger }))
60
+ }
61
+
62
+ /** @returns {[string]} */
63
+ async getManifestDependencies () {
64
+ const manifest = await readValidateJSON(this.manifestFilePath)
65
+ return manifest.dependencies
66
+ }
67
+
68
+ /** @returns {[Plugin]} */
69
+ async getInstalledPlugins () {
70
+ return Object.entries(await this.getInstalledDependencies()).map(([name]) => new Plugin({ name, project: this, logger: this.logger }))
71
+ }
72
+
73
+ /** @returns {[Target]} */
74
+ async getUninstallTargets () {
75
+ return Object.entries(await this.getInstalledDependencies()).map(([name]) => new Target({ name, project: this, logger: this.logger }))
76
+ }
77
+
78
+ /** @returns {[Target]} */
79
+ async getUpdateTargets () {
80
+ return Object.entries(await this.getInstalledDependencies()).map(([name]) => new Target({ name, project: this, logger: this.logger }))
81
+ }
82
+
83
+ async getInstalledDependencies () {
84
+ const getDependencyBowerJSONs = async () => {
85
+ const glob = `${this.cwd.replace(/\\/g, '/')}/src/**/bower.json`
86
+ const bowerJSONPaths = await new Promise((resolve, reject) => {
87
+ globs(glob, (err, matches) => {
88
+ if (err) return reject(err)
89
+ resolve(matches)
90
+ })
91
+ })
92
+ const bowerJSONs = []
93
+ for (const bowerJSONPath of bowerJSONPaths) {
94
+ try {
95
+ bowerJSONs.push(await fs.readJSON(bowerJSONPath))
96
+ } catch (err) {}
97
+ }
98
+ return bowerJSONs
99
+ }
100
+ const dependencies = (await getDependencyBowerJSONs())
101
+ .filter(bowerJSON => bowerJSON?.name && bowerJSON?.version)
102
+ .reduce((dependencies, bowerJSON) => {
103
+ dependencies[bowerJSON.name] = bowerJSON.version
104
+ return dependencies
105
+ }, {})
106
+ return dependencies
107
+ }
108
+
109
+ async getSchemaPaths () {
110
+ const glob = `${this.cwd.replace(/\\/g, '/')}/src/**/*.schema.json`
111
+ const bowerJSONPaths = await new Promise((resolve, reject) => {
112
+ globs(glob, (err, matches) => {
113
+ if (err) return reject(err)
114
+ resolve(matches)
115
+ })
116
+ })
117
+ return bowerJSONPaths
118
+ }
119
+
120
+ /**
121
+ * @param {Plugin} plugin
122
+ */
123
+ add (plugin) {
124
+ if (typeof Plugin !== 'object' && !(plugin instanceof Plugin)) {
125
+ plugin = new Plugin({ name: plugin })
126
+ }
127
+ let manifest = { version: '0.0.0', dependencies: {} }
128
+ if (this.containsManifestFile) {
129
+ manifest = readValidateJSONSync(this.manifestFilePath)
130
+ }
131
+ manifest.dependencies[plugin.packageName] = plugin.sourcePath || plugin.requestedVersion || plugin.version
132
+ fs.writeJSONSync(this.manifestFilePath, manifest, { spaces: 2, replacer: null })
133
+ }
134
+
135
+ /**
136
+ * @param {Plugin} plugin
137
+ */
138
+ remove (plugin) {
139
+ if (typeof Plugin !== 'object' && !(plugin instanceof Plugin)) {
140
+ plugin = new Plugin({ name: plugin })
141
+ }
142
+ const manifest = readValidateJSONSync(this.manifestFilePath)
143
+ delete manifest.dependencies[plugin.packageName]
144
+ fs.writeJSONSync(this.manifestFilePath, manifest, { spaces: 2, replacer: null })
145
+ }
146
+ }