adapt-cli 2.1.13 → 3.0.0

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 (114) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc.json +14 -0
  3. package/README.md +150 -150
  4. package/bin/adapt.js +3 -0
  5. package/json/help-create/question.json +9 -0
  6. package/json/help-create.json +2 -1
  7. package/lib/api.js +260 -0
  8. package/lib/cli.js +61 -44
  9. package/lib/commands/authenticate.js +18 -0
  10. package/lib/commands/create/component.js +55 -72
  11. package/lib/commands/create/course.js +25 -80
  12. package/lib/commands/create/question.js +18 -0
  13. package/lib/commands/create.js +80 -85
  14. package/lib/commands/devinstall.js +35 -97
  15. package/lib/commands/help.js +31 -52
  16. package/lib/commands/install.js +16 -907
  17. package/lib/commands/ls.js +9 -24
  18. package/lib/commands/register.js +10 -195
  19. package/lib/commands/rename.js +13 -128
  20. package/lib/commands/search.js +10 -28
  21. package/lib/commands/uninstall.js +9 -136
  22. package/lib/commands/unregister.js +11 -95
  23. package/lib/commands/update.js +12 -867
  24. package/lib/commands/version.js +12 -14
  25. package/lib/integration/AdaptFramework/build.js +39 -0
  26. package/lib/integration/AdaptFramework/clone.js +27 -0
  27. package/lib/integration/AdaptFramework/deleteSrcCore.js +9 -0
  28. package/lib/integration/AdaptFramework/deleteSrcCourse.js +9 -0
  29. package/lib/integration/AdaptFramework/download.js +21 -0
  30. package/lib/integration/AdaptFramework/erase.js +34 -0
  31. package/lib/integration/AdaptFramework/getLatestVersion.js +79 -0
  32. package/lib/integration/AdaptFramework/npmInstall.js +21 -0
  33. package/lib/integration/AdaptFramework.js +19 -0
  34. package/lib/integration/Plugin.js +403 -0
  35. package/lib/integration/PluginManagement/autenticate.js +56 -0
  36. package/lib/integration/PluginManagement/install.js +222 -0
  37. package/lib/integration/PluginManagement/print.js +52 -0
  38. package/lib/integration/PluginManagement/register.js +130 -0
  39. package/lib/integration/PluginManagement/rename.js +101 -0
  40. package/lib/integration/PluginManagement/schemas.js +8 -0
  41. package/lib/integration/PluginManagement/search.js +46 -0
  42. package/lib/integration/PluginManagement/uninstall.js +141 -0
  43. package/lib/integration/PluginManagement/unregister.js +101 -0
  44. package/lib/integration/PluginManagement/update.js +224 -0
  45. package/lib/integration/PluginManagement.js +21 -0
  46. package/lib/integration/Project.js +146 -0
  47. package/lib/integration/Target.js +296 -0
  48. package/lib/integration/getBowerRegistryConfig.js +34 -0
  49. package/lib/logger.js +28 -0
  50. package/lib/util/JSONReadValidate.js +34 -0
  51. package/lib/util/constants.js +38 -0
  52. package/lib/util/createPromptTask.js +7 -0
  53. package/lib/util/download.js +45 -0
  54. package/lib/util/errors.js +58 -0
  55. package/lib/util/extract.js +24 -0
  56. package/lib/util/getDirNameFromImportMeta.js +6 -0
  57. package/lib/util/promises.js +36 -0
  58. package/package.json +20 -29
  59. package/TESTING.md +0 -25
  60. package/bin/adapt +0 -3
  61. package/gruntfile.js +0 -18
  62. package/lib/AdaptConsoleApplication.js +0 -19
  63. package/lib/CommandParser.js +0 -19
  64. package/lib/CommandTranslator.js +0 -16
  65. package/lib/ConsoleRenderer.js +0 -10
  66. package/lib/Constants.js +0 -68
  67. package/lib/JsonLoader.js +0 -40
  68. package/lib/JsonWriter.js +0 -21
  69. package/lib/PackageMeta.js +0 -41
  70. package/lib/Plugin.js +0 -53
  71. package/lib/PluginTypeResolver.js +0 -47
  72. package/lib/Project.js +0 -89
  73. package/lib/RendererHelpers.js +0 -41
  74. package/lib/RepositoryDownloader.js +0 -64
  75. package/lib/Slug.js +0 -5
  76. package/lib/VersionChecker.js +0 -7
  77. package/lib/commands/create/index.js +0 -6
  78. package/lib/commands/index.js +0 -16
  79. package/lib/commands/install/InstallLog.js +0 -32
  80. package/lib/commands/install/InstallTarget.js +0 -259
  81. package/lib/commands/install/extend.js +0 -31
  82. package/lib/download.js +0 -101
  83. package/lib/errors.js +0 -58
  84. package/lib/promise/authenticate.js +0 -58
  85. package/lib/promise/build.js +0 -20
  86. package/lib/promise/cloneInstall.js +0 -35
  87. package/lib/promise/confirmBuild.js +0 -6
  88. package/lib/promise/exec.js +0 -39
  89. package/lib/promise/getRepository.js +0 -26
  90. package/lib/promise/highest.js +0 -109
  91. package/lib/promise/install.js +0 -31
  92. package/lib/promise/installAdaptDependencies.js +0 -30
  93. package/lib/promise/installNodeDependencies.js +0 -28
  94. package/lib/promise/removeTemporaryDownload.js +0 -8
  95. package/lib/promise/replaceTextContent.js +0 -10
  96. package/lib/promise/uninstallPackage.js +0 -15
  97. package/lib/promise/update.js +0 -33
  98. package/lib/promise/util.js +0 -16
  99. package/test/fixtures/adapt-with-plugins.json +0 -6
  100. package/test/specs/command_translation_concerns.js +0 -13
  101. package/test/specs/create_command_concerns.js +0 -22
  102. package/test/specs/create_concerns.js +0 -30
  103. package/test/specs/install_concerns.js +0 -31
  104. package/test/specs/installing_compatible_plugins_concerns.js +0 -126
  105. package/test/specs/installing_incompatible_plugins_concerns.js +0 -103
  106. package/test/specs/ls_concerns.js +0 -28
  107. package/test/specs/plugin_name_concerns.js +0 -82
  108. package/test/specs/project_concerns.js +0 -128
  109. package/test/specs/registration_concerns.js +0 -31
  110. package/test/specs/repository_downloader_concerns.js +0 -55
  111. package/test/specs/search_concerns.js +0 -30
  112. package/test/specs/type_resolution_concerns.js +0 -71
  113. package/test/specs/uninstall_command_concerns.js +0 -64
  114. package/test/specs/uninstall_concerns.js +0 -31
