adapt-cli 2.1.13 → 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 (134) hide show
  1. package/.bowerrc +2 -2
  2. package/.eslintignore +1 -0
  3. package/.eslintrc.json +14 -0
  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 -0
  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 -0
  15. package/json/help-create.json +12 -11
  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 -0
  28. package/lib/cli.js +69 -52
  29. package/lib/commands/authenticate.js +18 -0
  30. package/lib/commands/create/component.js +64 -81
  31. package/lib/commands/create/course.js +26 -81
  32. package/lib/commands/create/question.js +18 -0
  33. package/lib/commands/create.js +94 -90
  34. package/lib/commands/devinstall.js +35 -97
  35. package/lib/commands/help.js +31 -52
  36. package/lib/commands/install.js +16 -907
  37. package/lib/commands/ls.js +9 -24
  38. package/lib/commands/register.js +11 -196
  39. package/lib/commands/rename.js +14 -129
  40. package/lib/commands/search.js +11 -29
  41. package/lib/commands/uninstall.js +9 -136
  42. package/lib/commands/unregister.js +12 -96
  43. package/lib/commands/update.js +12 -867
  44. package/lib/commands/version.js +13 -15
  45. package/lib/integration/AdaptFramework/build.js +42 -0
  46. package/lib/integration/AdaptFramework/clone.js +27 -0
  47. package/lib/integration/AdaptFramework/deleteSrcCore.js +9 -0
  48. package/lib/integration/AdaptFramework/deleteSrcCourse.js +9 -0
  49. package/lib/integration/AdaptFramework/download.js +21 -0
  50. package/lib/integration/AdaptFramework/erase.js +34 -0
  51. package/lib/integration/AdaptFramework/getLatestVersion.js +79 -0
  52. package/lib/integration/AdaptFramework/npmInstall.js +21 -0
  53. package/lib/integration/AdaptFramework.js +19 -0
  54. package/lib/integration/Plugin.js +404 -0
  55. package/lib/integration/PluginManagement/autenticate.js +56 -0
  56. package/lib/integration/PluginManagement/install.js +224 -0
  57. package/lib/integration/PluginManagement/print.js +52 -0
  58. package/lib/integration/PluginManagement/register.js +130 -0
  59. package/lib/integration/PluginManagement/rename.js +101 -0
  60. package/lib/integration/PluginManagement/schemas.js +8 -0
  61. package/lib/integration/PluginManagement/search.js +46 -0
  62. package/lib/integration/PluginManagement/uninstall.js +141 -0
  63. package/lib/integration/PluginManagement/unregister.js +101 -0
  64. package/lib/integration/PluginManagement/update.js +224 -0
  65. package/lib/integration/PluginManagement.js +21 -0
  66. package/lib/integration/Project.js +146 -0
  67. package/lib/integration/Target.js +299 -0
  68. package/lib/integration/getBowerRegistryConfig.js +34 -0
  69. package/lib/logger.js +28 -0
  70. package/lib/util/JSONReadValidate.js +34 -0
  71. package/lib/util/constants.js +38 -0
  72. package/lib/util/createPromptTask.js +7 -0
  73. package/lib/util/download.js +45 -0
  74. package/lib/util/errors.js +58 -0
  75. package/lib/util/extract.js +24 -0
  76. package/lib/util/getDirNameFromImportMeta.js +6 -0
  77. package/lib/util/promises.js +36 -0
  78. package/package.json +74 -49
  79. package/TESTING.md +0 -25
  80. package/bin/adapt +0 -3
  81. package/gruntfile.js +0 -18
  82. package/lib/AdaptConsoleApplication.js +0 -19
  83. package/lib/CommandParser.js +0 -19
  84. package/lib/CommandTranslator.js +0 -16
  85. package/lib/ConsoleRenderer.js +0 -10
  86. package/lib/Constants.js +0 -68
  87. package/lib/JsonLoader.js +0 -40
  88. package/lib/JsonWriter.js +0 -21
  89. package/lib/PackageMeta.js +0 -41
  90. package/lib/Plugin.js +0 -53
  91. package/lib/PluginTypeResolver.js +0 -47
  92. package/lib/Project.js +0 -89
  93. package/lib/RendererHelpers.js +0 -41
  94. package/lib/RepositoryDownloader.js +0 -64
  95. package/lib/Slug.js +0 -5
  96. package/lib/VersionChecker.js +0 -7
  97. package/lib/commands/create/index.js +0 -6
  98. package/lib/commands/index.js +0 -16
  99. package/lib/commands/install/InstallLog.js +0 -32
  100. package/lib/commands/install/InstallTarget.js +0 -259
  101. package/lib/commands/install/extend.js +0 -31
  102. package/lib/download.js +0 -101
  103. package/lib/errors.js +0 -58
  104. package/lib/promise/authenticate.js +0 -58
  105. package/lib/promise/build.js +0 -20
  106. package/lib/promise/cloneInstall.js +0 -35
  107. package/lib/promise/confirmBuild.js +0 -6
  108. package/lib/promise/exec.js +0 -39
  109. package/lib/promise/getRepository.js +0 -26
  110. package/lib/promise/highest.js +0 -109
  111. package/lib/promise/install.js +0 -31
  112. package/lib/promise/installAdaptDependencies.js +0 -30
  113. package/lib/promise/installNodeDependencies.js +0 -28
  114. package/lib/promise/removeTemporaryDownload.js +0 -8
  115. package/lib/promise/replaceTextContent.js +0 -10
  116. package/lib/promise/uninstallPackage.js +0 -15
  117. package/lib/promise/update.js +0 -33
  118. package/lib/promise/util.js +0 -16
  119. package/test/fixtures/adapt-with-plugins.json +0 -6
  120. package/test/specs/command_translation_concerns.js +0 -13
  121. package/test/specs/create_command_concerns.js +0 -22
  122. package/test/specs/create_concerns.js +0 -30
  123. package/test/specs/install_concerns.js +0 -31
  124. package/test/specs/installing_compatible_plugins_concerns.js +0 -126
  125. package/test/specs/installing_incompatible_plugins_concerns.js +0 -103
  126. package/test/specs/ls_concerns.js +0 -28
  127. package/test/specs/plugin_name_concerns.js +0 -82
  128. package/test/specs/project_concerns.js +0 -128
  129. package/test/specs/registration_concerns.js +0 -31
  130. package/test/specs/repository_downloader_concerns.js +0 -55
  131. package/test/specs/search_concerns.js +0 -30
  132. package/test/specs/type_resolution_concerns.js +0 -71
  133. package/test/specs/uninstall_command_concerns.js +0 -64
  134. package/test/specs/uninstall_concerns.js +0 -31
