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,52 +1,52 @@
1
- import chalk from 'chalk'
2
- import semver from 'semver'
3
- import { ADAPT_ALLOW_PRERELEASE } from '../../util/constants.js'
4
- const semverOptions = { includePrerelease: ADAPT_ALLOW_PRERELEASE }
5
-
6
- function highlight (pluginname) {
7
- return ['adapt-contrib', 'adapt-'].reduce((output, prefix) => {
8
- if (output || !pluginname.startsWith(prefix)) return output
9
- return chalk.reset(prefix) + chalk.yellowBright(pluginname.substring(prefix.length))
10
- }, null) || pluginname
11
- }
12
-
13
- function greenIfEqual (v1, v2) {
14
- if (v1 === '*') return chalk.greenBright(v2)
15
- return semver.satisfies(v1, v2, semverOptions)
16
- ? chalk.greenBright(v2)
17
- : chalk.magentaBright(v2)
18
- }
19
-
20
- export function versionPrinter (plugin, logger) {
21
- const {
22
- versionToApply,
23
- latestCompatibleSourceVersion
24
- } = plugin
25
- logger?.log(highlight(plugin.packageName), latestCompatibleSourceVersion === null
26
- ? '(no version information)'
27
- : `${chalk.greenBright(versionToApply)}${plugin.isLocalSource ? ' (local)' : ` (latest compatible version is ${greenIfEqual(versionToApply, latestCompatibleSourceVersion)})`}`
28
- )
29
- }
30
-
31
- export function existingVersionPrinter (plugin, logger) {
32
- const {
33
- preUpdateProjectVersion,
34
- projectVersion,
35
- latestCompatibleSourceVersion
36
- } = plugin
37
- const fromTo = preUpdateProjectVersion !== null
38
- ? `from ${chalk.greenBright(preUpdateProjectVersion)} to ${chalk.greenBright(projectVersion)}`
39
- : `${chalk.greenBright(projectVersion)}`
40
- logger?.log(highlight(plugin.packageName), latestCompatibleSourceVersion === null
41
- ? fromTo
42
- : `${fromTo}${plugin.isLocalSource ? ' (local)' : ` (latest compatible version is ${greenIfEqual(projectVersion, latestCompatibleSourceVersion)})`}`
43
- )
44
- }
45
-
46
- export function errorPrinter (plugin, logger) {
47
- logger?.log(highlight(plugin.packageName), plugin.installError ? '(error: ' + plugin.installError + ')' : '(unknown error)')
48
- }
49
-
50
- export function packageNamePrinter (plugin, logger) {
51
- logger?.log(highlight(plugin.packageName))
52
- }
1
+ import chalk from 'chalk'
2
+ import semver from 'semver'
3
+ import { ADAPT_ALLOW_PRERELEASE } from '../../util/constants.js'
4
+ const semverOptions = { includePrerelease: ADAPT_ALLOW_PRERELEASE }
5
+
6
+ function highlight (pluginname) {
7
+ return ['adapt-contrib', 'adapt-'].reduce((output, prefix) => {
8
+ if (output || !pluginname.startsWith(prefix)) return output
9
+ return chalk.reset(prefix) + chalk.yellowBright(pluginname.substring(prefix.length))
10
+ }, null) || pluginname
11
+ }
12
+
13
+ function greenIfEqual (v1, v2) {
14
+ if (v1 === '*') return chalk.greenBright(v2)
15
+ return semver.satisfies(v1, v2, semverOptions)
16
+ ? chalk.greenBright(v2)
17
+ : chalk.magentaBright(v2)
18
+ }
19
+
20
+ export function versionPrinter (plugin, logger) {
21
+ const {
22
+ versionToApply,
23
+ latestCompatibleSourceVersion
24
+ } = plugin
25
+ logger?.log(highlight(plugin.packageName), latestCompatibleSourceVersion === null
26
+ ? '(no version information)'
27
+ : `${chalk.greenBright(versionToApply)}${plugin.isLocalSource ? ' (local)' : ` (latest compatible version is ${greenIfEqual(versionToApply, latestCompatibleSourceVersion)})`}`
28
+ )
29
+ }
30
+
31
+ export function existingVersionPrinter (plugin, logger) {
32
+ const {
33
+ preUpdateProjectVersion,
34
+ projectVersion,
35
+ latestCompatibleSourceVersion
36
+ } = plugin
37
+ const fromTo = preUpdateProjectVersion !== null
38
+ ? `from ${chalk.greenBright(preUpdateProjectVersion)} to ${chalk.greenBright(projectVersion)}`
39
+ : `${chalk.greenBright(projectVersion)}`
40
+ logger?.log(highlight(plugin.packageName), latestCompatibleSourceVersion === null
41
+ ? fromTo
42
+ : `${fromTo}${plugin.isLocalSource ? ' (local)' : ` (latest compatible version is ${greenIfEqual(projectVersion, latestCompatibleSourceVersion)})`}`
43
+ )
44
+ }
45
+
46
+ export function errorPrinter (plugin, logger) {
47
+ logger?.log(highlight(plugin.packageName), plugin.installError ? '(error: ' + plugin.installError + ')' : '(unknown error)')
48
+ }
49
+
50
+ export function packageNamePrinter (plugin, logger) {
51
+ logger?.log(highlight(plugin.packageName))
52
+ }
@@ -1,130 +1,130 @@
1
-
2
- import getBowerRegistryConfig from '../getBowerRegistryConfig.js'
3
- import fs from 'fs-extra'
4
- import path from 'path'
5
- import bower from 'bower'
6
- import chalk from 'chalk'
7
- import inquirer from 'inquirer'
8
- import { readValidateJSON } from '../../util/JSONReadValidate.js'
9
- import Plugin from '../Plugin.js'
10
- import semver from 'semver'
11
- import { ADAPT_ALLOW_PRERELEASE } from '../../util/constants.js'
12
- const semverOptions = { includePrerelease: ADAPT_ALLOW_PRERELEASE }
13
-
14
- export default async function register ({
15
- logger,
16
- cwd = process.cwd()
17
- } = {}) {
18
- cwd = path.resolve(process.cwd(), cwd)
19
- const BOWER_REGISTRY_CONFIG = getBowerRegistryConfig({ cwd })
20
- logger?.warn('Using registry at', BOWER_REGISTRY_CONFIG.register)
21
- try {
22
- const bowerJSONPath = path.join(cwd, 'bower.json')
23
- const hasBowerJSON = fs.existsSync(bowerJSONPath)
24
-
25
- const bowerJSON = {
26
- name: undefined,
27
- repository: undefined,
28
- framework: undefined,
29
- ...(hasBowerJSON ? await readValidateJSON(bowerJSONPath) : {})
30
- }
31
- const properties = await confirm(bowerJSON)
32
- hasBowerJSON && await fs.writeJSON(bowerJSONPath, properties, { spaces: 2, replacer: null })
33
-
34
- // given a package name, create two Plugin representations
35
- // if supplied name is adapt-contrib-myPackageName do a check against this name only
36
- // if suppled name is adapt-myPackageName check against this name and adapt-contrib-myPackageName
37
- // becase we don't want to allow adapt-myPackageName if adapt-contrib-myPackageName exists
38
- const plugin = new Plugin({ name: properties.name, logger })
39
- const contribPlugin = new Plugin({ name: properties.name, isContrib: true, logger })
40
- const contribExists = await exists(BOWER_REGISTRY_CONFIG, contribPlugin)
41
- const pluginExists = await exists(BOWER_REGISTRY_CONFIG, plugin)
42
-
43
- if (contribExists || pluginExists) {
44
- logger?.warn(plugin.toString(), 'has been previously registered. Plugin names must be unique. Try again with a different name.')
45
- return
46
- }
47
-
48
- const result = await registerWithBowerRepo(BOWER_REGISTRY_CONFIG, plugin, properties.repository)
49
- if (!result) throw new Error('The plugin was unable to register.')
50
- logger?.log(chalk.green(plugin.packageName), 'has been registered successfully.')
51
- } catch (err) {
52
- logger?.error(err)
53
- }
54
- }
55
-
56
- async function confirm (properties) {
57
- const plugin = new Plugin({ name: properties.name })
58
- const schema = [
59
- {
60
- name: 'name',
61
- message: chalk.cyan('name'),
62
- validate: v => {
63
- return /^adapt-[\w|-]+?$/.test(v) ||
64
- 'Name must prefixed with \'adapt\' and each word separated with a hyphen(-)'
65
- },
66
- type: 'input',
67
- default: plugin.toString() || 'not specified'
68
- },
69
- {
70
- name: 'repositoryUrl',
71
- message: chalk.cyan('repository URL'),
72
- validate: v => {
73
- return /https:\/\/([\w.@:/\-~]+)(\.git)(\/)?/.test(v) ||
74
- 'Please provide a repository URL of the form https://<domain><path>.git'
75
- },
76
- type: 'input',
77
- default: properties.repository ? properties.repository.url : undefined
78
- },
79
- {
80
- name: 'framework',
81
- message: chalk.cyan('framework'),
82
- validate: v => {
83
- return semver.validRange(v, semverOptions) !== null ||
84
- 'Please provide a valid semver (see https://semver.org/)'
85
- },
86
- type: 'input',
87
- default: properties.framework || '>=5.15'
88
- },
89
- {
90
- name: 'ready',
91
- message: chalk.cyan('Register now?'),
92
- type: 'confirm',
93
- default: true
94
- }
95
- ]
96
- const confirmation = await inquirer.prompt(schema)
97
- if (!confirmation.ready) throw new Error('Aborted. Nothing has been registered.')
98
- properties.name = confirmation.name
99
- properties.repository = { type: 'git', url: confirmation.repositoryUrl }
100
- properties.framework = confirmation.framework
101
- return properties
102
- }
103
-
104
- /**
105
- * @param {Plugin} plugin
106
- * @returns {boolean}
107
- */
108
- async function exists (BOWER_REGISTRY_CONFIG, plugin) {
109
- const pluginName = plugin.toString().toLowerCase()
110
- return new Promise((resolve, reject) => {
111
- bower.commands.search(pluginName, {
112
- registry: BOWER_REGISTRY_CONFIG.register
113
- })
114
- .on('end', result => {
115
- const matches = result.filter(({ name }) => name.toLowerCase() === pluginName)
116
- resolve(Boolean(matches.length))
117
- })
118
- .on('error', reject)
119
- })
120
- }
121
-
122
- async function registerWithBowerRepo (BOWER_REGISTRY_CONFIG, plugin, repository) {
123
- return new Promise((resolve, reject) => {
124
- bower.commands.register(plugin.toString(), repository.url || repository, {
125
- registry: BOWER_REGISTRY_CONFIG
126
- })
127
- .on('end', resolve)
128
- .on('error', reject)
129
- })
130
- }
1
+
2
+ import getBowerRegistryConfig from '../getBowerRegistryConfig.js'
3
+ import fs from 'fs-extra'
4
+ import path from 'path'
5
+ import bower from 'bower'
6
+ import chalk from 'chalk'
7
+ import inquirer from 'inquirer'
8
+ import { readValidateJSON } from '../../util/JSONReadValidate.js'
9
+ import Plugin from '../Plugin.js'
10
+ import semver from 'semver'
11
+ import { ADAPT_ALLOW_PRERELEASE } from '../../util/constants.js'
12
+ const semverOptions = { includePrerelease: ADAPT_ALLOW_PRERELEASE }
13
+
14
+ export default async function register ({
15
+ logger,
16
+ cwd = process.cwd()
17
+ } = {}) {
18
+ cwd = path.resolve(process.cwd(), cwd)
19
+ const BOWER_REGISTRY_CONFIG = getBowerRegistryConfig({ cwd })
20
+ logger?.warn('Using registry at', BOWER_REGISTRY_CONFIG.register)
21
+ try {
22
+ const bowerJSONPath = path.join(cwd, 'bower.json')
23
+ const hasBowerJSON = fs.existsSync(bowerJSONPath)
24
+
25
+ const bowerJSON = {
26
+ name: undefined,
27
+ repository: undefined,
28
+ framework: undefined,
29
+ ...(hasBowerJSON ? await readValidateJSON(bowerJSONPath) : {})
30
+ }
31
+ const properties = await confirm(bowerJSON)
32
+ hasBowerJSON && await fs.writeJSON(bowerJSONPath, properties, { spaces: 2, replacer: null })
33
+
34
+ // given a package name, create two Plugin representations
35
+ // if supplied name is adapt-contrib-myPackageName do a check against this name only
36
+ // if suppled name is adapt-myPackageName check against this name and adapt-contrib-myPackageName
37
+ // becase we don't want to allow adapt-myPackageName if adapt-contrib-myPackageName exists
38
+ const plugin = new Plugin({ name: properties.name, logger })
39
+ const contribPlugin = new Plugin({ name: properties.name, isContrib: true, logger })
40
+ const contribExists = await exists(BOWER_REGISTRY_CONFIG, contribPlugin)
41
+ const pluginExists = await exists(BOWER_REGISTRY_CONFIG, plugin)
42
+
43
+ if (contribExists || pluginExists) {
44
+ logger?.warn(plugin.toString(), 'has been previously registered. Plugin names must be unique. Try again with a different name.')
45
+ return
46
+ }
47
+
48
+ const result = await registerWithBowerRepo(BOWER_REGISTRY_CONFIG, plugin, properties.repository)
49
+ if (!result) throw new Error('The plugin was unable to register.')
50
+ logger?.log(chalk.green(plugin.packageName), 'has been registered successfully.')
51
+ } catch (err) {
52
+ logger?.error(err)
53
+ }
54
+ }
55
+
56
+ async function confirm (properties) {
57
+ const plugin = new Plugin({ name: properties.name })
58
+ const schema = [
59
+ {
60
+ name: 'name',
61
+ message: chalk.cyan('name'),
62
+ validate: v => {
63
+ return /^adapt-[\w|-]+?$/.test(v) ||
64
+ 'Name must prefixed with \'adapt\' and each word separated with a hyphen(-)'
65
+ },
66
+ type: 'input',
67
+ default: plugin.toString() || 'not specified'
68
+ },
69
+ {
70
+ name: 'repositoryUrl',
71
+ message: chalk.cyan('repository URL'),
72
+ validate: v => {
73
+ return /https:\/\/([\w.@:/\-~]+)(\.git)(\/)?/.test(v) ||
74
+ 'Please provide a repository URL of the form https://<domain><path>.git'
75
+ },
76
+ type: 'input',
77
+ default: properties.repository ? properties.repository.url : undefined
78
+ },
79
+ {
80
+ name: 'framework',
81
+ message: chalk.cyan('framework'),
82
+ validate: v => {
83
+ return semver.validRange(v, semverOptions) !== null ||
84
+ 'Please provide a valid semver (see https://semver.org/)'
85
+ },
86
+ type: 'input',
87
+ default: properties.framework || '>=5.15'
88
+ },
89
+ {
90
+ name: 'ready',
91
+ message: chalk.cyan('Register now?'),
92
+ type: 'confirm',
93
+ default: true
94
+ }
95
+ ]
96
+ const confirmation = await inquirer.prompt(schema)
97
+ if (!confirmation.ready) throw new Error('Aborted. Nothing has been registered.')
98
+ properties.name = confirmation.name
99
+ properties.repository = { type: 'git', url: confirmation.repositoryUrl }
100
+ properties.framework = confirmation.framework
101
+ return properties
102
+ }
103
+
104
+ /**
105
+ * @param {Plugin} plugin
106
+ * @returns {boolean}
107
+ */
108
+ async function exists (BOWER_REGISTRY_CONFIG, plugin) {
109
+ const pluginName = plugin.toString().toLowerCase()
110
+ return new Promise((resolve, reject) => {
111
+ bower.commands.search(pluginName, {
112
+ registry: BOWER_REGISTRY_CONFIG.register
113
+ })
114
+ .on('end', result => {
115
+ const matches = result.filter(({ name }) => name.toLowerCase() === pluginName)
116
+ resolve(Boolean(matches.length))
117
+ })
118
+ .on('error', reject)
119
+ })
120
+ }
121
+
122
+ async function registerWithBowerRepo (BOWER_REGISTRY_CONFIG, plugin, repository) {
123
+ return new Promise((resolve, reject) => {
124
+ bower.commands.register(plugin.toString(), repository.url || repository, {
125
+ registry: BOWER_REGISTRY_CONFIG
126
+ })
127
+ .on('end', resolve)
128
+ .on('error', reject)
129
+ })
130
+ }
@@ -1,101 +1,101 @@
1
- import getBowerRegistryConfig from '../getBowerRegistryConfig.js'
2
- import authenticate from './autenticate.js'
3
- import bower from 'bower'
4
- import chalk from 'chalk'
5
- import inquirer from 'inquirer'
6
- import request from 'request'
7
- import path from 'path'
8
- import Plugin from '../Plugin.js'
9
-
10
- export default async function rename ({
11
- logger,
12
- oldName,
13
- newName,
14
- cwd = process.cwd()
15
- } = {}) {
16
- cwd = path.resolve(process.cwd(), cwd)
17
- const BOWER_REGISTRY_CONFIG = getBowerRegistryConfig({ cwd })
18
- if (!oldName || !newName) {
19
- logger?.error('You must call rename with the following arguments: <plugin name> <new plugin name>')
20
- return
21
- }
22
- // use Plugin to standardise name
23
- newName = new Plugin({ name: newName, logger }).packageName
24
- oldName = new Plugin({ name: oldName, logger }).packageName
25
- logger?.warn('Using registry at', BOWER_REGISTRY_CONFIG.register)
26
- logger?.warn(`Plugin will be renamed from ${oldName} to ${newName}`)
27
- try {
28
- const oldExists = await exists(BOWER_REGISTRY_CONFIG, oldName)
29
- if (!oldExists) throw new Error(`Plugin "${oldName}" does not exist`)
30
- const newExists = await exists(BOWER_REGISTRY_CONFIG, newName)
31
- if (newExists) throw new Error(`Name "${newName}" already exists`)
32
- const { username, token, type } = await authenticate({ pluginName: oldName })
33
- logger?.log(`${username} authenticated as ${type}`)
34
- await confirm()
35
- await renameInBowerRepo({
36
- username,
37
- token,
38
- oldName,
39
- newName,
40
- BOWER_REGISTRY_CONFIG
41
- })
42
- logger?.log(chalk.green('The plugin was successfully renamed.'))
43
- } catch (err) {
44
- logger?.error(err)
45
- logger?.error('The plugin was not renamed.')
46
- }
47
- }
48
-
49
- async function confirm () {
50
- const schema = [
51
- {
52
- name: 'ready',
53
- message: chalk.cyan('Confirm rename now?'),
54
- type: 'confirm',
55
- default: true
56
- }
57
- ]
58
- const confirmation = await inquirer.prompt(schema)
59
- if (!confirmation.ready) throw new Error('Aborted. Nothing has been renamed.')
60
- }
61
-
62
- async function renameInBowerRepo ({
63
- username,
64
- token,
65
- oldName,
66
- newName,
67
- BOWER_REGISTRY_CONFIG
68
- }) {
69
- const path = 'packages/rename/' + username + '/' + oldName + '/' + newName
70
- const query = '?access_token=' + token
71
- return new Promise((resolve, reject) => {
72
- request({
73
- url: BOWER_REGISTRY_CONFIG.register + path + query,
74
- method: 'GET',
75
- headers: { 'User-Agent': 'adapt-cli' },
76
- followRedirect: false
77
- }, (err, res) => {
78
- if (err) return reject(err)
79
- if (res.statusCode !== 201) reject(new Error(`The server responded with ${res.statusCode}`))
80
- resolve()
81
- })
82
- })
83
- }
84
-
85
- /**
86
- * @param {Plugin} plugin
87
- * @returns {boolean}
88
- */
89
- async function exists (BOWER_REGISTRY_CONFIG, plugin) {
90
- const pluginName = plugin.toString().toLowerCase()
91
- return new Promise((resolve, reject) => {
92
- bower.commands.search(pluginName, {
93
- registry: BOWER_REGISTRY_CONFIG.register
94
- })
95
- .on('end', result => {
96
- const matches = result.filter(({ name }) => name.toLowerCase() === pluginName)
97
- resolve(Boolean(matches.length))
98
- })
99
- .on('error', reject)
100
- })
101
- }
1
+ import getBowerRegistryConfig from '../getBowerRegistryConfig.js'
2
+ import authenticate from './autenticate.js'
3
+ import bower from 'bower'
4
+ import chalk from 'chalk'
5
+ import inquirer from 'inquirer'
6
+ import request from 'request'
7
+ import path from 'path'
8
+ import Plugin from '../Plugin.js'
9
+
10
+ export default async function rename ({
11
+ logger,
12
+ oldName,
13
+ newName,
14
+ cwd = process.cwd()
15
+ } = {}) {
16
+ cwd = path.resolve(process.cwd(), cwd)
17
+ const BOWER_REGISTRY_CONFIG = getBowerRegistryConfig({ cwd })
18
+ if (!oldName || !newName) {
19
+ logger?.error('You must call rename with the following arguments: <plugin name> <new plugin name>')
20
+ return
21
+ }
22
+ // use Plugin to standardise name
23
+ newName = new Plugin({ name: newName, logger }).packageName
24
+ oldName = new Plugin({ name: oldName, logger }).packageName
25
+ logger?.warn('Using registry at', BOWER_REGISTRY_CONFIG.register)
26
+ logger?.warn(`Plugin will be renamed from ${oldName} to ${newName}`)
27
+ try {
28
+ const oldExists = await exists(BOWER_REGISTRY_CONFIG, oldName)
29
+ if (!oldExists) throw new Error(`Plugin "${oldName}" does not exist`)
30
+ const newExists = await exists(BOWER_REGISTRY_CONFIG, newName)
31
+ if (newExists) throw new Error(`Name "${newName}" already exists`)
32
+ const { username, token, type } = await authenticate({ pluginName: oldName })
33
+ logger?.log(`${username} authenticated as ${type}`)
34
+ await confirm()
35
+ await renameInBowerRepo({
36
+ username,
37
+ token,
38
+ oldName,
39
+ newName,
40
+ BOWER_REGISTRY_CONFIG
41
+ })
42
+ logger?.log(chalk.green('The plugin was successfully renamed.'))
43
+ } catch (err) {
44
+ logger?.error(err)
45
+ logger?.error('The plugin was not renamed.')
46
+ }
47
+ }
48
+
49
+ async function confirm () {
50
+ const schema = [
51
+ {
52
+ name: 'ready',
53
+ message: chalk.cyan('Confirm rename now?'),
54
+ type: 'confirm',
55
+ default: true
56
+ }
57
+ ]
58
+ const confirmation = await inquirer.prompt(schema)
59
+ if (!confirmation.ready) throw new Error('Aborted. Nothing has been renamed.')
60
+ }
61
+
62
+ async function renameInBowerRepo ({
63
+ username,
64
+ token,
65
+ oldName,
66
+ newName,
67
+ BOWER_REGISTRY_CONFIG
68
+ }) {
69
+ const path = 'packages/rename/' + username + '/' + oldName + '/' + newName
70
+ const query = '?access_token=' + token
71
+ return new Promise((resolve, reject) => {
72
+ request({
73
+ url: BOWER_REGISTRY_CONFIG.register + path + query,
74
+ method: 'GET',
75
+ headers: { 'User-Agent': 'adapt-cli' },
76
+ followRedirect: false
77
+ }, (err, res) => {
78
+ if (err) return reject(err)
79
+ if (res.statusCode !== 201) reject(new Error(`The server responded with ${res.statusCode}`))
80
+ resolve()
81
+ })
82
+ })
83
+ }
84
+
85
+ /**
86
+ * @param {Plugin} plugin
87
+ * @returns {boolean}
88
+ */
89
+ async function exists (BOWER_REGISTRY_CONFIG, plugin) {
90
+ const pluginName = plugin.toString().toLowerCase()
91
+ return new Promise((resolve, reject) => {
92
+ bower.commands.search(pluginName, {
93
+ registry: BOWER_REGISTRY_CONFIG.register
94
+ })
95
+ .on('end', result => {
96
+ const matches = result.filter(({ name }) => name.toLowerCase() === pluginName)
97
+ resolve(Boolean(matches.length))
98
+ })
99
+ .on('error', reject)
100
+ })
101
+ }
@@ -1,8 +1,8 @@
1
- import Project from '../Project.js'
2
- import path from 'path'
3
-
4
- export default async function schemas ({ cwd = process.cwd() } = {}) {
5
- cwd = path.resolve(process.cwd(), cwd)
6
- const project = new Project({ cwd })
7
- return await project.getSchemaPaths({ cwd })
8
- }
1
+ import Project from '../Project.js'
2
+ import path from 'path'
3
+
4
+ export default async function schemas ({ cwd = process.cwd() } = {}) {
5
+ cwd = path.resolve(process.cwd(), cwd)
6
+ const project = new Project({ cwd })
7
+ return await project.getSchemaPaths({ cwd })
8
+ }