@@ -1,90 +1,85 @@
1
- var bower = require('bower'),
2
- chalk = require('chalk'),
3
- inquirer = require('inquirer'),
4
- path = require('path'),
5
- Q = require('q'),
6
- Constants = require('../Constants'),
7
- Plugin = require('../Plugin'),
8
- create = require('./create/index'),
9
- highest = require('../promise/highest'),
10
- _ = require('lodash');
1
+ import inquirer from 'inquirer'
2
+ import component from './create/component.js'
3
+ import question from './create/question.js'
4
+ import course from './create/course.js'
5
+ import { ADAPT_FRAMEWORK } from '../util/constants.js'
6
+ import { getLatestVersion as getAdaptLatestVersion } from '../integration/AdaptFramework.js'
11
7
 
12
- module.exports = {
13
- create: function (renderer) {
14
- var type = arguments.length >= 3 ? arguments[1] : Constants.DefaultCreateType,
15
- localDir = arguments.length >= 4 ? arguments[2] : undefined,
16
- branch = arguments.length >= 5 ? arguments[3] : undefined,
17
- done = arguments[arguments.length-1];
18
- highest()
19
- .then(function (tag) {
20
- return confirm({
21
- type: type,
22
- localDir: localDir,
23
- branch: branch || tag,
24
- renderer: renderer
25
- });
26
- })
27
- .then(function (properties) {
28
- var action = create[properties.type];
29
- if(!action) throw new Error('' + properties.type + ' is not a supported type');
30
- return action(properties);
31
- })
32
- .then(function () {
33
- done();
34
- })
35
- .fail(function (err) {
36
- renderer.log(chalk.red("Oh dear, something went wrong. I'm terribly sorry."), err.message);
37
- done(err);
38
- });
39
- }
40
- };
41
-
42
- function confirm(properties) {
43
- var deferred = Q.defer(),
44
- renderer = properties.renderer;
45
-
46
- var typeSchema = [
47
- {
48
- name: 'type',
49
- choices: [ 'course', 'component' ],
50
- type: 'list',
51
- default: properties.type
52
- }
53
- ];
8
+ const subTasks = {
9
+ component,
10
+ question,
11
+ course
12
+ }
54
13
 
55
- inquirer.prompt(typeSchema).then(typeSchemaResults => {
56
- var propertySchema = [
57
- {
58
- name: 'localDir',
59
- message: 'name',
60
- type: 'input',
61
- default: properties.localDir || Constants.DefaultTypeNames[typeSchemaResults.type]
62
- },
63
- {
64
- name: 'branch',
65
- message: 'branch/tag',
66
- type: 'input',
67
- default: properties.branch || 'not specified'
68
- },
69
- {
70
- name: 'ready',
71
- message: 'create now?',
72
- type: 'confirm',
73
- default: true
74
- }
75
- ];
14
+ /**
15
+ * TODO: Change component name to camel case
16
+ */
17
+ export const DEFAULT_TYPE_NAME = {
18
+ course: 'my-adapt-course',
19
+ component: 'myAdaptComponent',
20
+ question: 'myAdaptQuestion'
21
+ }
76
22
 
77
- inquirer.prompt(propertySchema).then(propertySchemaResults => {
78
- if(!propertySchemaResults.ready) deferred.reject(new Error('Aborted. Nothing has been created.'));
23
+ export default async function create (logger, type = 'course', name, branch) {
24
+ const options = await confirmOptions({
25
+ type,
26
+ name,
27
+ branch,
28
+ logger
29
+ })
30
+ const action = subTasks[options.type]
31
+ if (!action) throw new Error('' + options.type + ' is not a supported type')
32
+ try {
33
+ await action({
34
+ name: options.name,
35
+ branch: options.branch,
36
+ cwd: process.cwd(),
37
+ logger
38
+ })
39
+ } catch (err) {
40
+ logger?.error("Oh dear, something went wrong. I'm terribly sorry.", err.message)
41
+ throw err
42
+ }
43
+ }
79
44
 
80
- var properties = _.extend({},
81
- typeSchemaResults,
82
- propertySchemaResults,
83
- {
84
- renderer: renderer
85
- });
86
- deferred.resolve(properties);
87
- }).catch(err => deferred.reject(err));
88
- }).catch(err => deferred.reject(err));
89
- return deferred.promise;
45
+ async function confirmOptions ({ logger, type, name, branch }) {
46
+ const typeSchema = [
47
+ {
48
+ name: 'type',
49
+ choices: ['course', 'component', 'question'],
50
+ type: 'list',
51
+ default: type
52
+ }
53
+ ]
54
+ const typeSchemaResults = await inquirer.prompt(typeSchema)
55
+ branch = branch || (typeSchemaResults.type === 'course')
56
+ ? await getAdaptLatestVersion({ repository: ADAPT_FRAMEWORK })
57
+ : 'master'
58
+ const propertySchema = [
59
+ {
60
+ name: 'name',
61
+ message: 'name',
62
+ type: 'input',
63
+ default: name || DEFAULT_TYPE_NAME[typeSchemaResults.type]
64
+ },
65
+ {
66
+ name: 'branch',
67
+ message: 'branch/tag',
68
+ type: 'input',
69
+ default: branch || 'not specified'
70
+ },
71
+ {
72
+ name: 'ready',
73
+ message: 'create now?',
74
+ type: 'confirm',
75
+ default: true
76
+ }
77
+ ]
78
+ const propertySchemaResults = await inquirer.prompt(propertySchema)
79
+ if (!propertySchemaResults.ready) throw new Error('Aborted. Nothing has been created.')
80
+ const finalProperties = {
81
+ ...typeSchemaResults,
82
+ ...propertySchemaResults
83
+ }
84
+ return finalProperties
90
85
  }
@@ -1,97 +1,35 @@
1
- var promise = require('../promise/util');
2
-
3
- module.exports = function (dependencies) {
4
-
5
- var chalk = dependencies.chalk || require('chalk'),
6
- path = dependencies.path || require('path'),
7
- Q = dependencies.Q || require('q'),
8
- Constants = dependencies.Constants || require('../Constants'),
9
- PluginTypeResolver = dependencies.PluginTypeResolver || require('../PluginTypeResolver'),
10
- PackageMeta = dependencies.PackageMeta || require('../PackageMeta'),
11
- Project = dependencies.Project || require('../Project'),
12
- Plugin = dependencies.Plugin || require('../Plugin'),
13
- RendererHelpers = dependencies.RendererHelpers || require('../RendererHelpers'),
14
- VersionChecker = dependencies.VersionChecker || require('../VersionChecker'),
15
- install = dependencies.install || require('../promise/install'),
16
- cloneInstall = dependencies.cloneInstall || require('../promise/cloneInstall'),
17
- mkdirp = require('mkdirp'),
18
- exec = require('child_process').exec;
19
-
20
- function clonePlugins(localPath, renderer) {
21
- renderer.log("Cloning Plugins");
22
-
23
- var project = new Project(
24
- path.resolve(localPath, Constants.DefaultProjectManifestPath),
25
- path.resolve(localPath, Constants.DefaultProjectFrameworkPath)
26
- ),
27
- plugins = project.plugins;
28
-
29
-
30
-
31
- plugins.forEach(function(plugin, index, array) {
32
- createInstallationTask(plugin, localPath, renderer);
33
- });
34
- }
35
-
36
-
37
- function createInstallationTask(plugin, localPath, renderer) {
38
- return PackageMeta.getKeywords(plugin, { registry: Constants.getRegistry() })
39
- .then(function (keywords) {
40
- var resolver = new PluginTypeResolver(),
41
- pluginType = resolver.resolve(keywords);
42
-
43
- renderer.log(chalk.cyan(plugin.packageName), 'found.', 'Installing', pluginType.typename, '...');
44
- return cloneInstall(plugin, {
45
- localPath: localPath,
46
- directory: path.join('src', pluginType.belongsTo),
47
- registry: Constants.getRegistry()
48
- });
49
- })
50
- .then(function (installed) {
51
- if (!installed) throw new Error('The plugin was found but failed to download and install.');
52
- renderer.log(chalk.green(plugin.packageName), 'has been installed successfully.');
53
- })
54
- .done();
55
- }
56
-
57
- return {
58
- devinstall: function (renderer) {
59
-
60
- var repository = arguments.length >= 3 ? arguments[1] : Constants.FrameworkRepository,
61
- localPath = path.resolve(Constants.FrameworkRepositoryName),
62
- done = arguments[arguments.length-1] || function () {};
63
-
64
- try {
65
- // Are we inside an existing adapt_framework project.
66
- var packageJson = require(process.cwd() + '/package.json');
67
- if (packageJson.name === 'adapt_framework') {
68
- localPath = process.cwd();
69
- }
70
- } catch (err) {
71
- // Don't worry, we're not inside a framework directory.
72
- }
73
-
74
- // we're trying to install a single plugin.
75
- if (repository !== Constants.FrameworkRepository) {
76
- return createInstallationTask(Plugin.parse(repository), localPath, renderer)
77
- }
78
-
79
- function promiseFromChildProcess(child) {
80
- return new Promise(function (resolve, reject) {
81
- child.addListener("error", reject);
82
- child.addListener("exit", resolve);
83
- });
84
- }
85
- var child = exec(`git clone ${repository} "${localPath}"`);
86
-
87
- // clone the framework and all the bundled plugins.
88
- renderer.log("Cloning adapt_framework");
89
- promiseFromChildProcess(child)
90
- .then(function(repo){
91
- renderer.log("Framework cloned.");
92
- process.chdir(localPath);
93
- clonePlugins(localPath, renderer, done);
94
- });
95
- }
96
- };
97
- };
1
+ import { clone as adaptClone } from '../integration/AdaptFramework.js'
2
+ import { install as pluginsInstall } from '../integration/PluginManagement.js'
3
+ import { ADAPT_FRAMEWORK } from '../util/constants.js'
4
+ import path from 'path'
5
+ import Project from '../integration/Project.js'
6
+ import gh from 'parse-github-url'
7
+
8
+ export default async function devinstall (logger, ...args) {
9
+ const NAME = gh(ADAPT_FRAMEWORK).repo
10
+ const isInAdapt = new Project().isAdaptDirectory
11
+ // In adapt folder or download adapt into adapt_framework folder
12
+ const cwd = isInAdapt
13
+ ? process.cwd()
14
+ : path.resolve(NAME)
15
+ // strip flags
16
+ const isClean = args.includes('--clean')
17
+ const isDryRun = args.includes('--dry-run') || args.includes('--check')
18
+ const isCompatibleEnabled = args.includes('--compatible')
19
+ args = args.filter(arg => !String(arg).startsWith('--'))
20
+ // always perform a clone on the adapt directory
21
+ if (!isInAdapt || args.includes(NAME)) {
22
+ await adaptClone({ logger, cwd })
23
+ args = args.filter(arg => arg !== NAME)
24
+ }
25
+ const plugins = args
26
+ return await pluginsInstall({
27
+ logger,
28
+ cwd,
29
+ isClean,
30
+ isDryRun,
31
+ isCompatibleEnabled,
32
+ dev: true,
33
+ plugins
34
+ })
35
+ }
@@ -1,52 +1,31 @@
1
- var fs = require('fs'),
2
- path = require('path'),
3
- chalk = require('chalk'),
4
- _ = require('lodash');
5
-
6
- module.exports = {
7
- help: function (renderer) {
8
-
9
- var name = arguments.length >= 3
10
- ? arguments.length > 3
11
- ? Array.prototype.slice.apply(arguments, [1, arguments.length -1]).join(' ')
12
- : arguments[1]
13
- : '';
14
- var json;
15
-
16
- if (name) {
17
- json = path.resolve(__dirname, '../../json/help-' + name.replace(/\s+/g, '/') + '.json');
18
- } else {
19
- json = path.resolve(__dirname, '../../json/help.json');
20
- }
21
-
22
- fs.exists(json, function(exists) {
23
- if (!exists) {
24
- renderer.log('adapt ' + chalk.red(name) + ' Unknown command: ' + name);
25
- } else {
26
-
27
- var jsonData = require(json);
28
-
29
- renderer.log('\nUsage: \n');
30
- _.each(jsonData.usage, function(usage) {
31
- renderer.log(' ' + chalk.cyan('adapt') + ' ' + usage);
32
- });
33
-
34
- if(!_.isEmpty(jsonData.commands)) {
35
- renderer.log('\n\nwhere <command> is one of:\n');
36
- _.each(jsonData.commands, function(description, command) {
37
- renderer.log(' ' + command + new Array(23 - command.length).join(' ') + description);
38
- });
39
- }
40
-
41
- if(jsonData.description) {
42
- renderer.log('\nDescription:\n\n ' + jsonData.description);
43
- }
44
-
45
- if(!name) {
46
- renderer.log('\nSee \'adapt help <command>\' for more information on a specific command.\n');
47
- }
48
- }
49
- });
50
-
51
- }
52
- };
1
+ import fs from 'fs-extra'
2
+ import path from 'path'
3
+ import chalk from 'chalk'
4
+ import getDirNameFromImportMeta from '../util/getDirNameFromImportMeta.js'
5
+ const __dirname = getDirNameFromImportMeta(import.meta)
6
+
7
+ export default function help (logger, ...args) {
8
+ const name = args.join(' ')
9
+ const json = name
10
+ ? path.resolve(__dirname, `../../json/help-${name.replace(/\s+/g, '/')}.json`)
11
+ : path.resolve(__dirname, '../../json/help.json')
12
+ if (!fs.existsSync(json)) {
13
+ logger?.log(`adapt ${chalk.red(name)} Unknown command: ${name}`)
14
+ return
15
+ }
16
+ const jsonData = fs.readJSONSync(json)
17
+ logger?.log('\nUsage: \n')
18
+ jsonData.usage.forEach(usage => logger?.log(` ${chalk.cyan('adapt')} ${usage}`))
19
+ if (jsonData.commands && Object.entries(jsonData.commands).length) {
20
+ logger?.log('\n\nwhere <command> is one of:\n')
21
+ Object.entries(jsonData.commands).forEach(([command, description]) => {
22
+ logger?.log(` ${command}${new Array(23 - command.length).join(' ')}${description}`)
23
+ })
24
+ }
25
+ if (jsonData.description) {
26
+ logger?.log(`\nDescription:\n\n ${jsonData.description}`)
27
+ }
28
+ if (!name) {
29
+ logger?.log('\nSee \'adapt help <command>\' for more information on a specific command.\n')
30
+ }
31
+ }