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
package/lib/api.js ADDED
@@ -0,0 +1,260 @@
1
+ import http from 'http' // api http import, to hold open process for testing
2
+ import { ADAPT_FRAMEWORK } from './util/constants.js'
3
+ import {
4
+ build,
5
+ download,
6
+ erase,
7
+ getLatestVersion,
8
+ npmInstall,
9
+ deleteSrcCourse,
10
+ deleteSrcCore
11
+ } from './integration/AdaptFramework.js'
12
+ import {
13
+ install,
14
+ uninstall,
15
+ update,
16
+ schemas
17
+ } from './integration/PluginManagement.js'
18
+ import Plugin from './integration/Plugin.js'
19
+ import Project from './integration/Project.js'
20
+ import fs from 'fs-extra'
21
+ import async from 'async'
22
+
23
+ // TODO: api, check no interactivity, should be sorted, will fail silently if it absolutely cannot do what you've asked
24
+ // TODO: api, console and error output, error on fail when isInteractive: false? or something else? return Targets?
25
+ // TODO: api, figure out error translations, should probably error with codes?
26
+
27
+ class API {
28
+ /**
29
+ * Installs a clean copy of the framework
30
+ * @param {Object} options
31
+ * @param {string} [options.version=null] Specific version of the framework to install
32
+ * @param {string} [options.repository] URL to github repo
33
+ * @param {string} [options.cwd=process.cwd()] Directory to install into
34
+ * @return {Promise}
35
+ */
36
+ async installFramework ({
37
+ version = null,
38
+ repository = ADAPT_FRAMEWORK,
39
+ cwd = process.cwd()
40
+ } = {}) {
41
+ if (!version) version = await getLatestVersion({ repository })
42
+ await erase({
43
+ isInteractive: false,
44
+ cwd
45
+ })
46
+ await download({
47
+ repository,
48
+ branch: version,
49
+ cwd
50
+ })
51
+ await deleteSrcCourse({
52
+ cwd
53
+ })
54
+ await deleteSrcCore({
55
+ cwd
56
+ })
57
+ await npmInstall({
58
+ cwd
59
+ })
60
+ }
61
+
62
+ /**
63
+ * @param {Object} options
64
+ * @param {Object} [options.repository=ADAPT_FRAMEWORK] The github repository url
65
+ * @returns {string}
66
+ */
67
+ async getLatestFrameworkVersion ({
68
+ repository = ADAPT_FRAMEWORK
69
+ } = {}) {
70
+ return getLatestVersion({ repository })
71
+ }
72
+
73
+ /**
74
+ * Runs build for a current course
75
+ * @param {Object} options
76
+ * @param {boolean} [options.sourceMaps=false] Whether to run the build with sourcemaps
77
+ * @param {boolean} [options.checkJSON=false] Whether to run without checking the json
78
+ * @param {boolean} [options.cache=true] Whether to clear build caches
79
+ * @param {string} [options.outputDir="build/"] Root path of the framework installation
80
+ * @param {string} [options.cachePath="build/.cache"] Path of compilation cache file
81
+ * @param {string} [options.cwd=process.cwd()] Root path of the framework installation
82
+ * @return {Promise}
83
+ */
84
+ async buildCourse ({
85
+ sourceMaps = false,
86
+ checkJSON = false,
87
+ cache = true,
88
+ outputDir = null,
89
+ cachePath = './build/.cache',
90
+ cwd = process.cwd()
91
+ } = {}) {
92
+ await build({
93
+ sourceMaps,
94
+ checkJSON,
95
+ cache,
96
+ cwd,
97
+ outputDir,
98
+ cachePath
99
+ })
100
+ }
101
+
102
+ /**
103
+ * Installs multiple plugins
104
+ * Can install from source folder or bower registry
105
+ * @param {Object} options
106
+ * @param {[string]} [options.plugins=null] An array with name@version or name@path strings
107
+ * @param {string} [options.cwd=process.cwd()] Root path of the framework installation
108
+ * @return {Promise<[Target]>}
109
+ */
110
+ async installPlugins ({
111
+ plugins = null,
112
+ cwd = process.cwd()
113
+ } = {}) {
114
+ return await install({
115
+ plugins,
116
+ isInteractive: false,
117
+ cwd
118
+ })
119
+ }
120
+
121
+ /**
122
+ * Uninstalls multiple plugins
123
+ * @param {Object} options
124
+ * @param {[string]} [options.plugins=null] An array with name@version or name@path strings
125
+ * @param {string} [options.cwd=process.cwd()] Root path of the framework installation
126
+ * @return {Promise<[Target]>}
127
+ */
128
+ async uninstallPlugins ({
129
+ plugins = null,
130
+ cwd = process.cwd()
131
+ } = {}) {
132
+ return await uninstall({
133
+ plugins,
134
+ isInteractive: false,
135
+ cwd
136
+ })
137
+ }
138
+
139
+ /**
140
+ * Updates multiple plugins
141
+ * Can install from source folder or bower registry
142
+ * @param {Object} options
143
+ * @param {[string]} [options.plugins=null] An array with name@version or name@path strings
144
+ * @param {string} [options.cwd=process.cwd()] Root path of the framework installation
145
+ * @return {Promise<[Target]>}
146
+ */
147
+ async updatePlugins ({
148
+ plugins = null,
149
+ cwd = process.cwd()
150
+ } = {}) {
151
+ return await update({
152
+ plugins,
153
+ isInteractive: false,
154
+ cwd
155
+ })
156
+ }
157
+
158
+ /**
159
+ * Retrieves all schemas defined in the project
160
+ * Clears schema cache
161
+ * @param {string} [options.cwd=process.cwd()] Root path of the framework installation
162
+ * @return {Promise<[string]>} Resolves with array of JSON schema filepaths
163
+ */
164
+ async getSchemaPaths ({
165
+ cwd = process.cwd()
166
+ } = {}) {
167
+ this._schemaPaths = await schemas({ cwd })
168
+ this._schemas = {}
169
+ return this._schemaPaths
170
+ }
171
+
172
+ /**
173
+ * Retrieves named schema
174
+ * Caches schemas for subsequent use
175
+ * Call getSchemaPaths to reset cache
176
+ * @param {string} options.name Schema filepath as returned from getSchemaPaths
177
+ * @return {Promise<Object>} Resolves with the JSON schema contents
178
+ */
179
+ async getSchema ({
180
+ name
181
+ } = {}) {
182
+ if (!this._schemaPaths) return new Error('Please run getSchemaPaths first')
183
+ if (!fs.existsSync(name) || !this._schemaPaths.includes(name)) throw new Error(`Schema does not exist: ${name}`)
184
+ return (this._schemas[name] = this._schemas[name] ?? await fs.readJSON(name))
185
+ }
186
+
187
+ /**
188
+ * Returns all installed plugins
189
+ * @return {Promise<[Plugin]>}
190
+ */
191
+ async getInstalledPlugins ({
192
+ cwd = process.cwd()
193
+ } = {}) {
194
+ const project = new Project({ cwd })
195
+ if (!project.isAdaptDirectory) throw new Error(`Not in an adapt folder at: ${cwd}`)
196
+ const installedPlugins = await project.getInstalledPlugins()
197
+ for (const plugin of installedPlugins) {
198
+ await plugin.fetchProjectInfo()
199
+ }
200
+ return installedPlugins
201
+ }
202
+
203
+ /**
204
+ * Gets the update information for installed and named plugins
205
+ * @param {Object} options
206
+ * @param {[string]} [options.plugins=null] An y of plugin names (if not specified, all plugins are checked)
207
+ * @param {string} [options.cwd=process.cwd()] Root path of the framework installation
208
+ * @return {Promise<[Plugin]>}
209
+ */
210
+ async getPluginUpdateInfos ({
211
+ plugins = null,
212
+ cwd = process.cwd()
213
+ } = {}) {
214
+ /** @type {Project} */
215
+ const project = new Project({ cwd })
216
+ if (!project.isAdaptDirectory) throw new Error(`Not in an adapt folder at: ${cwd}`)
217
+ const frameworkVersion = project.version
218
+ /** @type {[Plugin]} */
219
+ const installedPlugins = await project.getInstalledPlugins()
220
+ const filteredPlugins = !plugins?.length
221
+ ? installedPlugins
222
+ : plugins
223
+ .map(name => installedPlugins.find(plugin => plugin.packageName === name))
224
+ .filter(Boolean)
225
+ await async.eachOfLimit(filteredPlugins, 8, async plugin => {
226
+ await plugin.fetchProjectInfo()
227
+ await plugin.fetchBowerInfo()
228
+ await plugin.findCompatibleVersion(frameworkVersion)
229
+ })
230
+ return filteredPlugins
231
+ }
232
+
233
+ /**
234
+ * Returns an object representing the plugin at the path specified
235
+ * @returns {Plugin}
236
+ */
237
+ async getPluginFromPath ({
238
+ pluginPath,
239
+ cwd = null
240
+ } = {}) {
241
+ const project = cwd ? new Project({ cwd }) : null
242
+ return Plugin.fromPath({ pluginPath, project })
243
+ }
244
+ }
245
+
246
+ const api = new API()
247
+ export default api
248
+
249
+ // debugging
250
+ if (process.argv.includes('--debug-wait')) {
251
+ // http server to hold open process for testing
252
+ const a = http.createServer((request, response) => {
253
+ response.writeHead(200, { 'Content-Type': 'text/plain' })
254
+ response.end('test', 'utf-8')
255
+ })
256
+ a.listen(999)
257
+ // make api global to debug more easily
258
+ global.api = api
259
+ console.log('API Ready')
260
+ }
package/lib/cli.js CHANGED
@@ -1,52 +1,69 @@
1
- var path = require('path'),
2
- _ = require('lodash'),
3
- CommandParser = require('./CommandParser'),
4
- AdaptConsoleApplication = require('./AdaptConsoleApplication'),
5
- stdoutRenderer = {
6
- log: _.bind(console.log, console),
7
- write: _.bind(process.stdout.write, process.stdout)
8
- };
1
+ import authenticate from './commands/authenticate.js'
2
+ import create from './commands/create.js'
3
+ import devinstall from './commands/devinstall.js'
4
+ import help from './commands/help.js'
5
+ import install from './commands/install.js'
6
+ import ls from './commands/ls.js'
7
+ import register from './commands/register.js'
8
+ import rename from './commands/rename.js'
9
+ import search from './commands/search.js'
10
+ import uninstall from './commands/uninstall.js'
11
+ import unregister from './commands/unregister.js'
12
+ import update from './commands/update.js'
13
+ import version from './commands/version.js'
14
+ import logger from './logger.js'
9
15
 