@@ -1,24 +1,9 @@
1
- module.exports = function (dependencies) {
2
-
3
- var chalk = dependencies.chalk || require('chalk'),
4
- Project = dependencies.Project || require('../Project'),
5
- Constants = dependencies.Constants || require('../Constants'),
6
- RendererHelpers = dependencies.RendererHelpers || require('../RendererHelpers');
7
-
8
- return {
9
- ls: function(renderer) {
10
- var project = new Project(Constants.DefaultProjectManifestPath),
11
- done = arguments[arguments.length -1];
12
-
13
- if(project.isProjectContainsManifestFile()) {
14
- project.plugins.forEach(function (p) {
15
- renderer.log(chalk.cyan(p.name), p.version);
16
- });
17
- done();
18
- } else {
19
- RendererHelpers.reportInvalidFrameworkDirectory(renderer, done)(true);
20
- }
21
- }
22
- };
23
-
24
- };
1
+ import chalk from 'chalk'
2
+ import Project from '../integration/Project.js'
3
+
4
+ export default async function ls (logger) {
5
+ const project = new Project({ logger })
6
+ project.tryThrowInvalidPath()
7
+ const installTargets = await project.getInstallTargets()
8
+ installTargets.forEach(p => logger?.log(`${chalk.cyan(p.name || p.sourcePath)} ${p.sourcePath || p.requestedVersion}`))
9
+ }
@@ -1,196 +1,11 @@
1
- var bower = require('bower'),
2
- chalk = require('chalk'),
3
- inquirer = require('inquirer'),
4
- path = require('path'),
5
- _ = require('lodash'),
6
- Q = require('q'),
7
- Constants = require('../Constants'),
8
- JsonLoader = require('../JsonLoader'),
9
- JsonWriter = require('../JsonWriter'),
10
- Project = require('../Project'),
11
- Plugin = require('../Plugin'),
12
- semver = require('semver');
13
-
14
- module.exports = {
15
- register: function (renderer) {
16
- var done = arguments[arguments.length-1] || function () {};
17
-
18
- //renderer.log(chalk.yellow('This will publish this plugin to', Constants.Registry));
19
-
20
- loadPluginProperties('./bower.json', {
21
- name: undefined,
22
- repository: undefined,
23
- framework: undefined
24
- })
25
- .then(confirm)
26
- .then(function (properties) {
27
- savePluginProperties('./bower.json', properties);
28
- return properties;
29
- })
30
- .then(function (properties) {
31
- // given a package name, create two Plugin representations
32
- // if supplied name is adapt-contrib-myPackageName do a check against this name only
33
- // if suppled name is adapt-myPackageName check against this name and adapt-contrib-myPackageName
34
- // becase we don't want to allow adapt-myPackageName if adapt-contrib-myPackageName exists
35
- var plugin = new Plugin(properties.name),
36
- contribPlugin = new Plugin(properties.name, true),
37
- searches = [exists(contribPlugin)];
38
-
39
- if(!plugin.isContrib) {
40
- searches.push(exists(plugin));
41
- }
42
-
43
- return Q.all(searches)
44
- .spread(function (contribExists, pluginExists) {
45
- if(contribExists) {
46
- return reportExistence(contribPlugin, renderer);
47
- }
48
- if(pluginExists) {
49
- return reportExistence(plugin, renderer);
50
- }
51
- return register(plugin, properties.repository);
52
- });
53
- })
54
- .then(function (registered) {
55
- if(!registered.result) throw new Error('The plugin was unable to register.');
56
- renderer.log(chalk.green(registered.plugin.packageName), 'has been registered successfully.');
57
- done();
58
- })
59
- .fail(function (err) {
60
- renderer.log(chalk.red(err));
61
- done(err);
62
- })
63
- .done();
64
- }
65
- };
66
-
67
- function loadPluginProperties(path, defaults) {
68
- var deferred = Q.defer();
69
-
70
- path = path || './bower.json';
71
-
72
- if(!JsonLoader.existsSync(path)) {
73
- deferred.reject(new Error('bower.json is not in the current working directory. Plugins must be a valid bower package.'));
74
- }
75
- JsonLoader.readJSON(path, function (error, data) {
76
- if(error) {
77
- deferred.reject(new Error(error));
78
- } else {
79
- deferred.resolve(_.extend({}, defaults, data));
80
- }
81
- });
82
-
83
- return deferred.promise;
84
- }
85
-
86
- function savePluginProperties(path, values) {
87
- var deferred = Q.defer();
88
-
89
- path = path || './bower.json';
90
-
91
- if(!JsonWriter.existsSync(path)) {
92
- deferred.reject(new Error('bower.json is not in the current working directory. Plugins must be a valid bower package.'));
93
- }
94
- JsonWriter.writeJSON(path, values, function () {
95
- deferred.resolve(true);
96
- });
97
-
98
- return deferred.promise;
99
- }
100
-
101
- function confirm(properties) {
102
- var deferred = Q.defer();
103
- var plugin = new Plugin(properties.name),
104
- schema = [
105
- {
106
- name: 'name',
107
- message: chalk.cyan('name'),
108
- validate: v => {
109
- return /^adapt-[\w|-]+?$/.test(v) ||
110
- `Name must prefixed with 'adapt' and each word separated with a hyphen(-)`;
111
- },
112
- type: 'input',
113
- default: plugin.toString() || 'not specified'
114
- },
115
- {
116
- name: 'repositoryUrl',
117
- message: chalk.cyan('repository URL'),
118
- validate: v => {
119
- return /git:\/\/([\w\.@\:/\-~]+)(\.git)(\/)?/.test(v) ||
120
- 'Please provide a repository URL of the form git://<domain><path>.git';
121
- },
122
- type: 'input',
123
- default: properties.repository ? properties.repository.url : undefined
124
- },
125
- {
126
- name: 'framework',
127
- message: chalk.cyan('framework'),
128
- validate: v => {
129
- return semver.validRange(v) !== null ||
130
- 'Please provide a valid semver (see https://semver.org/)';
131
- },
132
- type: 'input',
133
- default: properties.framework || '~2.0.0'
134
- },
135
- {
136
- name: 'ready',
137
- message: chalk.cyan('Register now?'),
138
- type: 'confirm',
139
- default: true
140
- }
141
- ];
142
- inquirer.prompt(schema).then(confirmation => {
143
- if(!confirmation.ready) deferred.reject(new Error('Aborted. Nothing has been registered.'));
144
-
145
- properties.name = confirmation.name;
146
- properties.repository = {type:'git', url:confirmation.repositoryUrl};
147
- properties.framework = confirmation.framework;
148
-
149
- deferred.resolve(properties);
150
- }).catch(err => deferred.reject(err));
151
- return deferred.promise;
152
- }
153
-
154
- function register(plugin, repository) {
155
- var deferred = Q.defer();
156
-
157
- bower.commands.register(plugin.toString(), repository.url || repository, { registry: Constants.getRegistry() })
158
- .on('end', function(result) {
159
- deferred.resolve({ result: result, plugin: plugin });
160
- })
161
- .on('error', function (err) {
162
- deferred.reject(err);
163
- });
164
- return deferred.promise;
165
- }
166
-
167
- function exists(plugin) {
168
- var deferred = Q.defer();
169
-
170
- bower.commands.search(plugin.toString(), { registry: Constants.getRegistry() })
171
- .on('end', function(result) {
172
- var matches = result.filter(exactMatch(plugin.toString()));
173
- deferred.resolve(!!matches.length);
174
- })
175
- .on('error', function (err) {
176
- deferred.reject(err);
177
- });
178
- return deferred.promise;
179
- }
180
-
181
- function exactMatch(pattern) {
182
- return function (item) {
183
- if (typeof pattern === 'string') {
184
- if (pattern.toLowerCase() === item.name.toLowerCase()) {
185
- return true;
186
- }
187
- return false
188
- }
189
- var regexp = new RegExp(pattern, 'i');
190
- return regexp.test(item.name);
191
- };
192
- }
193
-
194
- function reportExistence(plugin, renderer) {
195
- renderer.log(chalk.yellow(plugin.toString()), chalk.cyan('has been previously registered. Plugin names must be unique. Try again with a different name.'));
196
- }
1
+ import { register as pluginRegister } from '../integration/PluginManagement.js'
2
+
3
+ export default async function register (logger, ...args) {
4
+ // strip flags
5
+ args = args.filter(arg => !String(arg).startsWith('--'))
6
+ return await pluginRegister({
7
+ logger,
8
+ cwd: process.cwd(),
9
+ args
10
+ })
11
+ }
@@ -1,129 +1,14 @@
1
- var bower = require('bower'),
2
- chalk = require('chalk'),
3
- inquirer = require('inquirer'),
4
- _ = require('lodash'),
5
- Q = require('q'),
6
- request = require('request'),
7
- Constants = require('../Constants'),
8
- Plugin = require('../Plugin'),
9
- authenticate = require('../promise/authenticate'),
10
- log;
11
-
12
- module.exports = {
13
- rename: function (renderer) {
14
- log = renderer.log;
15
-
16
- var done = arguments[arguments.length-1] || function () {};
17
-
18
- if (arguments.length >= 4) {
19
- var params = {
20
- oldName:arguments[1],
21
- newName:arguments[2]
22
- };
23
-
24
- // use Plugin to standardise name
25
- params.newName = new Plugin(params.newName).packageName;
26
-
27
- log(chalk.yellow('Using registry at', Constants.getRegistry()));
28
- log(chalk.yellow('Plugin will be renamed to', params.newName));
29
-
30
- Q(params)
31
- .then(checkPluginNameExists)
32
- .then(checkNewPluginNameDoesNotExist)
33
- .then(authenticate)
34
- .then(confirm)
35
- .then(rename)
36
- .then(function() {
37
- log(chalk.green('The plugin was successfully renamed.'));
38
- done();
39
- })
40
- .catch(function (err) {
41
- log(chalk.red(err));
42
- log('The plugin was not renamed.');
43
- done(err);
44
- })
45
- .done();
46
-
47
- } else {
48
- log(chalk.red('You must call rename with the following arguments: <plugin name> <new plugin name>'));
49
- done();
50
- }
51
- }
52
- };
53
-
54
- function checkPluginNameExists(params) {
55
- return exists(params.oldName).then(function(exists) {
56
- return exists ? Q.resolve(params) : Q.reject('Plugin "'+params.oldName+'" does not exist');
57
- });
58
- }
59
-
60
- function checkNewPluginNameDoesNotExist(params) {
61
- return exists(params.newName).then(function(exists) {
62
- return exists ? Q.reject('Name "'+params.newName+'" already exists') : Q.resolve(params);
63
- });
64
- }
65
-
66
- function confirm(params) {
67
- var deferred = Q.defer();
68
- var schema = [
69
- {
70
- name: 'ready',
71
- message: chalk.cyan('Confirm rename now?'),
72
- type: 'confirm',
73
- default: true
74
- }
75
- ];
76
- inquirer.prompt(schema).then(confirmation => {
77
- if(!confirmation.ready) deferred.reject(new Error('Aborted. Nothing has been renamed.'));
78
- deferred.resolve(params);
79
- }).catch(err => deferred.reject(err));
80
- return deferred.promise;
81
- }
82
-
83
- function rename(params) {
84
- var deferred = Q.defer();
85
- var path = 'packages/rename/'+params.username+'/'+params.oldName+'/'+params.newName;
86
- var query = '?access_token='+params.token;
87
-
88
- request({
89
- url: Constants.getRegistry()+'/'+path+query,
90
- method:'GET',
91
- headers: {'User-Agent':'adapt-cli'},
92
- followRedirect:false
93
- }, function(err, res, body) {
94
- if (err) {
95
- deferred.reject(err);
96
- } else {
97
- res.statusCode==201 ? deferred.resolve(params) : deferred.reject("The server responded with "+res.statusCode);
98
- }
99
- });
100
-
101
- return deferred.promise;
102
- }
103
-
104
- function exists(plugin) {
105
- var deferred = Q.defer();
106
-
107
- bower.commands.search(plugin.toString(), { registry: Constants.getRegistry() })
108
- .on('end', function(result) {
109
- var matches = result.filter(exactMatch(plugin.toString()));
110
- deferred.resolve(!!matches.length);
111
- })
112
- .on('error', function (err) {
113
- deferred.reject(err);
114
- });
115
- return deferred.promise;
116
- }
117
-
118
- function exactMatch(pattern) {
119
- return function (item) {
120
- if (typeof pattern === 'string') {
121
- if (pattern.toLowerCase() === item.name.toLowerCase()) {
122
- return true;
123
- }
124
- return false
125
- }
126
- var regexp = new RegExp(pattern, 'i');
127
- return regexp.test(item.name);
128
- };
129
- }
1
+ import { rename as pluginRename } from '../integration/PluginManagement.js'
2
+
3
+ export default async function rename (logger, ...args) {
4
+ /** strip flags */
5
+ args = args.filter(arg => !String(arg).startsWith('--'))
6
+ const oldName = args[0]
7
+ const newName = args[1]
8
+ await pluginRename({
9
+ logger,
10
+ cwd: process.cwd(),
11
+ oldName,
12
+ newName
13
+ })
14
+ }
@@ -1,29 +1,11 @@
1
- var bower = require('bower'),
2
- chalk = require('chalk'),
3
- Constants = require('../Constants'),
4
- Plugin = require('../Plugin');
5
-
6
-
7
- module.exports = {
8
- search: function(renderer) {
9
- var searchTerm = arguments.length >= 3 ? arguments[1] : '',
10
- done = arguments[arguments.length -1] || function () {};
11
-
12
- var plugin = new Plugin(searchTerm);
13
-
14
- bower.commands.search(searchTerm, { registry: Constants.getRegistry() })
15
- .on('end', function(results) {
16
- if(!results.length) {
17
- renderer.log(chalk.yellow('no plugins found', plugin.toString()));
18
- }
19
- results.forEach(function (result) {
20
- renderer.log(chalk.cyan(result.name) + ' ' + result.url);
21
- });
22
- done();
23
- })
24
- .on('error', function (err) {
25
- renderer.log(chalk.red("Oh dear, something went wrong. I'm terribly sorry."), err);
26
- done(err);
27
- });
28
- }
29
- };
1
+ import { search as pluginsSearch } from '../integration/PluginManagement.js'
2
+
3
+ export default async function search (logger, ...args) {
4
+ /** strip flags */
5
+ args = args.filter(arg => !String(arg).startsWith('--'))
6
+ const searchTerm = (args[0] || '')
7
+ await pluginsSearch({
8
+ logger,
9
+ searchTerm
10
+ })
11
+ }
@@ -1,136 +1,9 @@
1
- var chalk = require('chalk'),
2
- fs = require('fs'),
3
- path = require('path'),
4
- rimraf = require('rimraf'),
5
- Q = require('q'),
6
- Constants = require('../Constants'),
7
- PluginTypeResolver = require('../PluginTypeResolver'),
8
- PackageMeta = require('../PackageMeta'),
9
- Project = require('../Project'),
10
- Plugin = require('../Plugin'),
11
- RendererHelpers = require('../RendererHelpers'),
12
- uninstallPackage = require('../promise/uninstallPackage'),
13
- Errors = require('../errors');
14
-
15
- module.exports = {
16
- apiuninstall:function(pluginName, cwd) {
17
- Constants.setCwd(cwd);
18
-
19
- var project = new Project(Constants.DefaultProjectManifestPath, Constants.DefaultProjectFrameworkPath);
20
-
21
- if(!project.isProjectContainsManifestFile()) {
22
- return Q.reject(Errors.ERROR_COURSE_DIR);
23
- }
24
-
25
- var plugin = Plugin.parse(pluginName);
26
- var deferred = Q.defer();
27
-
28
- PackageMeta.getKeywords(plugin, { registry: Constants.getRegistry() })
29
- .then(function (keywords) {
30
- var resolver = new PluginTypeResolver(),
31
- pluginType = resolver.resolve(keywords);
32
-
33
- return uninstallPackage(plugin, {
34
- directory: path.join('src', pluginType.belongsTo),
35
- cwd:Constants.cwd
36
- });
37
- })
38
- .then(function () {
39
- project.remove(plugin);
40
- })
41
- .then(function () {
42
- deferred.resolve(pluginName);
43
- })
44
- .fail(function() {
45
- // will fail if plugin has not been installed by Bower (i.e. the .bower.json manifest is missing)
46
- // so just try and remove the directory (this is basically what Bower does anyway)
47
-
48
- var removePath;
49
-
50
- ['components', 'extensions', 'menu', 'theme'].forEach(function(pluginType) {
51
- var pluginPath = path.join(Constants.cwd, 'src', pluginType, plugin.packageName);
52
-
53
- if (fs.existsSync(pluginPath)) {
54
- removePath = pluginPath;
55
- }
56
- });
57
-
58
- if (removePath) {
59
- rimraf(removePath, function() {
60
- if (fs.existsSync(removePath)) {
61
- deferred.reject(Errors.ERROR_UNINSTALL);
62
- } else {
63
- project.remove(plugin);
64
- deferred.resolve(pluginName);
65
- }
66
- });
67
- } else {
68
- deferred.reject(Errors.ERROR_NOT_FOUND);
69
- }
70
- });
71
-
72
- return deferred.promise;
73
- },
74
- uninstall: function (renderer) {
75
-
76
- var packageName = arguments.length >= 3 ? arguments[1] : null,
77
- done = arguments[arguments.length - 1];
78
-
79
- if(!packageName) {
80
- return renderer.log(chalk.red('Please specify a plugin to uninstall.'));
81
- }
82
-
83
- var project = new Project(Constants.DefaultProjectManifestPath);
84
- if (!project.isProjectContainsManifestFile()) {
85
- return RendererHelpers.reportInvalidFrameworkDirectory(renderer, done)(true);
86
- }
87
-
88
- var plugin = Plugin.parse(packageName);
89
-
90
- PackageMeta.getKeywords(plugin, { registry: Constants.getRegistry() })
91
- .then(function (keywords) {
92
- var resolver = new PluginTypeResolver(),
93
- pluginType = resolver.resolve(keywords);
94
-
95
- renderer.log(chalk.cyan(plugin.packageName), 'found.', 'Uninstalling', pluginType.typename, '...');
96
- return uninstallPackage(plugin, {
97
- directory: path.join('src', pluginType.belongsTo),
98
- cwd:Constants.cwd
99
- });
100
- })
101
- .then(function () {
102
- project.remove(plugin);
103
- })
104
- .then(function () {
105
- done();
106
- })
107
- .fail(function() {
108
- // will fail if plugin has not been installed by Bower (i.e. the .bower.json manifest is missing)
109
- // so just try and remove the directory (this is basically what Bower does anyway)
110
-
111
- var removePath;
112
-
113
- ['components', 'extensions', 'menu', 'theme'].forEach(function(pluginType) {
114
- var pluginPath = path.join(Constants.cwd, 'src', pluginType, plugin.packageName);
115
-
116
- if (fs.existsSync(pluginPath)) {
117
- removePath = pluginPath;
118
- }
119
- });
120
-
121
- if (removePath) {
122
- rimraf(removePath, function() {
123
- if (fs.existsSync(removePath)) {
124
- RendererHelpers.reportFailure(renderer, done);
125
- } else {
126
- project.remove(plugin);
127
- done();
128
- }
129
- });
130
- } else {
131
- RendererHelpers.reportFailure(renderer, done);
132
- }
133
- });
134
- }
135
-
136
- };
1
+ import { uninstall as pluginsUninstall } from '../integration/PluginManagement.js'
2
+
3
+ export default async function uninstall (logger, ...args) {
4
+ const plugins = args.filter(arg => !String(arg).startsWith('--'))
5
+ await pluginsUninstall({
6
+ logger,
7
+ plugins
8
+ })
9
+ }
@@ -1,96 +1,12 @@
1
- var bower = require('bower'),
2
- chalk = require('chalk'),
3
- inquirer = require('inquirer'),
4
- _ = require('lodash'),
5
- Q = require('q'),
6
- request = require('request'),
7
- Constants = require('../Constants'),
8
- JsonLoader = require('../JsonLoader'),
9
- authenticate = require('../promise/authenticate'),
10
- log;
11
-
12
- module.exports = {
13
- unregister: function (renderer) {
14
- log = renderer.log;
15
-
16
- var done = arguments[arguments.length-1] || function () {};
17
- var pluginName;
18
-
19
- if (arguments.length >= 3) {
20
- pluginName = arguments[1];
21
- }
22
-
23
- log(chalk.yellow('This will unregister the plugin at', Constants.getRegistry()));
24
-
25
- getProperties(pluginName)
26
- .then(authenticate)
27
- .then(confirm)
28
- .then(unregister)
29
- .then(function() {
30
- log(chalk.green('The plugin was successfully unregistered.'));
31
- done();
32
- })
33
- .catch(function (err) {
34
- log(chalk.red(err));
35
- log('The plugin was not unregistered.');
36
- done(err);
37
- })
38
- .done();
39
- }
40
- };
41
-
42
- function getProperties(pluginName) {
43
- if (pluginName) {
44
- return Q.resolve({name:pluginName});
45
- }
46
-
47
- return loadPluginProperties('./bower.json');
48
- }
49
-
50
- function loadPluginProperties(path, defaults) {
51
- var deferred = Q.defer();
52
-
53
- path = path || './bower.json';
54
-
55
- if(!JsonLoader.existsSync(path)) {
56
- deferred.reject(new Error('bower.json is not in the current working directory. Plugins must be a valid bower package.'));
57
- }
58
- JsonLoader.readJSON(path, function (data) {
59
- deferred.resolve(_.extend({}, defaults, data));
60
- });
61
-
62
- return deferred.promise;
63
- }
64
-
65
- function confirm(properties) {
66
- var deferred = Q.defer();
67
- var schema = [
68
- {
69
- name: 'ready',
70
- message: chalk.cyan('Confirm Unregister now?'),
71
- type: 'confirm',
72
- default: true
73
- }
74
- ];
75
- inquirer.prompt(schema).then(confirmation => {
76
- if(!confirmation.ready) deferred.reject(new Error('Aborted. Nothing has been unregistered.'));
77
- deferred.resolve(properties);
78
- }).catch(err => deferred.reject(err));
79
- return deferred.promise;
80
- }
81
-
82
- function unregister(properties) {
83
- var deferred = Q.defer();
84
-
85
- // user (username) with OAuth (token) wants to unregister the registered plugin (name) from registry
86
- bower.commands.unregister(properties.username+'/'+properties.name, {token:properties.token, registry: Constants.getRegistry()})
87
- .on('end', function (result) {
88
- //log('end', result);
89
- deferred.resolve();
90
- })
91
- .on('error', function (err) {
92
- //log('error', err);
93
- deferred.reject(err);
94
- });
95
- return deferred.promise;
96
- }
1
+ import { unregister as pluginUnregister } from '../integration/PluginManagement.js'
2
+
3
+ export default async function register (logger, ...args) {
4
+ // strip flags
5
+ args = args.filter(arg => !String(arg).startsWith('--'))
6
+ const pluginName = args[0]
7
+ return await pluginUnregister({
8
+ logger,
9
+ cwd: process.cwd(),
10
+ pluginName
11
+ })
12
+ }