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,299 +1,299 @@
1
- import chalk from 'chalk'
2
- import bower from 'bower'
3
- import { exec } from 'child_process'
4
- import semver from 'semver'
5
- import fs from 'fs-extra'
6
- import path from 'path'
7
- import { ADAPT_ALLOW_PRERELEASE } from '../util/constants.js'
8
- import Plugin from './Plugin.js'
9
- /** @typedef {import("./Project.js").default} Project */
10
- const semverOptions = { includePrerelease: ADAPT_ALLOW_PRERELEASE }
11
-
12
- export default class Target extends Plugin {
13
- /**
14
- * @param {Object} options
15
- * @param {string} options.name
16
- * @param {string} options.requestedVersion
17
- * @param {boolean} options.isContrib
18
- * @param {boolean} options.isCompatibleEnabled whether to target the latest compatible version for all plugin installations (overrides requestedVersion)
19
- * @param {Project} options.project
20
- * @param {string} options.cwd
21
- * @param {Object} options.logger
22
- */
23
- constructor ({
24
- name,
25
- requestedVersion = '*',
26
- isContrib = false,
27
- isCompatibleEnabled = false,
28
- project,
29
- cwd = (project?.cwd ?? process.cwd()),
30
- logger
31
- } = {}) {
32
- super({
33
- name,
34
- requestedVersion,
35
- isContrib,
36
- isCompatibleEnabled,
37
- project,
38
- cwd,
39
- logger
40
- })
41
- // The version to be installed
42
- this.versionToApply = null
43
- // Keep the project version preupdate
44
- this.preUpdateProjectVersion = null
45
- // Was explicitly skipped by the user
46
- this._isSkipped = null
47
- // Marks that this target was uninstalled, true, false and null
48
- this._wasUninstalled = null
49
- }
50
-
51
- /**
52
- * Was explicitly skipped by the user
53
- * @returns {boolean}
54
- */
55
- get isSkipped () {
56
- return Boolean(this._isSkipped)
57
- }
58
-
59
- get isNoApply () {
60
- return (this.isPresent && this.versionToApply === null)
61
- }
62
-
63
- /** @returns {boolean} */
64
- get hasProposedVersion () {
65
- return (this.matchedVersion !== null)
66
- }
67
-
68
- /** @returns {boolean} */
69
- get isToBeInstalled () {
70
- return (this.versionToApply !== null && !this._isSkipped)
71
- }
72
-
73
- /** @returns {boolean} */
74
- get isInstallSuccessful () {
75
- return (this.isToBeInstalled && this.isUpToDate)
76
- }
77
-
78
- /** @returns {boolean} */
79
- get isInstallFailure () {
80
- return (this.isToBeInstalled && !this.isUpToDate)
81
- }
82
-
83
- /** @returns {boolean} */
84
- get isToBeUninstalled () {
85
- return (this.versionToApply !== null && !this._isSkipped)
86
- }
87
-
88
- /** @returns {boolean} */
89
- get isUninstallSuccessful () {
90
- return (this.isToBeUninstalled && this._wasUninstalled)
91
- }
92
-
93
- /** @returns {boolean} */
94
- get isUninstallFailure () {
95
- return (this.isToBeUninstalled && !this._wasUninstalled)
96
- }
97
-
98
- /** @returns {boolean} */
99
- get isToBeUpdated () {
100
- return (this.versionToApply !== null && !this._isSkipped)
101
- }
102
-
103
- /** @returns {boolean} */
104
- get isUpdateSuccessful () {
105
- return (this.isToBeUpdated && this.isUpToDate)
106
- }
107
-
108
- /** @returns {boolean} */
109
- get isUpdateFailure () {
110
- return (this.isToBeUpdated && !this.isUpToDate)
111
- }
112
-
113
- /** @returns {boolean} */
114
- get isApplyLatestCompatibleVersion () {
115
- return (this.hasFrameworkCompatibleVersion &&
116
- semver.satisfies(this.latestCompatibleSourceVersion, this.matchedVersion, semverOptions))
117
- }
118
-
119
- markSkipped () {
120
- this._isSkipped = true
121
- }
122
-
123
- markInstallable () {
124
- if (!this.isApplyLatestCompatibleVersion && !(this.isLocalSource && this.latestSourceVersion)) return
125
- this.versionToApply = this.matchedVersion
126
- }
127
-
128
- markUpdateable () {
129
- if (!this.isPresent || this.isSkipped || !this.canBeUpdated) return
130
- if (this.projectVersion === this.matchedVersion) return
131
- this.versionToApply = this.matchedVersion
132
- }
133
-
134
- markMasterForInstallation () {
135
- this.versionToApply = 'master'
136
- }
137
-
138
- markRequestedForInstallation () {
139
- this.matchedVersion = this.matchedVersion ?? semver.maxSatisfying(this.sourceVersions, this.requestedVersion, semverOptions)
140
- if (this.projectVersion === this.matchedVersion) return
141
- this.versionToApply = this.matchedVersion
142
- }
143
-
144
- markLatestCompatibleForInstallation () {
145
- if (this.projectVersion === this.latestCompatibleSourceVersion) return
146
- this.versionToApply = this.latestCompatibleSourceVersion
147
- }
148
-
149
- markLatestForInstallation () {
150
- if (this.projectVersion === this.latestSourceVersion) return
151
- this.versionToApply = this.latestSourceVersion
152
- }
153
-
154
- markUninstallable () {
155
- if (!this.isPresent) return
156
- this.versionToApply = this.projectVersion
157
- }
158
-
159
- async install ({ clone = false } = {}) {
160
- const logger = this.logger
161
- const pluginTypeFolder = await this.getTypeFolder()
162
- if (this.isLocalSource) {
163
- await fs.ensureDir(path.resolve(this.cwd, 'src', pluginTypeFolder))
164
- const pluginPath = path.resolve(this.cwd, 'src', pluginTypeFolder, this.name)
165
- await fs.rm(pluginPath, { recursive: true, force: true })
166
- await fs.copy(this.sourcePath, pluginPath, { recursive: true })
167
- const bowerJSON = await fs.readJSON(path.join(pluginPath, 'bower.json'))
168
- bowerJSON._source = this.sourcePath
169
- bowerJSON._wasInstalledFromPath = true
170
- await fs.writeJSON(path.join(pluginPath, '.bower.json'), bowerJSON, { spaces: 2, replacer: null })
171
- this._projectInfo = null
172
- await this.fetchProjectInfo()
173
- return
174
- }
175
- if (clone) {
176
- // clone install
177
- const repoDetails = await this.getRepositoryUrl()
178
- if (!repoDetails) throw new Error('Error: Plugin repository url could not be found.')
179
- await fs.ensureDir(path.resolve(this.cwd, 'src', pluginTypeFolder))
180
- const pluginPath = path.resolve(this.cwd, 'src', pluginTypeFolder, this.name)
181
- await fs.rm(pluginPath, { recursive: true, force: true })
182
- const url = repoDetails.url.replace(/^git:\/\//, 'https://')
183
- try {
184
- const exitCode = await new Promise((resolve, reject) => {
185
- try {
186
- exec(`git clone ${url} "${pluginPath}"`, resolve)
187
- } catch (err) {
188
- reject(err)
189
- }
190
- })
191
- if (exitCode) throw new Error(`The plugin was found but failed to download and install. Exit code ${exitCode}`)
192
- } catch (error) {
193
- throw new Error(`The plugin was found but failed to download and install. Error ${error}`)
194
- }
195
- if (this.versionToApply !== '*') {
196
- try {
197
- await new Promise(resolve => exec(`git -C "${pluginPath}" checkout v${this.versionToApply}`, resolve))
198
- logger?.log(chalk.green(this.packageName), `is on branch "${this.versionToApply}".`)
199
- } catch (err) {
200
- throw new Error(chalk.yellow(this.packageName), `could not checkout branch "${this.versionToApply}".`)
201
- }
202
- }
203
- this._projectInfo = null
204
- await this.fetchProjectInfo()
205
- return
206
- }
207
- // bower install
208
- const outputPath = path.join(this.cwd, 'src', pluginTypeFolder)
209
- const pluginPath = path.join(outputPath, this.name)
210
- try {
211
- await fs.rm(pluginPath, { recursive: true, force: true })
212
- } catch (err) {
213
- throw new Error(`There was a problem writing to the target directory ${pluginPath}`)
214
- }
215
- await new Promise((resolve, reject) => {
216
- const pluginNameVersion = `${this.packageName}@${this.versionToApply}`
217
- bower.commands.install([pluginNameVersion], null, {
218
- directory: outputPath,
219
- cwd: this.cwd,
220
- registry: this.BOWER_REGISTRY_CONFIG
221
- })
222
- .on('end', resolve)
223
- .on('error', err => {
224
- err = new Error(`Bower reported ${err}`)
225
- this._error = err
226
- reject(err)
227
- })
228
- })
229
- const bowerJSON = await fs.readJSON(path.join(pluginPath, 'bower.json'))
230
- bowerJSON.version = bowerJSON.version ?? this.versionToApply;
231
- await fs.writeJSON(path.join(pluginPath, '.bower.json'), bowerJSON, { spaces: 2, replacer: null })
232
- this._projectInfo = null
233
- await this.fetchProjectInfo()
234
- }
235
-
236
- async update () {
237
- if (!this.isToBeUpdated) throw new Error()
238
- const typeFolder = await this.getTypeFolder()
239
- const outputPath = path.join(this.cwd, 'src', typeFolder)
240
- const pluginPath = path.join(outputPath, this.name)
241
- try {
242
- await fs.rm(pluginPath, { recursive: true, force: true })
243
- } catch (err) {
244
- throw new Error(`There was a problem writing to the target directory ${pluginPath}`)
245
- }
246
- await new Promise((resolve, reject) => {
247
- const pluginNameVersion = `${this.packageName}@${this.matchedVersion}`
248
- bower.commands.install([pluginNameVersion], null, {
249
- directory: outputPath,
250
- cwd: this.cwd,
251
- registry: this.BOWER_REGISTRY_CONFIG
252
- })
253
- .on('end', resolve)
254
- .on('error', err => {
255
- err = new Error(`Bower reported ${err}`)
256
- this._error = err
257
- reject(err)
258
- })
259
- })
260
- this.preUpdateProjectVersion = this.projectVersion
261
- this._projectInfo = null
262
- await this.fetchProjectInfo()
263
- }
264
-
265
- async uninstall () {
266
- try {
267
- if (!this.isToBeUninstalled) throw new Error()
268
- await fs.rm(this.projectPath, { recursive: true, force: true })
269
- this._wasUninstalled = true
270
- } catch (err) {
271
- this._wasUninstalled = false
272
- throw new Error(`There was a problem writing to the target directory ${this.projectPath}`)
273
- }
274
- }
275
-
276
- isNameMatch (name) {
277
- const tester = new RegExp(`${name}$`, 'i')
278
- return tester.test(this.packageName)
279
- }
280
-
281
- /**
282
- * Read plugin data from pluginPath
283
- * @param {Object} options
284
- * @param {string} options.pluginPath Path to source directory
285
- * @param {string} [options.projectPath=process.cwd()] Optional path to potential installation project
286
- * @returns {Target}
287
- */
288
- static async fromPath ({
289
- pluginPath,
290
- projectPath = process.cwd()
291
- }) {
292
- const target = new Target({
293
- name: pluginPath,
294
- cwd: projectPath
295
- })
296
- await target.fetchLocalSourceInfo()
297
- return target
298
- }
299
- }
1
+ import chalk from 'chalk'
2
+ import bower from 'bower'
3
+ import { exec } from 'child_process'
4
+ import semver from 'semver'
5
+ import fs from 'fs-extra'
6
+ import path from 'path'
7
+ import { ADAPT_ALLOW_PRERELEASE } from '../util/constants.js'
8
+ import Plugin from './Plugin.js'
9
+ /** @typedef {import("./Project.js").default} Project */
10
+ const semverOptions = { includePrerelease: ADAPT_ALLOW_PRERELEASE }
11
+
12
+ export default class Target extends Plugin {
13
+ /**
14
+ * @param {Object} options
15
+ * @param {string} options.name
16
+ * @param {string} options.requestedVersion
17
+ * @param {boolean} options.isContrib
18
+ * @param {boolean} options.isCompatibleEnabled whether to target the latest compatible version for all plugin installations (overrides requestedVersion)
19
+ * @param {Project} options.project
20
+ * @param {string} options.cwd
21
+ * @param {Object} options.logger
22
+ */
23
+ constructor ({
24
+ name,
25
+ requestedVersion = '*',
26
+ isContrib = false,
27
+ isCompatibleEnabled = false,
28
+ project,
29
+ cwd = (project?.cwd ?? process.cwd()),
30
+ logger
31
+ } = {}) {
32
+ super({
33
+ name,
34
+ requestedVersion,
35
+ isContrib,
36
+ isCompatibleEnabled,
37
+ project,
38
+ cwd,
39
+ logger
40
+ })
41
+ // The version to be installed
42
+ this.versionToApply = null
43
+ // Keep the project version preupdate
44
+ this.preUpdateProjectVersion = null
45
+ // Was explicitly skipped by the user
46
+ this._isSkipped = null
47
+ // Marks that this target was uninstalled, true, false and null
48
+ this._wasUninstalled = null
49
+ }
50
+
51
+ /**
52
+ * Was explicitly skipped by the user
53
+ * @returns {boolean}
54
+ */
55
+ get isSkipped () {
56
+ return Boolean(this._isSkipped)
57
+ }
58
+
59
+ get isNoApply () {
60
+ return (this.isPresent && this.versionToApply === null)
61
+ }
62
+
63
+ /** @returns {boolean} */
64
+ get hasProposedVersion () {
65
+ return (this.matchedVersion !== null)
66
+ }
67
+
68
+ /** @returns {boolean} */
69
+ get isToBeInstalled () {
70
+ return (this.versionToApply !== null && !this._isSkipped)
71
+ }
72
+
73
+ /** @returns {boolean} */
74
+ get isInstallSuccessful () {
75
+ return (this.isToBeInstalled && this.isUpToDate)
76
+ }
77
+
78
+ /** @returns {boolean} */
79
+ get isInstallFailure () {
80
+ return (this.isToBeInstalled && !this.isUpToDate)
81
+ }
82
+
83
+ /** @returns {boolean} */
84
+ get isToBeUninstalled () {
85
+ return (this.versionToApply !== null && !this._isSkipped)
86
+ }
87
+
88
+ /** @returns {boolean} */
89
+ get isUninstallSuccessful () {
90
+ return (this.isToBeUninstalled && this._wasUninstalled)
91
+ }
92
+
93
+ /** @returns {boolean} */
94
+ get isUninstallFailure () {
95
+ return (this.isToBeUninstalled && !this._wasUninstalled)
96
+ }
97
+
98
+ /** @returns {boolean} */
99
+ get isToBeUpdated () {
100
+ return (this.versionToApply !== null && !this._isSkipped)
101
+ }
102
+
103
+ /** @returns {boolean} */
104
+ get isUpdateSuccessful () {
105
+ return (this.isToBeUpdated && this.isUpToDate)
106
+ }
107
+
108
+ /** @returns {boolean} */
109
+ get isUpdateFailure () {
110
+ return (this.isToBeUpdated && !this.isUpToDate)
111
+ }
112
+
113
+ /** @returns {boolean} */
114
+ get isApplyLatestCompatibleVersion () {
115
+ return (this.hasFrameworkCompatibleVersion &&
116
+ semver.satisfies(this.latestCompatibleSourceVersion, this.matchedVersion, semverOptions))
117
+ }
118
+
119
+ markSkipped () {
120
+ this._isSkipped = true
121
+ }
122
+
123
+ markInstallable () {
124
+ if (!this.isApplyLatestCompatibleVersion && !(this.isLocalSource && this.latestSourceVersion)) return
125
+ this.versionToApply = this.matchedVersion
126
+ }
127
+
128
+ markUpdateable () {
129
+ if (!this.isPresent || this.isSkipped || !this.canBeUpdated) return
130
+ if (this.projectVersion === this.matchedVersion) return
131
+ this.versionToApply = this.matchedVersion
132
+ }
133
+
134
+ markMasterForInstallation () {
135
+ this.versionToApply = 'master'
136
+ }
137
+
138
+ markRequestedForInstallation () {
139
+ this.matchedVersion = this.matchedVersion ?? semver.maxSatisfying(this.sourceVersions, this.requestedVersion, semverOptions)
140
+ if (this.projectVersion === this.matchedVersion) return
141
+ this.versionToApply = this.matchedVersion
142
+ }
143
+
144
+ markLatestCompatibleForInstallation () {
145
+ if (this.projectVersion === this.latestCompatibleSourceVersion) return
146
+ this.versionToApply = this.latestCompatibleSourceVersion
147
+ }
148
+
149
+ markLatestForInstallation () {
150
+ if (this.projectVersion === this.latestSourceVersion) return
151
+ this.versionToApply = this.latestSourceVersion
152
+ }
153
+
154
+ markUninstallable () {
155
+ if (!this.isPresent) return
156
+ this.versionToApply = this.projectVersion
157
+ }
158
+
159
+ async install ({ clone = false } = {}) {
160
+ const logger = this.logger
161
+ const pluginTypeFolder = await this.getTypeFolder()
162
+ if (this.isLocalSource) {
163
+ await fs.ensureDir(path.resolve(this.cwd, 'src', pluginTypeFolder))
164
+ const pluginPath = path.resolve(this.cwd, 'src', pluginTypeFolder, this.name)
165
+ await fs.rm(pluginPath, { recursive: true, force: true })
166
+ await fs.copy(this.sourcePath, pluginPath, { recursive: true })
167
+ const bowerJSON = await fs.readJSON(path.join(pluginPath, 'bower.json'))
168
+ bowerJSON._source = this.sourcePath
169
+ bowerJSON._wasInstalledFromPath = true
170
+ await fs.writeJSON(path.join(pluginPath, '.bower.json'), bowerJSON, { spaces: 2, replacer: null })
171
+ this._projectInfo = null
172
+ await this.fetchProjectInfo()
173
+ return
174
+ }
175
+ if (clone) {
176
+ // clone install
177
+ const repoDetails = await this.getRepositoryUrl()
178
+ if (!repoDetails) throw new Error('Error: Plugin repository url could not be found.')
179
+ await fs.ensureDir(path.resolve(this.cwd, 'src', pluginTypeFolder))
180
+ const pluginPath = path.resolve(this.cwd, 'src', pluginTypeFolder, this.name)
181
+ await fs.rm(pluginPath, { recursive: true, force: true })
182
+ const url = repoDetails.url.replace(/^git:\/\//, 'https://')
183
+ try {
184
+ const exitCode = await new Promise((resolve, reject) => {
185
+ try {
186
+ exec(`git clone ${url} "${pluginPath}"`, resolve)
187
+ } catch (err) {
188
+ reject(err)
189
+ }
190
+ })
191
+ if (exitCode) throw new Error(`The plugin was found but failed to download and install. Exit code ${exitCode}`)
192
+ } catch (error) {
193
+ throw new Error(`The plugin was found but failed to download and install. Error ${error}`)
194
+ }
195
+ if (this.versionToApply !== '*') {
196
+ try {
197
+ await new Promise(resolve => exec(`git -C "${pluginPath}" checkout v${this.versionToApply}`, resolve))
198
+ logger?.log(chalk.green(this.packageName), `is on branch "${this.versionToApply}".`)
199
+ } catch (err) {
200
+ throw new Error(chalk.yellow(this.packageName), `could not checkout branch "${this.versionToApply}".`)
201
+ }
202
+ }
203
+ this._projectInfo = null
204
+ await this.fetchProjectInfo()
205
+ return
206
+ }
207
+ // bower install
208
+ const outputPath = path.join(this.cwd, 'src', pluginTypeFolder)
209
+ const pluginPath = path.join(outputPath, this.name)
210
+ try {
211
+ await fs.rm(pluginPath, { recursive: true, force: true })
212
+ } catch (err) {
213
+ throw new Error(`There was a problem writing to the target directory ${pluginPath}`)
214
+ }
215
+ await new Promise((resolve, reject) => {
216
+ const pluginNameVersion = `${this.packageName}@${this.versionToApply}`
217
+ bower.commands.install([pluginNameVersion], null, {
218
+ directory: outputPath,
219
+ cwd: this.cwd,
220
+ registry: this.BOWER_REGISTRY_CONFIG
221
+ })
222
+ .on('end', resolve)
223
+ .on('error', err => {
224
+ err = new Error(`Bower reported ${err}`)
225
+ this._error = err
226
+ reject(err)
227
+ })
228
+ })
229
+ const bowerJSON = await fs.readJSON(path.join(pluginPath, 'bower.json'))
230
+ bowerJSON.version = bowerJSON.version ?? this.versionToApply;
231
+ await fs.writeJSON(path.join(pluginPath, '.bower.json'), bowerJSON, { spaces: 2, replacer: null })
232
+ this._projectInfo = null
233
+ await this.fetchProjectInfo()
234
+ }
235
+
236
+ async update () {
237
+ if (!this.isToBeUpdated) throw new Error()
238
+ const typeFolder = await this.getTypeFolder()
239
+ const outputPath = path.join(this.cwd, 'src', typeFolder)
240
+ const pluginPath = path.join(outputPath, this.name)
241
+ try {
242
+ await fs.rm(pluginPath, { recursive: true, force: true })
243
+ } catch (err) {
244
+ throw new Error(`There was a problem writing to the target directory ${pluginPath}`)
245
+ }
246
+ await new Promise((resolve, reject) => {
247
+ const pluginNameVersion = `${this.packageName}@${this.matchedVersion}`
248
+ bower.commands.install([pluginNameVersion], null, {
249
+ directory: outputPath,
250
+ cwd: this.cwd,
251
+ registry: this.BOWER_REGISTRY_CONFIG
252
+ })
253
+ .on('end', resolve)
254
+ .on('error', err => {
255
+ err = new Error(`Bower reported ${err}`)
256
+ this._error = err
257
+ reject(err)
258
+ })
259
+ })
260
+ this.preUpdateProjectVersion = this.projectVersion
261
+ this._projectInfo = null
262
+ await this.fetchProjectInfo()
263
+ }
264
+
265
+ async uninstall () {
266
+ try {
267
+ if (!this.isToBeUninstalled) throw new Error()
268
+ await fs.rm(this.projectPath, { recursive: true, force: true })
269
+ this._wasUninstalled = true
270
+ } catch (err) {
271
+ this._wasUninstalled = false
272
+ throw new Error(`There was a problem writing to the target directory ${this.projectPath}`)
273
+ }
274
+ }
275
+
276
+ isNameMatch (name) {
277
+ const tester = new RegExp(`${name}$`, 'i')
278
+ return tester.test(this.packageName)
279
+ }
280
+
281
+ /**
282
+ * Read plugin data from pluginPath
283
+ * @param {Object} options
284
+ * @param {string} options.pluginPath Path to source directory
285
+ * @param {string} [options.projectPath=process.cwd()] Optional path to potential installation project
286
+ * @returns {Target}
287
+ */
288
+ static async fromPath ({
289
+ pluginPath,
290
+ projectPath = process.cwd()
291
+ }) {
292
+ const target = new Target({
293
+ name: pluginPath,
294
+ cwd: projectPath
295
+ })
296
+ await target.fetchLocalSourceInfo()
297
+ return target
298
+ }
299
+ }
@@ -1,34 +1,34 @@
1
- import fs from 'fs-extra'
2
- import { findUpSync } from 'find-up'
3
-
4
- export default function getBowerRegistryConfig ({ cwd = process.cwd() } = {}) {
5
- function getConfig () {
6
- if (process.env.ADAPT_REGISTRY) {
7
- return process.env.ADAPT_REGISTRY
8
- }
9
- const configPath = findUpSync('.bowerrc', { cwd })
10
- if (configPath) {
11
- // a manifest exists, load it
12
- const config = fs.readJSONSync(configPath)
13
- return config.registry
14
- }
15
- // use the default Adapt registry
16
- return 'http://adapt-bower-repository.herokuapp.com/'
17
- }
18
- // normalize to https://github.com/bower/spec/blob/master/config.md
19
- const config = getConfig()
20
- let normalized = {}
21
- switch (typeof config) {
22
- case 'string':
23
- normalized = {
24
- register: config,
25
- search: [config]
26
- }
27
- break
28
- case 'object':
29
- Object.assign(normalized, config)
30
- break
31
- }
32
- if (typeof normalized.search === 'string') normalized.search = [normalized.search].filter(Boolean)
33
- return normalized
34
- }
1
+ import fs from 'fs-extra'
2
+ import { findUpSync } from 'find-up'
3
+
4
+ export default function getBowerRegistryConfig ({ cwd = process.cwd() } = {}) {
5
+ function getConfig () {
6
+ if (process.env.ADAPT_REGISTRY) {
7
+ return process.env.ADAPT_REGISTRY
8
+ }
9
+ const configPath = findUpSync('.bowerrc', { cwd })
10
+ if (configPath) {
11
+ // a manifest exists, load it
12
+ const config = fs.readJSONSync(configPath)
13
+ return config.registry
14
+ }
15
+ // use the default Adapt registry
16
+ return 'http://adapt-bower-repository.herokuapp.com/'
17
+ }
18
+ // normalize to https://github.com/bower/spec/blob/master/config.md
19
+ const config = getConfig()
20
+ let normalized = {}
21
+ switch (typeof config) {
22
+ case 'string':
23
+ normalized = {
24
+ register: config,
25
+ search: [config]
26
+ }
27
+ break
28
+ case 'object':
29
+ Object.assign(normalized, config)
30
+ break
31
+ }
32
+ if (typeof normalized.search === 'string') normalized.search = [normalized.search].filter(Boolean)
33
+ return normalized
34
+ }