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.
- package/.bowerrc +2 -2
- package/.eslintignore +1 -0
- package/.eslintrc.json +14 -0
- 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 -0
- package/json/help-create/component.json +9 -9
- package/json/help-create/course.json +9 -9
- package/json/help-create/question.json +9 -0
- package/json/help-create.json +12 -11
- 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 +260 -0
- package/lib/cli.js +69 -52
- package/lib/commands/authenticate.js +18 -0
- package/lib/commands/create/component.js +64 -81
- package/lib/commands/create/course.js +26 -81
- package/lib/commands/create/question.js +18 -0
- package/lib/commands/create.js +94 -90
- package/lib/commands/devinstall.js +35 -97
- package/lib/commands/help.js +31 -52
- package/lib/commands/install.js +16 -907
- package/lib/commands/ls.js +9 -24
- package/lib/commands/register.js +11 -196
- package/lib/commands/rename.js +14 -129
- package/lib/commands/search.js +11 -29
- package/lib/commands/uninstall.js +9 -136
- package/lib/commands/unregister.js +12 -96
- package/lib/commands/update.js +12 -867
- package/lib/commands/version.js +13 -15
- package/lib/integration/AdaptFramework/build.js +42 -0
- package/lib/integration/AdaptFramework/clone.js +27 -0
- package/lib/integration/AdaptFramework/deleteSrcCore.js +9 -0
- package/lib/integration/AdaptFramework/deleteSrcCourse.js +9 -0
- package/lib/integration/AdaptFramework/download.js +21 -0
- package/lib/integration/AdaptFramework/erase.js +34 -0
- package/lib/integration/AdaptFramework/getLatestVersion.js +79 -0
- package/lib/integration/AdaptFramework/npmInstall.js +21 -0
- package/lib/integration/AdaptFramework.js +19 -0
- package/lib/integration/Plugin.js +404 -0
- package/lib/integration/PluginManagement/autenticate.js +56 -0
- package/lib/integration/PluginManagement/install.js +224 -0
- package/lib/integration/PluginManagement/print.js +52 -0
- package/lib/integration/PluginManagement/register.js +130 -0
- package/lib/integration/PluginManagement/rename.js +101 -0
- package/lib/integration/PluginManagement/schemas.js +8 -0
- package/lib/integration/PluginManagement/search.js +46 -0
- package/lib/integration/PluginManagement/uninstall.js +141 -0
- package/lib/integration/PluginManagement/unregister.js +101 -0
- package/lib/integration/PluginManagement/update.js +224 -0
- package/lib/integration/PluginManagement.js +21 -0
- package/lib/integration/Project.js +146 -0
- package/lib/integration/Target.js +299 -0
- package/lib/integration/getBowerRegistryConfig.js +34 -0
- package/lib/logger.js +28 -0
- package/lib/util/JSONReadValidate.js +34 -0
- package/lib/util/constants.js +38 -0
- package/lib/util/createPromptTask.js +7 -0
- package/lib/util/download.js +45 -0
- package/lib/util/errors.js +58 -0
- package/lib/util/extract.js +24 -0
- package/lib/util/getDirNameFromImportMeta.js +6 -0
- package/lib/util/promises.js +36 -0
- package/package.json +74 -49
- package/TESTING.md +0 -25
- package/bin/adapt +0 -3
- package/gruntfile.js +0 -18
- package/lib/AdaptConsoleApplication.js +0 -19
- package/lib/CommandParser.js +0 -19
- package/lib/CommandTranslator.js +0 -16
- package/lib/ConsoleRenderer.js +0 -10
- package/lib/Constants.js +0 -68
- package/lib/JsonLoader.js +0 -40
- package/lib/JsonWriter.js +0 -21
- package/lib/PackageMeta.js +0 -41
- package/lib/Plugin.js +0 -53
- package/lib/PluginTypeResolver.js +0 -47
- package/lib/Project.js +0 -89
- package/lib/RendererHelpers.js +0 -41
- package/lib/RepositoryDownloader.js +0 -64
- package/lib/Slug.js +0 -5
- package/lib/VersionChecker.js +0 -7
- package/lib/commands/create/index.js +0 -6
- package/lib/commands/index.js +0 -16
- package/lib/commands/install/InstallLog.js +0 -32
- package/lib/commands/install/InstallTarget.js +0 -259
- package/lib/commands/install/extend.js +0 -31
- package/lib/download.js +0 -101
- package/lib/errors.js +0 -58
- package/lib/promise/authenticate.js +0 -58
- package/lib/promise/build.js +0 -20
- package/lib/promise/cloneInstall.js +0 -35
- package/lib/promise/confirmBuild.js +0 -6
- package/lib/promise/exec.js +0 -39
- package/lib/promise/getRepository.js +0 -26
- package/lib/promise/highest.js +0 -109
- package/lib/promise/install.js +0 -31
- package/lib/promise/installAdaptDependencies.js +0 -30
- package/lib/promise/installNodeDependencies.js +0 -28
- package/lib/promise/removeTemporaryDownload.js +0 -8
- package/lib/promise/replaceTextContent.js +0 -10
- package/lib/promise/uninstallPackage.js +0 -15
- package/lib/promise/update.js +0 -33
- package/lib/promise/util.js +0 -16
- package/test/fixtures/adapt-with-plugins.json +0 -6
- package/test/specs/command_translation_concerns.js +0 -13
- package/test/specs/create_command_concerns.js +0 -22
- package/test/specs/create_concerns.js +0 -30
- package/test/specs/install_concerns.js +0 -31
- package/test/specs/installing_compatible_plugins_concerns.js +0 -126
- package/test/specs/installing_incompatible_plugins_concerns.js +0 -103
- package/test/specs/ls_concerns.js +0 -28
- package/test/specs/plugin_name_concerns.js +0 -82
- package/test/specs/project_concerns.js +0 -128
- package/test/specs/registration_concerns.js +0 -31
- package/test/specs/repository_downloader_concerns.js +0 -55
- package/test/specs/search_concerns.js +0 -30
- package/test/specs/type_resolution_concerns.js +0 -71
- package/test/specs/uninstall_command_concerns.js +0 -64
- package/test/specs/uninstall_concerns.js +0 -31
package/json/help-install.json
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
{
|
2
|
-
"command": "install",
|
3
|
-
"description": "Install plugins according to the Adapt manifest (adapt.json). You can also specify which plugins to install as arguments. When specifying arguments you can provide an optional semantic version (semver). If a semver is not given the command will attempt to install the latest compatible version. Add the --dry-run option to simulate an installation without making any changes. Add the --compatible option to override any given semvers: the command will attempt to install the latest compatible version for all requested plugins.",
|
4
|
-
"usage": [
|
5
|
-
"install [--dry-run, --compatible]",
|
6
|
-
"install <plugin-name>",
|
7
|
-
"install <plugin-name>#<semver>",
|
8
|
-
"install <plugin-name>@<semver>"
|
9
|
-
]
|
10
|
-
}
|
1
|
+
{
|
2
|
+
"command": "install",
|
3
|
+
"description": "Install plugins according to the Adapt manifest (adapt.json). You can also specify which plugins to install as arguments. When specifying arguments you can provide an optional semantic version (semver). If a semver is not given the command will attempt to install the latest compatible version. Add the --dry-run option to simulate an installation without making any changes. Add the --compatible option to override any given semvers: the command will attempt to install the latest compatible version for all requested plugins.",
|
4
|
+
"usage": [
|
5
|
+
"install [--dry-run, --compatible]",
|
6
|
+
"install <plugin-name>",
|
7
|
+
"install <plugin-name>#<semver>",
|
8
|
+
"install <plugin-name>@<semver>"
|
9
|
+
]
|
10
|
+
}
|
package/json/help-ls.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
{
|
2
|
-
"command": "ls",
|
3
|
-
"description": "List the plugin(s) name with version number mentioned in adapt.json file.",
|
4
|
-
"usage": [
|
5
|
-
"ls"
|
6
|
-
]
|
7
|
-
}
|
1
|
+
{
|
2
|
+
"command": "ls",
|
3
|
+
"description": "List the plugin(s) name with version number mentioned in adapt.json file.",
|
4
|
+
"usage": [
|
5
|
+
"ls"
|
6
|
+
]
|
7
|
+
}
|
package/json/help-register.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
{
|
2
|
-
"command": "register",
|
3
|
-
"description": "Register a plugin to adapt's remote registry by reading bower.json file. Check folowing URL for more detail - https://github.com/adaptlearning/adapt_framework/wiki/Registering-a-plugin",
|
4
|
-
"usage": [
|
5
|
-
"register"
|
6
|
-
]
|
7
|
-
}
|
1
|
+
{
|
2
|
+
"command": "register",
|
3
|
+
"description": "Register a plugin to adapt's remote registry by reading bower.json file. Check folowing URL for more detail - https://github.com/adaptlearning/adapt_framework/wiki/Registering-a-plugin",
|
4
|
+
"usage": [
|
5
|
+
"register"
|
6
|
+
]
|
7
|
+
}
|
package/json/help-rename.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
{
|
2
|
-
"command": "rename",
|
3
|
-
"description": "Unregister a plugin at Adapt's remote registry. Specify as two arguments the current name of the plugin to be renamed and a new name. Please note that you must authenticate with GitHub to unregister and must be a collaborator on the endpoint registered with the plugin or a collaborator on the Adapt framework. Access to GitHub is for authentication only.",
|
4
|
-
"usage": [
|
5
|
-
"rename <plugin name> <new plugin name>"
|
6
|
-
]
|
7
|
-
}
|
1
|
+
{
|
2
|
+
"command": "rename",
|
3
|
+
"description": "Unregister a plugin at Adapt's remote registry. Specify as two arguments the current name of the plugin to be renamed and a new name. Please note that you must authenticate with GitHub to unregister and must be a collaborator on the endpoint registered with the plugin or a collaborator on the Adapt framework. Access to GitHub is for authentication only.",
|
4
|
+
"usage": [
|
5
|
+
"rename <plugin name> <new plugin name>"
|
6
|
+
]
|
7
|
+
}
|
package/json/help-search.json
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
{
|
2
|
-
"command": "search",
|
3
|
-
"description": "List out all the plugin(s) in adapt's remote registry or could also search a plugin with supplied partial name.",
|
4
|
-
"usage": [
|
5
|
-
"search",
|
6
|
-
"search <plugin-name>"
|
7
|
-
]
|
8
|
-
}
|
1
|
+
{
|
2
|
+
"command": "search",
|
3
|
+
"description": "List out all the plugin(s) in adapt's remote registry or could also search a plugin with supplied partial name.",
|
4
|
+
"usage": [
|
5
|
+
"search",
|
6
|
+
"search <plugin-name>"
|
7
|
+
]
|
8
|
+
}
|
package/json/help-uninstall.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
{
|
2
|
-
"command": "uninstall",
|
3
|
-
"description": "Remove a local plugin by its name.",
|
4
|
-
"usage": [
|
5
|
-
"uninstall <plugin-name>"
|
6
|
-
]
|
7
|
-
}
|
1
|
+
{
|
2
|
+
"command": "uninstall",
|
3
|
+
"description": "Remove a local plugin by its name.",
|
4
|
+
"usage": [
|
5
|
+
"uninstall <plugin-name>"
|
6
|
+
]
|
7
|
+
}
|
@@ -1,8 +1,8 @@
|
|
1
|
-
{
|
2
|
-
"command": "unregister",
|
3
|
-
"description": "Unregister a plugin at Adapt's remote registry. This command can be run without arguments in a directory which contains the bower.json file for the plugin to be unregistered. Alternatively, specify the name of the plugin as a single argument. Please note that you must authenticate with GitHub to unregister and must be a collaborator on the endpoint registered with the plugin or a collaborator on the Adapt framework. Access to GitHub is for authentication only.",
|
4
|
-
"usage": [
|
5
|
-
"unregister",
|
6
|
-
"unregister <plugin name>"
|
7
|
-
]
|
8
|
-
}
|
1
|
+
{
|
2
|
+
"command": "unregister",
|
3
|
+
"description": "Unregister a plugin at Adapt's remote registry. This command can be run without arguments in a directory which contains the bower.json file for the plugin to be unregistered. Alternatively, specify the name of the plugin as a single argument. Please note that you must authenticate with GitHub to unregister and must be a collaborator on the endpoint registered with the plugin or a collaborator on the Adapt framework. Access to GitHub is for authentication only.",
|
4
|
+
"usage": [
|
5
|
+
"unregister",
|
6
|
+
"unregister <plugin name>"
|
7
|
+
]
|
8
|
+
}
|
package/json/help-update.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
{
|
2
|
-
"command": "update",
|
3
|
-
"description": "Update plugins to their latest compatible version. You can also specify which plugins to update as arguments. When specifying arguments you can provide an optional semantic version (semver). Add the --check option for a summary of available updates for the given plugin(s). When using this option no changes are made. Ensure that there is no bower.json file in your project directory.",
|
4
|
-
"usage": [
|
5
|
-
"update [--check]",
|
6
|
-
"update <group> [<group> ..] where <group> is one of [components|extensions|menu|theme|all]",
|
7
|
-
"update <plugin-name>",
|
8
|
-
"update <plugin-name>#<semver>",
|
9
|
-
"update <plugin-name>@<semver>",
|
10
|
-
"update <target> [<target> ..] where target is the name of a plugin or group"
|
11
|
-
]
|
12
|
-
}
|
1
|
+
{
|
2
|
+
"command": "update",
|
3
|
+
"description": "Update plugins to their latest compatible version. You can also specify which plugins to update as arguments. When specifying arguments you can provide an optional semantic version (semver). Add the --check option for a summary of available updates for the given plugin(s). When using this option no changes are made. Ensure that there is no bower.json file in your project directory.",
|
4
|
+
"usage": [
|
5
|
+
"update [--check]",
|
6
|
+
"update <group> [<group> ..] where <group> is one of [components|extensions|menu|theme|all]",
|
7
|
+
"update <plugin-name>",
|
8
|
+
"update <plugin-name>#<semver>",
|
9
|
+
"update <plugin-name>@<semver>",
|
10
|
+
"update <target> [<target> ..] where target is the name of a plugin or group"
|
11
|
+
]
|
12
|
+
}
|
package/json/help-version.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
{
|
2
|
-
"command": "version",
|
3
|
-
"description": "Display version of adapt-cli.",
|
4
|
-
"usage": [
|
5
|
-
"version"
|
6
|
-
]
|
7
|
-
}
|
1
|
+
{
|
2
|
+
"command": "version",
|
3
|
+
"description": "Display version of adapt-cli.",
|
4
|
+
"usage": [
|
5
|
+
"version"
|
6
|
+
]
|
7
|
+
}
|
package/json/help.json
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
{
|
2
|
-
"usage": [
|
3
|
-
"<command>"
|
4
|
-
],
|
5
|
-
"commands": {
|
6
|
-
"create": "Create a new Adapt course or plugin",
|
7
|
-
"devinstall": "Get the framework and plugins as Git repository",
|
8
|
-
"help": "List out the commands available with adapt-cli",
|
9
|
-
"install": "Install plugin(s) within the Adapt course directory",
|
10
|
-
"ls": "List all the plugin names mentioned in adapt.json",
|
11
|
-
"rename": "Rename a plugin at the Adapt remote registry",
|
12
|
-
"register": "Register a plugin with the Adapt remote registry",
|
13
|
-
"search": "List/Search for plugin(s) at the Adapt remote registry",
|
14
|
-
"uninstall": "Remove a local plugin",
|
15
|
-
"unregister": "Unregister a plugin from the Adapt remote registry",
|
16
|
-
"update": "Update one or more plugins",
|
17
|
-
"version": "Display version of adapt-cli"
|
18
|
-
}
|
19
|
-
}
|
1
|
+
{
|
2
|
+
"usage": [
|
3
|
+
"<command>"
|
4
|
+
],
|
5
|
+
"commands": {
|
6
|
+
"create": "Create a new Adapt course or plugin",
|
7
|
+
"devinstall": "Get the framework and plugins as Git repository",
|
8
|
+
"help": "List out the commands available with adapt-cli",
|
9
|
+
"install": "Install plugin(s) within the Adapt course directory",
|
10
|
+
"ls": "List all the plugin names mentioned in adapt.json",
|
11
|
+
"rename": "Rename a plugin at the Adapt remote registry",
|
12
|
+
"register": "Register a plugin with the Adapt remote registry",
|
13
|
+
"search": "List/Search for plugin(s) at the Adapt remote registry",
|
14
|
+
"uninstall": "Remove a local plugin",
|
15
|
+
"unregister": "Unregister a plugin from the Adapt remote registry",
|
16
|
+
"update": "Update one or more plugins",
|
17
|
+
"version": "Display version of adapt-cli"
|
18
|
+
}
|
19
|
+
}
|
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
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
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
|
+
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
|
30
|
+
}
|
31
|
+
|
32
|
+
const translationTable = [
|
33
|
+
{ pattern: /^-v$|^--version$/i, replacement: 'version' },
|
34
|
+
{ pattern: /^upgrade$/i, replacement: 'update' }
|
35
|
+
]
|
36
|
+
|
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
|
+
}
|
52
|
+
|
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)
|
65
|
+
}
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
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
|
+
}
|