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
@@ -1,296 +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 = '
|
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
|
-
|
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
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
this.
|
269
|
-
|
270
|
-
}
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
*
|
283
|
-
* @
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
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
|
+
}
|