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
package/lib/JsonLoader.js DELETED
@@ -1,40 +0,0 @@
1
- var fs = require('fs'),
2
- JSONLint = require('json-lint');
3
-
4
- module.exports = {
5
- existsSync: fs.existsSync,
6
-
7
- exists: fs.exists,
8
-
9
- readJSON: function (filepath, done) {
10
- done = done || function () {};
11
-
12
- fs.readFile(filepath, 'utf8', function (err, data) {
13
- if(err) return done(err);
14
-
15
- try {
16
- validateJSON(data, filepath);
17
- done(null, JSON.parse(data));
18
- } catch (ex) {
19
- done(ex.message);
20
- }
21
- });
22
- },
23
-
24
- readJSONSync: function (filepath) {
25
- var data = fs.readFileSync(filepath, 'utf-8');
26
- validateJSON(data, filepath);
27
- return JSON.parse(data);
28
- }
29
- };
30
-
31
- function validateJSON(jsonData, filepath) {
32
- var lint = JSONLint(jsonData);
33
- if (lint.error) {
34
- var errorMessage = 'JSON parsing error: ' + lint.error + ', line: ' + lint.line + ', character: ' + lint.character;
35
- if(filepath) {
36
- errorMessage += ', file: \'' + filepath + '\'';
37
- }
38
- throw new Error(errorMessage);
39
- }
40
- }
package/lib/JsonWriter.js DELETED
@@ -1,21 +0,0 @@
1
- var fs = require('fs');
2
-
3
- module.exports = {
4
- existsSync: fs.existsSync,
5
-
6
- exists: fs.exists,
7
-
8
- writeJSON: function (filepath, values, done) {
9
- done = done || function () {};
10
-
11
- fs.writeFile(filepath, JSON.stringify(values, null, 4), { encoding: 'utf8' }, function (err) {
12
- if(err) return done(err);
13
-
14
- done();
15
- });
16
- },
17
-
18
- writeJSONSync: function (filepath, values) {
19
- return fs.writeFileSync(filepath, JSON.stringify(values, null, 4), { encoding: 'utf8' });
20
- }
21
- }
@@ -1,41 +0,0 @@
1
- var bower = require('bower'),
2
- Q = require('q');
3
-
4
- module.exports = {
5
- getKeywords: function (plugin, config) {
6
- var deferred = Q.defer();
7
-
8
- bower.commands.info(plugin.toString(), 'keywords', config || {})
9
- .on('end', function(results) {
10
- deferred.resolve(results);
11
- })
12
- .on('error', function(err) {
13
- deferred.reject(err);
14
- });
15
- return deferred.promise;
16
- },
17
- getFrameworkCompatibility: function (plugin, config) {
18
- var deferred = Q.defer();
19
- var allVersions = '*';
20
-
21
- bower.commands.info(plugin.toString(), 'framework', config || {})
22
- .on('end', function(results) {
23
- deferred.resolve(results || allVersions);
24
- })
25
- .on('error', function() {
26
- deferred.resolve(allVersions);
27
- });
28
- return deferred.promise;
29
- },
30
- getRepositoryUrl: function (plugin, config) {
31
- var deferred = Q.defer();
32
- bower.commands.lookup(plugin.name, config || {})
33
- .on('end', function(results) {
34
- deferred.resolve(results);
35
- })
36
- .on('error', function(err) {
37
- deferred.reject(err);
38
- });
39
- return deferred.promise;
40
- }
41
- };
package/lib/Plugin.js DELETED
@@ -1,53 +0,0 @@
1
- var slug = require('./Slug'),
2
- endpointParser = require('bower-endpoint-parser'),
3
- zero = '0.0.0',
4
- any = '*';
5
-
6
-
7
- var Plugin = function(name, versionOrIsContrib, isContrib) {
8
- this.name = name;
9
-
10
- if(typeof isContrib === 'undefined') {
11
- isContrib = false;
12
- }
13
- if(typeof versionOrIsContrib === 'undefined') {
14
- isContrib = false;
15
- this.version = any;
16
- } else if(typeof versionOrIsContrib === 'boolean'){
17
- isContrib = versionOrIsContrib;
18
- this.version = any;
19
- } else {
20
- this.version = versionOrIsContrib === zero ? any : versionOrIsContrib;
21
- }
22
- this.packageName = makePackageName(name, isContrib);
23
-
24
- Object.defineProperty(this, 'isContrib', {
25
- get: function () {
26
- return /^adapt-contrib/.test(this.packageName);
27
- }
28
- });
29
- };
30
-
31
- Plugin.prototype.toString = function() {
32
- var version = '';
33
- if(this.version !== any) {
34
- version = '#'+ this.version;
35
- }
36
- return ''+this.packageName + version;
37
- };
38
-
39
- function makePackageName(name, isContrib) {
40
- return (/^adapt-/i.test(name) ? '' : 'adapt-') + (!isContrib ? '' : 'contrib-') + slug(name);
41
- }
42
-
43
- Plugin.parse = function (endpoint) {
44
- var ep = endpointParser.decompose(endpoint),
45
- version = /^\*$/.test(ep.target) ? any : ep.target;
46
- return new Plugin(ep.name || ep.source, version);
47
- };
48
-
49
- Plugin.compose = function (endpoint) {
50
- return Plugin.parse(endpointParser.compose(endpoint));
51
- };
52
-
53
- module.exports = Plugin;
@@ -1,47 +0,0 @@
1
- var PluginTypeResolver = function(types) {
2
- this.types = types || [
3
- {
4
- pattern: /^adapt-component$/,
5
- typename: 'component',
6
- belongsTo: 'components'
7
- },
8
- {
9
- pattern: /^adapt-extension$/,
10
- typename: 'extension',
11
- belongsTo: 'extensions'
12
- },
13
- {
14
- pattern: /^adapt-menu$/,
15
- typename: 'menu',
16
- belongsTo: 'menu'
17
- },
18
- {
19
- pattern: /^adapt-theme$/,
20
- typename: 'theme',
21
- belongsTo: 'theme'
22
- }
23
- ];
24
- this.defaultType = this.types[0];
25
- };
26
- PluginTypeResolver.prototype.resolve = function (keywords) {
27
- keywords = Array.isArray(keywords) ? keywords : [keywords];
28
-
29
- var types = keywords.map(toType(this.types))
30
- .filter(NonMatchingKeywords);
31
-
32
- return (types.length ? types[0] : this.defaultType);
33
- };
34
- module.exports = PluginTypeResolver;
35
-
36
- function toType(types) {
37
- return function (keyword) {
38
- var typematches = types.filter(function (type) {
39
- return type.pattern.test(keyword);
40
- });
41
- if(typematches.length) return typematches[0];
42
- }
43
- }
44
-
45
- function NonMatchingKeywords(item) {
46
- return item !== undefined
47
- }
package/lib/Project.js DELETED
@@ -1,89 +0,0 @@
1
- var Plugin = require('./Plugin'),
2
- fs = require('fs'),
3
- _ = require('lodash'),
4
- JsonLoader = require('./JsonLoader'),
5
- JsonWriter = require('./JsonWriter'),
6
- chalk = require('chalk'),
7
- renderer = require('./ConsoleRenderer'),
8
- EmptyProject = function (){
9
- return {
10
- dependencies: {}
11
- };
12
- };
13
- EmptyPackage = function () {
14
- return { "version": "0.0.0" };
15
- };
16
-
17
- var Project = function (manifestFilePath, frameworkPackagePath) {
18
- this.manifestFilePath = manifestFilePath;
19
- this.frameworkPackagePath = frameworkPackagePath;
20
- Object.defineProperty(this, 'plugins', {
21
- get: function () {
22
- var manifest = parse(this.manifestFilePath);
23
- return _.toPairs(manifest.dependencies)
24
- .map(function (pair) {
25
- return new Plugin(pair[0], pair[1]);
26
- });
27
- }.bind(this)
28
- });
29
- };
30
-
31
- Project.prototype.add = function (plugin) {
32
- if(typeof Plugin !== 'object' && plugin.constructor !== Plugin) {
33
- plugin = new Plugin(plugin);
34
- }
35
- var manifest;
36
- if(this.isProjectContainsManifestFile()) {
37
- manifest = parse(this.manifestFilePath);
38
- } else {
39
- manifest = EmptyProject();
40
- }
41
- manifest.dependencies[plugin.packageName] = plugin.version;
42
- save(this.manifestFilePath, manifest);
43
- };
44
-
45
- Project.prototype.remove = function (plugin) {
46
- if(typeof Plugin !== 'object' && plugin.constructor !== Plugin) {
47
- plugin = new Plugin(plugin);
48
- }
49
- var manifest = parse(this.manifestFilePath);
50
- delete manifest.dependencies[plugin.packageName];
51
- save(this.manifestFilePath, manifest);
52
- };
53
-
54
- Project.prototype.getFrameworkVersion = function () {
55
- return parsePackage(this.frameworkPackagePath).version;
56
- };
57
-
58
- Project.prototype.isProjectContainsManifestFile = function() {
59
- return fs.existsSync(this.manifestFilePath);
60
- };
61
-
62
- function parse(manifestFilePath) {
63
- if(!manifestFilePath) return EmptyProject();
64
-
65
- return JsonLoader.readJSONSync(manifestFilePath);
66
- }
67
-
68
- function parsePackage(frameworkPackagePath) {
69
- var EmptyPackage = function () {
70
- return { "version": "0.0.0" }
71
- };
72
-
73
- if(!frameworkPackagePath) return EmptyPackage();
74
-
75
- try {
76
- return JsonLoader.readJSONSync(frameworkPackagePath);
77
- }
78
- catch (ex) {
79
- return EmptyPackage();
80
- }
81
- }
82
-
83
- function save(manifestFilePath, manifest) {
84
- if(manifestFilePath) {
85
- JsonWriter.writeJSONSync(manifestFilePath, manifest);
86
- }
87
- }
88
-
89
- module.exports = Project;
@@ -1,41 +0,0 @@
1
- var chalk = require('chalk'),
2
- inquirer = require('inquirer'),
3
- Q = require('q');
4
-
5
- module.exports = {
6
- reportCompatibilityWarning : function (renderer, plugin) {
7
- renderer.log(chalk.yellow('The plugin'), chalk.white(plugin), chalk.yellow('is not compatible with this version of Adapt.', 'Installing it may cause unexpected behaviour.'));
8
- return confirm(plugin);
9
- },
10
- reportFailure : function (renderer, done) {
11
- return function (err) {
12
- renderer.log(chalk.red('Oh dear, something went wrong.'), err.message);
13
- done(err);
14
- };
15
- },
16
- reportInvalidFrameworkDirectory : function (renderer, done) {
17
- return function (err) {
18
- renderer.log(chalk.red('Fatal error: please run above commands in adapt course directory.'));
19
- done(err);
20
- };
21
- },
22
- };
23
-
24
- function confirm(plugin) {
25
- var deferred = Q.defer();
26
- var schema = [
27
- {
28
- name: 'continueWithInstall',
29
- message: 'Install this plugin anyway?',
30
- type: 'confirm',
31
- default: false
32
- }
33
- ];
34
- inquirer.prompt(schema).then(properties => {
35
- deferred.resolve({
36
- plugin: plugin,
37
- continueWithInstall: properties.continueWithInstall
38
- });
39
- }).catch(err => deferred.reject(err));
40
- return deferred.promise;
41
- }
@@ -1,64 +0,0 @@
1
- var Constants = require('./Constants'),
2
- urljoin = require('url-join'),
3
- path = require('path'),
4
- Q = require('q');
5
-
6
- var RepositoryDownloader = function(options) {
7
- if (!options.branch && !options.repository)
8
- throw new Error('Repository details are required.');
9
- this.options = options;
10
-
11
- Object.defineProperty(this, 'url', {
12
- get: function() {
13
- return urljoin(this.options.repository, 'archive', this.options.branch + '.zip');
14
- }
15
- });
16
- };
17
-
18
- RepositoryDownloader.prototype.fetch = function(destination) {
19
- var deferred = Q.defer(),
20
- download = require('download'),
21
- previousPercent = 0,
22
- fileName = '';
23
-
24
- download(this.url, destination, {
25
- extract: true
26
- })
27
- .on('response', function (response) {
28
- fileName = getFileName(response.headers['content-disposition']);
29
- })
30
- .on('downloadProgress', function(progress) {
31
- var state = {
32
- receivedSize: progress.transferred,
33
- percent: Math.round(progress.transferred / progress.total * 100)
34
- };
35
-
36
- if(state.percent > previousPercent) {
37
- previousPercent = state.percent;
38
- deferred.notify(state, progress);
39
- }
40
- })
41
- .on('error', function(err) {
42
- deferred.reject(err);
43
- })
44
- .then(function() {
45
- deferred.resolve(fileName);
46
- });
47
-
48
- return deferred.promise;
49
- };
50
-
51
- function getFileName(disposition) {
52
- var fileName = "";
53
- if (disposition && disposition.indexOf('attachment') !== -1) {
54
- var regex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
55
- var matches = regex.exec(disposition);
56
- if (matches != null && matches[1]) {
57
- fileName = matches[1].replace(/['"]/g, '');
58
- }
59
- }
60
- return fileName;
61
- }
62
-
63
- module.exports = RepositoryDownloader;
64
-
package/lib/Slug.js DELETED
@@ -1,5 +0,0 @@
1
- var slug = require('speakingurl');
2
- module.exports = function (name) {
3
-
4
- return slug(name, { maintainCase: true })
5
- };
@@ -1,7 +0,0 @@
1
- var semver = require('semver');
2
-
3
- module.exports = {
4
- assertVersionCompatibility: function (adaptVersion, compatibleVersionRange) {
5
- return semver.satisfies(adaptVersion, compatibleVersionRange);
6
- }
7
- };
@@ -1,6 +0,0 @@
1
- var chalk = require('chalk');
2
-
3
- module.exports = {
4
- "course": require('./course'),
5
- "component": require('./component')
6
- };
@@ -1,16 +0,0 @@
1
- var _ = require('lodash'),
2
- fs = require('fs'),
3
- commands = {},
4
- files = fs.readdirSync(__dirname);
5
-
6
- module.exports = files.filter(excludeIndex).reduce(function (commands, filename) {
7
- var useDefaultDependencies = {},
8
- command = require('./' + filename);
9
-
10
- if(typeof command === 'function') command = command(useDefaultDependencies);
11
- return _.extend(commands, command);
12
- }, {});
13
-
14
- function excludeIndex (filename) {
15
- return !/^index.js$/.test(filename);
16
- }
@@ -1,32 +0,0 @@
1
- var readline = require('readline');
2
-
3
- var isLoggingProgress = false;
4
- var lastProgressStr = '';
5
-
6
- module.exports = {
7
- logProgress:function(str) {
8
- lastProgressStr = str;
9
- isLoggingProgress = true;
10
- readline.cursorTo(process.stdout, 0);
11
- process.stdout.write(str);
12
- },
13
-
14
- logProgressConclusion(str) {
15
- lastProgressStr = str;
16
- isLoggingProgress = false;
17
- readline.cursorTo(process.stdout, 0);
18
- process.stdout.write(str);
19
- process.stdout.write('\n');
20
- },
21
-
22
- log:function() {
23
- if (isLoggingProgress) {
24
- readline.clearLine(process.stdout, 0);
25
- readline.cursorTo(process.stdout, 0);
26
- console.log.apply(console, arguments);
27
- this.logProgress(lastProgressStr);
28
- } else {
29
- console.log.apply(console, arguments);
30
- }
31
- }
32
- }