adapt-cli 3.0.0 → 3.0.7
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.
- package/.bowerrc +2 -2
- package/.eslintignore +1 -1
- package/.eslintrc.json +14 -14
- package/.github/CONTRIBUTING.md +8 -0
- package/.github/ISSUE_TEMPLATE.md +17 -0
- package/.github/pull_request_template.md +25 -0
- package/.github/workflows/addtomainproject.yml +19 -0
- package/.github/workflows/releases.yml +25 -0
- package/.travis.yml +46 -46
- package/README.md +266 -266
- package/bin/adapt.js +3 -3
- package/json/help-create/component.json +9 -9
- package/json/help-create/course.json +9 -9
- package/json/help-create/question.json +9 -9
- package/json/help-create.json +12 -12
- package/json/help-devinstall.json +9 -9
- package/json/help-install.json +10 -10
- package/json/help-ls.json +7 -7
- package/json/help-register.json +7 -7
- package/json/help-rename.json +7 -7
- package/json/help-search.json +8 -8
- package/json/help-uninstall.json +7 -7
- package/json/help-unregister.json +8 -8
- package/json/help-update.json +12 -12
- package/json/help-version.json +7 -7
- package/json/help.json +19 -19
- package/lib/api.js +273 -260
- package/lib/cli.js +70 -69
- package/lib/commands/authenticate.js +18 -18
- package/lib/commands/create/component.js +64 -64
- package/lib/commands/create/course.js +26 -26
- package/lib/commands/create/question.js +18 -18
- package/lib/commands/create.js +94 -85
- package/lib/commands/devinstall.js +35 -35
- package/lib/commands/help.js +31 -31
- package/lib/commands/install.js +16 -16
- package/lib/commands/ls.js +35 -9
- package/lib/commands/register.js +11 -11
- package/lib/commands/rename.js +14 -14
- package/lib/commands/search.js +11 -11
- package/lib/commands/uninstall.js +9 -9
- package/lib/commands/unregister.js +12 -12
- package/lib/commands/update.js +12 -12
- package/lib/commands/version.js +13 -13
- package/lib/econnreset.js +8 -0
- package/lib/integration/AdaptFramework/build.js +42 -39
- package/lib/integration/AdaptFramework/clone.js +27 -27
- package/lib/integration/AdaptFramework/deleteSrcCore.js +9 -9
- package/lib/integration/AdaptFramework/deleteSrcCourse.js +9 -9
- package/lib/integration/AdaptFramework/download.js +21 -21
- package/lib/integration/AdaptFramework/erase.js +34 -34
- package/lib/integration/AdaptFramework/getLatestVersion.js +74 -79
- package/lib/integration/AdaptFramework/npmInstall.js +21 -21
- package/lib/integration/AdaptFramework.js +19 -19
- package/lib/integration/Plugin.js +404 -403
- package/lib/integration/PluginManagement/autenticate.js +47 -56
- package/lib/integration/PluginManagement/install.js +224 -222
- package/lib/integration/PluginManagement/print.js +52 -52
- package/lib/integration/PluginManagement/register.js +130 -130
- package/lib/integration/PluginManagement/rename.js +95 -101
- package/lib/integration/PluginManagement/schemas.js +8 -8
- package/lib/integration/PluginManagement/search.js +37 -46
- package/lib/integration/PluginManagement/uninstall.js +141 -141
- package/lib/integration/PluginManagement/unregister.js +91 -101
- package/lib/integration/PluginManagement/update.js +224 -224
- package/lib/integration/PluginManagement.js +21 -21
- package/lib/integration/Project.js +146 -146
- package/lib/integration/Target.js +299 -296
- package/lib/integration/getBowerRegistryConfig.js +34 -34
- package/lib/logger.js +28 -28
- package/lib/util/JSONReadValidate.js +34 -34
- package/lib/util/constants.js +38 -38
- package/lib/util/createPromptTask.js +7 -7
- package/lib/util/download.js +45 -45
- package/lib/util/errors.js +58 -58
- package/lib/util/extract.js +24 -24
- package/lib/util/getDirNameFromImportMeta.js +6 -6
- package/lib/util/promises.js +36 -36
- package/package.json +74 -40
package/lib/cli.js
CHANGED
|
@@ -1,69 +1,70 @@
|
|
|
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'
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
{ pattern:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
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'
|
|
15
|
+
import './econnreset.js'
|
|
16
|
+
|
|
17
|
+
const commands = {
|
|
18
|
+
authenticate,
|
|
19
|
+
create,
|
|
20
|
+
devinstall,
|
|
21
|
+
help,
|
|
22
|
+
install,
|
|
23
|
+
ls,
|
|
24
|
+
register,
|
|
25
|
+
rename,
|
|
26
|
+
search,
|
|
27
|
+
uninstall,
|
|
28
|
+
unregister,
|
|
29
|
+
update,
|
|
30
|
+
version
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const translationTable = [
|
|
34
|
+
{ pattern: /^-v$|^--version$/i, replacement: 'version' },
|
|
35
|
+
{ pattern: /^upgrade$/i, replacement: 'update' }
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
class CLI {
|
|
39
|
+
withOptions (argv = process.argv || ['node', 'path']) {
|
|
40
|
+
const parameters = argv.slice(2).map(param => {
|
|
41
|
+
const translation = translationTable.find(item => item.pattern.test(param))
|
|
42
|
+
return translation ? translation.replacement : param
|
|
43
|
+
})
|
|
44
|
+
const name = parameters.length
|
|
45
|
+
? String.prototype.toLowerCase.call(parameters.shift())
|
|
46
|
+
: ''
|
|
47
|
+
this.command = {
|
|
48
|
+
name,
|
|
49
|
+
parameters
|
|
50
|
+
}
|
|
51
|
+
return this
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async execute () {
|
|
55
|
+
try {
|
|
56
|
+
if (!commands[this.command.name]) {
|
|
57
|
+
const e = new Error(`Unknown command "${this.command.name}", please check the documentation.`)
|
|
58
|
+
logger?.log(e.message)
|
|
59
|
+
throw e
|
|
60
|
+
}
|
|
61
|
+
const commandArguments = [logger].concat(this.command.parameters)
|
|
62
|
+
await commands[this.command.name](...commandArguments)
|
|
63
|
+
} catch (err) {
|
|
64
|
+
console.error(err)
|
|
65
|
+
process.exit(err ? 1 : 0)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export default new CLI()
|
|
@@ -1,18 +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
|
+
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,64 +1,64 @@
|
|
|
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'
|
|
9
|
-
|
|
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 })
|
|
18
|
-
|
|
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
|
-
}
|
|
28
|
-
|
|
29
|
-
await downloader({
|
|
30
|
-
branch,
|
|
31
|
-
repository,
|
|
32
|
-
cwd: pluginDir,
|
|
33
|
-
logger
|
|
34
|
-
})
|
|
35
|
-
|
|
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
|
-
})
|
|
42
|
-
|
|
43
|
-
const filesRenamed = files.map(from => {
|
|
44
|
-
const to = from.replace(/((contrib-)?componentName)/g, name)
|
|
45
|
-
fs.renameSync(from, to)
|
|
46
|
-
return to
|
|
47
|
-
})
|
|
48
|
-
|
|
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
|
-
}))
|
|
58
|
-
|
|
59
|
-
logger?.log('\n' + chalk.green(pluginDir), 'has been created.\n')
|
|
60
|
-
|
|
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
|
-
}
|
|
64
|
-
}
|
|
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'
|
|
9
|
+
|
|
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 })
|
|
18
|
+
|
|
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
|
+
}
|
|
28
|
+
|
|
29
|
+
await downloader({
|
|
30
|
+
branch,
|
|
31
|
+
repository,
|
|
32
|
+
cwd: pluginDir,
|
|
33
|
+
logger
|
|
34
|
+
})
|
|
35
|
+
|
|
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
|
+
})
|
|
42
|
+
|
|
43
|
+
const filesRenamed = files.map(from => {
|
|
44
|
+
const to = from.replace(/((contrib-)?componentName)/g, name)
|
|
45
|
+
fs.renameSync(from, to)
|
|
46
|
+
return to
|
|
47
|
+
})
|
|
48
|
+
|
|
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
|
+
}))
|
|
58
|
+
|
|
59
|
+
logger?.log('\n' + chalk.green(pluginDir), 'has been created.\n')
|
|
60
|
+
|
|
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
|
+
}
|
|
64
|
+
}
|
|
@@ -1,26 +1,26 @@
|
|
|
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
|
-
`)
|
|
26
|
-
}
|
|
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
|
+
`)
|
|
26
|
+
}
|
|
@@ -1,18 +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
|
-
}
|
|
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
|
+
}
|
package/lib/commands/create.js
CHANGED
|
@@ -1,85 +1,94 @@
|
|
|
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'
|
|
7
|
-
|
|
8
|
-
const subTasks = {
|
|
9
|
-
component,
|
|
10
|
-
question,
|
|
11
|
-
course
|
|
12
|
-
}
|
|
13
|
-
|
|
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
|
-
}
|
|
22
|
-
|
|
23
|
-
export default async function create (logger, type = 'course', name, branch) {
|
|
24
|
-
|
|
25
|
-
type,
|
|
26
|
-
name,
|
|
27
|
-
branch
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
{
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
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'
|
|
7
|
+
|
|
8
|
+
const subTasks = {
|
|
9
|
+
component,
|
|
10
|
+
question,
|
|
11
|
+
course
|
|
12
|
+
}
|
|
13
|
+
|
|
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
|
+
}
|
|
22
|
+
|
|
23
|
+
export default async function create (logger, type = 'course', name, branch, bypassPrompts) {
|
|
24
|
+
let options = {
|
|
25
|
+
type,
|
|
26
|
+
name,
|
|
27
|
+
branch
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!bypassPrompts) {
|
|
31
|
+
options = await confirmOptions({
|
|
32
|
+
type,
|
|
33
|
+
name,
|
|
34
|
+
branch,
|
|
35
|
+
logger
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const action = subTasks[options.type]
|
|
40
|
+
if (!action) throw new Error('' + options.type + ' is not a supported type')
|
|
41
|
+
try {
|
|
42
|
+
await action({
|
|
43
|
+
name: options.name,
|
|
44
|
+
branch: options.branch,
|
|
45
|
+
cwd: process.cwd(),
|
|
46
|
+
logger
|
|
47
|
+
})
|
|
48
|
+
} catch (err) {
|
|
49
|
+
logger?.error("Oh dear, something went wrong. I'm terribly sorry.", err.message)
|
|
50
|
+
throw err
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function confirmOptions ({ logger, type, name, branch }) {
|
|
55
|
+
const typeSchema = [
|
|
56
|
+
{
|
|
57
|
+
name: 'type',
|
|
58
|
+
choices: ['course', 'component', 'question'],
|
|
59
|
+
type: 'list',
|
|
60
|
+
default: type
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
const typeSchemaResults = await inquirer.prompt(typeSchema)
|
|
64
|
+
branch = branch || (typeSchemaResults.type === 'course')
|
|
65
|
+
? await getAdaptLatestVersion({ repository: ADAPT_FRAMEWORK })
|
|
66
|
+
: 'master'
|
|
67
|
+
const propertySchema = [
|
|
68
|
+
{
|
|
69
|
+
name: 'name',
|
|
70
|
+
message: 'name',
|
|
71
|
+
type: 'input',
|
|
72
|
+
default: name || DEFAULT_TYPE_NAME[typeSchemaResults.type]
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: 'branch',
|
|
76
|
+
message: 'branch/tag',
|
|
77
|
+
type: 'input',
|
|
78
|
+
default: branch || 'not specified'
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: 'ready',
|
|
82
|
+
message: 'create now?',
|
|
83
|
+
type: 'confirm',
|
|
84
|
+
default: true
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
const propertySchemaResults = await inquirer.prompt(propertySchema)
|
|
88
|
+
if (!propertySchemaResults.ready) throw new Error('Aborted. Nothing has been created.')
|
|
89
|
+
const finalProperties = {
|
|
90
|
+
...typeSchemaResults,
|
|
91
|
+
...propertySchemaResults
|
|
92
|
+
}
|
|
93
|
+
return finalProperties
|
|
94
|
+
}
|
|
@@ -1,35 +1,35 @@
|
|
|
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
|
+
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
|
+
}
|