10
- function withPackage(pack) {
11
- this.pkg = pack || require(path.join(__dirname, '..', 'package.json'));
12
- return this;
16
+ const commands = {
17
+ authenticate,
18
+ create,
19
+ devinstall,
20
+ help,
21
+ install,
22
+ ls,
23
+ register,
24
+ rename,
25
+ search,
26
+ uninstall,
27
+ unregister,
28
+ update,
29
+ version
13
30
  }
14
31
 
15
- function withOptions(argv) {
16
- argv = argv || process.argv;
17
- this.command = new CommandParser(argv);
18
- return this;
19
- }
20
-
21
- function execute() {
22
- var commands = require('./commands'),
23
- app = new AdaptConsoleApplication(commands, stdoutRenderer);
24
-
25
- app.do(this.command, function (err) {
26
- process.exit(err ? 1: 0);
27
- });
28
- }
29
-
30
- function getApi() {
31
- var commands = require('./commands');
32
- var apiCommands = {};
32
+ const translationTable = [
33
+ { pattern: /^-v$|^--version$/i, replacement: 'version' },
34
+ { pattern: /^upgrade$/i, replacement: 'update' }
35
+ ]
33
36
 
34
- _.each(commands, function(command, commandName) {
35
- var prefix = 'api';
36
- if (commandName.startsWith(prefix)) {
37
- apiCommands[commandName.split(prefix)[1]] = command;
38
- }
39
- });
37
+ class CLI {
38
+ withOptions (argv = process.argv || ['node', 'path']) {
39
+ const parameters = argv.slice(2).map(param => {
40
+ const translation = translationTable.find(item => item.pattern.test(param))
41
+ return translation ? translation.replacement : param
42
+ })
43
+ const name = parameters.length
44
+ ? String.prototype.toLowerCase.call(parameters.shift())
45
+ : ''
46
+ this.command = {
47
+ name,
48
+ parameters
49
+ }
50
+ return this
51
+ }
40
52
 
41
- return {
42
- commands:apiCommands
53
+ async execute () {
54
+ try {
55
+ if (!commands[this.command.name]) {
56
+ const e = new Error(`Unknown command "${this.command.name}", please check the documentation.`)
57
+ logger?.log(e.message)
58
+ throw e
59
+ }
60
+ const commandArguments = [logger].concat(this.command.parameters)
61
+ await commands[this.command.name](...commandArguments)
62
+ } catch (err) {
63
+ console.error(err)
64
+ process.exit(err ? 1 : 0)
43
65
  }
66
+ }
44
67
  }
45
68
 
46
- module.exports = {
47
- command: null,
48
- withOptions: withOptions,
49
- withPackage: withPackage,
50
- execute: execute,
51
- api: getApi()
52
- };
69
+ export default new CLI()
@@ -0,0 +1,18 @@
1
+ import chalk from 'chalk'
2
+ import { authenticate as pluginAuthenticate } from '../integration/PluginManagement.js'
3
+
4
+ export default async function authenticate (logger, ...args) {
5
+ // strip flags
6
+ args = args.filter(arg => !String(arg).startsWith('--'))
7
+ try {
8
+ const confirmation = await pluginAuthenticate({
9
+ logger,
10
+ cwd: process.cwd(),
11
+ pluginName: args[0]
12
+ })
13
+ const { username, type, pluginName } = confirmation
14
+ logger?.log(chalk.green(`${username} authenticated as ${type} for ${pluginName}`))
15
+ } catch (err) {
16
+ logger?.error('Authentication failed')
17
+ }
18
+ }
@@ -1,81 +1,64 @@
1
- var chalk = require('chalk'),
2
- Q = require('q'),
3
- getRepository = require('../../promise/getRepository'),
4
- removeTemporaryDownload = require('../../promise/removeTemporaryDownload'),
5
- replaceTextContent = require('../../promise/replaceTextContent'),
6
- slug = require('../../Slug'),
7
- Constants = require('../../Constants');
1
+ import fs from 'fs-extra'
2
+ import globs from 'globs'
3
+ import path from 'path'
4
+ import chalk from 'chalk'
5
+ import slug from 'speakingurl'
6
+ import Project from '../../integration/Project.js'
7
+ import downloader from '../../util/download.js'
8
+ import { ADAPT_COMPONENT } from '../../util/constants.js'
8
9
 
9
- module.exports = function (properties) {
10
- var fs = require('fs'),
11
- path = require('path');
10
+ export default async function component ({
11
+ name,
12
+ repository = ADAPT_COMPONENT,
13
+ cwd,
14
+ branch,
15
+ logger
16
+ }) {
17
+ name = slug(name, { maintainCase: true })
12
18
 
13
- properties.component = {
14
- name: slug(properties.localDir),
15
- files: []
16
- };
17
- properties.relative = function (file) {
18
- return path.join(this.localDir, file);
19
- };
19
+ const project = new Project({ cwd, logger })
20
+ let pluginDir
21
+ if (project.containsManifestFile) {
22
+ const componentsDirectory = 'src/components'
23
+ pluginDir = path.join(cwd, componentsDirectory, 'adapt-' + name)
24
+ if (!fs.existsSync(componentsDirectory)) fs.mkdirSync(componentsDirectory)
25
+ } else {
26
+ pluginDir = path.join(cwd, name)
27
+ }
20
28
 
21
- if(addComponentToCurrentCourse()) {
22
- var componentsDirectory = 'src/components';
23
- properties.localDir = path.join(componentsDirectory, properties.localDir);
24
- if(!fs.existsSync(componentsDirectory)) fs.mkdirSync(componentsDirectory);
25
- }
26
- properties.component.files.push(properties.relative('bower.json'));
29
+ await downloader({
30
+ branch,
31
+ repository,
32
+ cwd: pluginDir,
33
+ logger
34
+ })
27
35
 
28
- return createComponent(properties)
29
- .then(function (properties) {
30
- properties.renderer.log('\n' + chalk.green(properties.localDir), 'has been created.\n');
36
+ const files = await new Promise((resolve, reject) => {
37
+ globs('**', { cwd: pluginDir }, (err, matches) => {
38
+ if (err) return reject(err)
39
+ resolve(matches.map(match => path.join(pluginDir, match)))
40
+ })
41
+ })
31
42
 
32
- if(addComponentToCurrentCourse()) {
33
- properties.renderer.log(chalk.grey('To use this component in your course, use the registered name:') + chalk.yellow(properties.component.name));
34
- }
35
- });
36
- };
43
+ const filesRenamed = files.map(from => {
44
+ const to = from.replace(/((contrib-)?componentName)/g, name)
45
+ fs.renameSync(from, to)
46
+ return to
47
+ })
37
48
 
38
- function addComponentToCurrentCourse() {
39
- var fs = require('fs');
40
- return fs.existsSync('./adapt.json');
41
- }
42
-
43
- function createComponent(properties) {
44
- properties.repository = Constants.ComponentRepository;
45
- properties.repositoryName = Constants.ComponentRepositoryName;
46
- return getRepository(properties)
47
- .then(removeTemporaryDownload)
48
- .then(renameFiles)
49
- .then(renameVariables);
50
- }
49
+ await Promise.all(filesRenamed.map(async function (file) {
50
+ if (fs.statSync(file).isDirectory()) return
51
+ const lowerCaseName = name.toLowerCase()
52
+ const content = (await fs.readFile(file)).toString()
53
+ const modifiedContent = content
54
+ .replace(/((contrib-)?componentName)/g, name)
55
+ .replace(/((contrib-)?componentname)/g, lowerCaseName)
56
+ return fs.writeFile(file, modifiedContent)
57
+ }))
51
58
 
52
- function renameFiles(properties) {
53
- var fs = require('fs'),
54
- path = require('path');
59
+ logger?.log('\n' + chalk.green(pluginDir), 'has been created.\n')
55
60
 
56
- var files = [
57
- { match: 'js/adapt-contrib-componentName.js', replace: /contrib-componentName/ },
58
- { match: 'less/componentName.less', replace: /componentName/ },
59
- { match: 'templates/componentName.hbs', replace: /componentName/ }
60
- ];
61
- var renameFiles = files.map(function (file) {
62
- return {
63
- from: properties.relative(file.match),
64
- to: properties.relative(file.match.replace(file.replace, properties.component.name))
65
- };
66
- });
67
- renameFiles.forEach(function (file) {
68
- fs.renameSync(file.from, file.to);
69
- properties.component.files.push(file.to);
70
- });
71
- return properties;
61
+ if (fs.existsSync('./adapt.json')) {
62
+ logger?.log(chalk.grey('To use this component in your course, use the registered name:') + chalk.yellow(name))
63
+ }
72
64
  }
73
-
74
- function renameVariables(properties) {
75
- var renameFileContentPromises = properties.component.files.map(function (file) {
76
- return replaceTextContent(file, (/((contrib-)?componentName)/g), properties.component.name);
77
- });
78
- return Q.all(renameFileContentPromises).then(function () {
79
- return properties;
80
- });
81
- }
@@ -1,81 +1,26 @@
1
- var bower = require('bower'),
2
- chalk = require('chalk'),
3
- inquirer = require('inquirer'),
4
- path = require('path'),
5
- Q = require('q'),
6
- fs = require('q-io/fs'),
7
- Plugin = require('../../Plugin'),
8
- getRepository = require('../../promise/getRepository'),
9
- removeTemporaryDownload = require('../../promise/removeTemporaryDownload'),
10
- installNodeDependencies = require('../../promise/installNodeDependencies'),
11
- installAdaptDependencies = require('../../promise/installAdaptDependencies'),
12
- _ = require('lodash');
13
-
14
- module.exports = function (properties) {
15
- var progress = _.throttle(function () {
16
- properties.renderer.write(chalk.grey('.'));
17
- }, 300);
18
-
19
- return deleteExistingCourse(properties)
20
- .then(function (properties) {
21
- properties.renderer.write(chalk.cyan('downloading framework to', properties.localDir, '\t'));
22
- return properties;
23
- })
24
- .then(getRepository)
25
- .progress(function (data) {
26
- progress();
27
- return data;
28
- })
29
- .then(function (properties) {
30
- properties.renderer.log(' ', 'done!');
31
- return properties;
32
- })
33
- .then(removeTemporaryDownload)
34
- .then(installNodeDependencies)
35
- .then(installAdaptDependencies)
36
- .then(function (properties) {
37
- properties.renderer.log('\n' + chalk.green(properties.localDir), 'has been created.\n');
38
-
39
- properties.renderer.log(chalk.grey('To build the course, run:') +
40
- '\n\tcd ' + properties.localDir +
41
- '\n\tgrunt build\n');
42
-
43
- properties.renderer.log(chalk.grey('Then to view the course, run:') +
44
- '\n\tgrunt server\n');
45
- });
46
-
47
- };
48
-
49
- function deleteExistingCourse(properties) {
50
- return fs.exists(properties.localDir)
51
- .then(function (exists) {
52
- if(exists) {
53
- var deferred = Q.defer();
54
-
55
- inquirer.prompt([
56
- {
57
- name: 'overwrite existing course?',
58
- type: 'confirm',
59
- default: false
60
- }
61
- ]).then(results => {
62
- if(results['overwrite existing course?']) {
63
- fs.removeTree(properties.localDir)
64
- .then(function (){
65
- deferred.resolve(properties);
66
- })
67
- .fail(function (err) {
68
- deferred.reject(err);
69
- });
70
- } else {
71
- deferred.reject(new Error('Course already exists and cannot overwrite.'));
72
- }
73
- }).catch(err => deferred.reject(err));
74
-
75
- return deferred.promise;
76
- }
77
- })
78
- .then(function () {
79
- return properties;
80
- });
1
+ import chalk from 'chalk'
2
+ import {
3
+ erase,
4
+ download,
5
+ npmInstall
6
+ } from '../../integration/AdaptFramework.js'
7
+ import path from 'path'
8
+ import { install as pluginsInstall } from '../../integration/PluginManagement.js'
9
+
10
+ export default async function course ({ name, branch, cwd, logger }) {
11
+ cwd = path.join(cwd, name)
12
+ await erase({ logger, cwd })
13
+ await download({ logger, cwd, branch })
14
+ await npmInstall({ logger, cwd })
15
+ await pluginsInstall({ logger, cwd })
16
+ logger?.log(`
17
+ ${chalk.green(name)} has been created.
18
+
19
+ ${chalk.grey('To build the course, run:')}
20
+ cd ${name}
21
+ grunt build
22
+
23
+ ${chalk.grey('Then to view the course, run:')}
24
+ grunt server
25
+ `)
81
26
  }
@@ -0,0 +1,18 @@
1
+ import component from './component.js'
2
+ import { ADAPT_QUESTION } from '../../util/constants.js'
3
+
4
+ export default async function question ({
5
+ name,
6
+ repository = ADAPT_QUESTION,
7
+ cwd,
8
+ branch,
9
+ logger
10
+ }) {
11
+ return component({
12
+ name,
13
+ repository,
14
+ cwd,
15
+ branch,
16
+ logger
17
+ })
18
+ }