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.
- package/.eslintignore +1 -0
- package/.eslintrc.json +14 -0
- package/README.md +150 -150
- package/bin/adapt.js +3 -0
- package/json/help-create/question.json +9 -0
- package/json/help-create.json +2 -1
- package/lib/api.js +260 -0
- package/lib/cli.js +61 -44
- package/lib/commands/authenticate.js +18 -0
- package/lib/commands/create/component.js +55 -72
- package/lib/commands/create/course.js +25 -80
- package/lib/commands/create/question.js +18 -0
- package/lib/commands/create.js +80 -85
- 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 +10 -195
- package/lib/commands/rename.js +13 -128
- package/lib/commands/search.js +10 -28
- package/lib/commands/uninstall.js +9 -136
- package/lib/commands/unregister.js +11 -95
- package/lib/commands/update.js +12 -867
- package/lib/commands/version.js +12 -14
- package/lib/integration/AdaptFramework/build.js +39 -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 +403 -0
- package/lib/integration/PluginManagement/autenticate.js +56 -0
- package/lib/integration/PluginManagement/install.js +222 -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 +296 -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 +20 -29
- 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/lib/PackageMeta.js
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
var bower = require('bower'),
|
2
|
-
Q = require('q');
|
3
|
-
|
4
|
-
module.exports = {
|
5
|
-
getKeywords: function (plugin, config) {
|
6
|
-
var deferred = Q.defer();
|
7
|
-
|
8
|
-
bower.commands.info(plugin.toString(), 'keywords', config || {})
|
9
|
-
.on('end', function(results) {
|
10
|
-
deferred.resolve(results);
|
11
|
-
})
|
12
|
-
.on('error', function(err) {
|
13
|
-
deferred.reject(err);
|
14
|
-
});
|
15
|
-
return deferred.promise;
|
16
|
-
},
|
17
|
-
getFrameworkCompatibility: function (plugin, config) {
|
18
|
-
var deferred = Q.defer();
|
19
|
-
var allVersions = '*';
|
20
|
-
|
21
|
-
bower.commands.info(plugin.toString(), 'framework', config || {})
|
22
|
-
.on('end', function(results) {
|
23
|
-
deferred.resolve(results || allVersions);
|
24
|
-
})
|
25
|
-
.on('error', function() {
|
26
|
-
deferred.resolve(allVersions);
|
27
|
-
});
|
28
|
-
return deferred.promise;
|
29
|
-
},
|
30
|
-
getRepositoryUrl: function (plugin, config) {
|
31
|
-
var deferred = Q.defer();
|
32
|
-
bower.commands.lookup(plugin.name, config || {})
|
33
|
-
.on('end', function(results) {
|
34
|
-
deferred.resolve(results);
|
35
|
-
})
|
36
|
-
.on('error', function(err) {
|
37
|
-
deferred.reject(err);
|
38
|
-
});
|
39
|
-
return deferred.promise;
|
40
|
-
}
|
41
|
-
};
|
package/lib/Plugin.js
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
var slug = require('./Slug'),
|
2
|
-
endpointParser = require('bower-endpoint-parser'),
|
3
|
-
zero = '0.0.0',
|
4
|
-
any = '*';
|
5
|
-
|
6
|
-
|
7
|
-
var Plugin = function(name, versionOrIsContrib, isContrib) {
|
8
|
-
this.name = name;
|
9
|
-
|
10
|
-
if(typeof isContrib === 'undefined') {
|
11
|
-
isContrib = false;
|
12
|
-
}
|
13
|
-
if(typeof versionOrIsContrib === 'undefined') {
|
14
|
-
isContrib = false;
|
15
|
-
this.version = any;
|
16
|
-
} else if(typeof versionOrIsContrib === 'boolean'){
|
17
|
-
isContrib = versionOrIsContrib;
|
18
|
-
this.version = any;
|
19
|
-
} else {
|
20
|
-
this.version = versionOrIsContrib === zero ? any : versionOrIsContrib;
|
21
|
-
}
|
22
|
-
this.packageName = makePackageName(name, isContrib);
|
23
|
-
|
24
|
-
Object.defineProperty(this, 'isContrib', {
|
25
|
-
get: function () {
|
26
|
-
return /^adapt-contrib/.test(this.packageName);
|
27
|
-
}
|
28
|
-
});
|
29
|
-
};
|
30
|
-
|
31
|
-
Plugin.prototype.toString = function() {
|
32
|
-
var version = '';
|
33
|
-
if(this.version !== any) {
|
34
|
-
version = '#'+ this.version;
|
35
|
-
}
|
36
|
-
return ''+this.packageName + version;
|
37
|
-
};
|
38
|
-
|
39
|
-
function makePackageName(name, isContrib) {
|
40
|
-
return (/^adapt-/i.test(name) ? '' : 'adapt-') + (!isContrib ? '' : 'contrib-') + slug(name);
|
41
|
-
}
|
42
|
-
|
43
|
-
Plugin.parse = function (endpoint) {
|
44
|
-
var ep = endpointParser.decompose(endpoint),
|
45
|
-
version = /^\*$/.test(ep.target) ? any : ep.target;
|
46
|
-
return new Plugin(ep.name || ep.source, version);
|
47
|
-
};
|
48
|
-
|
49
|
-
Plugin.compose = function (endpoint) {
|
50
|
-
return Plugin.parse(endpointParser.compose(endpoint));
|
51
|
-
};
|
52
|
-
|
53
|
-
module.exports = Plugin;
|
@@ -1,47 +0,0 @@
|
|
1
|
-
var PluginTypeResolver = function(types) {
|
2
|
-
this.types = types || [
|
3
|
-
{
|
4
|
-
pattern: /^adapt-component$/,
|
5
|
-
typename: 'component',
|
6
|
-
belongsTo: 'components'
|
7
|
-
},
|
8
|
-
{
|
9
|
-
pattern: /^adapt-extension$/,
|
10
|
-
typename: 'extension',
|
11
|
-
belongsTo: 'extensions'
|
12
|
-
},
|
13
|
-
{
|
14
|
-
pattern: /^adapt-menu$/,
|
15
|
-
typename: 'menu',
|
16
|
-
belongsTo: 'menu'
|
17
|
-
},
|
18
|
-
{
|
19
|
-
pattern: /^adapt-theme$/,
|
20
|
-
typename: 'theme',
|
21
|
-
belongsTo: 'theme'
|
22
|
-
}
|
23
|
-
];
|
24
|
-
this.defaultType = this.types[0];
|
25
|
-
};
|
26
|
-
PluginTypeResolver.prototype.resolve = function (keywords) {
|
27
|
-
keywords = Array.isArray(keywords) ? keywords : [keywords];
|
28
|
-
|
29
|
-
var types = keywords.map(toType(this.types))
|
30
|
-
.filter(NonMatchingKeywords);
|
31
|
-
|
32
|
-
return (types.length ? types[0] : this.defaultType);
|
33
|
-
};
|
34
|
-
module.exports = PluginTypeResolver;
|
35
|
-
|
36
|
-
function toType(types) {
|
37
|
-
return function (keyword) {
|
38
|
-
var typematches = types.filter(function (type) {
|
39
|
-
return type.pattern.test(keyword);
|
40
|
-
});
|
41
|
-
if(typematches.length) return typematches[0];
|
42
|
-
}
|
43
|
-
}
|
44
|
-
|
45
|
-
function NonMatchingKeywords(item) {
|
46
|
-
return item !== undefined
|
47
|
-
}
|
package/lib/Project.js
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
var Plugin = require('./Plugin'),
|
2
|
-
fs = require('fs'),
|
3
|
-
_ = require('lodash'),
|
4
|
-
JsonLoader = require('./JsonLoader'),
|
5
|
-
JsonWriter = require('./JsonWriter'),
|
6
|
-
chalk = require('chalk'),
|
7
|
-
renderer = require('./ConsoleRenderer'),
|
8
|
-
EmptyProject = function (){
|
9
|
-
return {
|
10
|
-
dependencies: {}
|
11
|
-
};
|
12
|
-
};
|
13
|
-
EmptyPackage = function () {
|
14
|
-
return { "version": "0.0.0" };
|
15
|
-
};
|
16
|
-
|
17
|
-
var Project = function (manifestFilePath, frameworkPackagePath) {
|
18
|
-
this.manifestFilePath = manifestFilePath;
|
19
|
-
this.frameworkPackagePath = frameworkPackagePath;
|
20
|
-
Object.defineProperty(this, 'plugins', {
|
21
|
-
get: function () {
|
22
|
-
var manifest = parse(this.manifestFilePath);
|
23
|
-
return _.toPairs(manifest.dependencies)
|
24
|
-
.map(function (pair) {
|
25
|
-
return new Plugin(pair[0], pair[1]);
|
26
|
-
});
|
27
|
-
}.bind(this)
|
28
|
-
});
|
29
|
-
};
|
30
|
-
|
31
|
-
Project.prototype.add = function (plugin) {
|
32
|
-
if(typeof Plugin !== 'object' && plugin.constructor !== Plugin) {
|
33
|
-
plugin = new Plugin(plugin);
|
34
|
-
}
|
35
|
-
var manifest;
|
36
|
-
if(this.isProjectContainsManifestFile()) {
|
37
|
-
manifest = parse(this.manifestFilePath);
|
38
|
-
} else {
|
39
|
-
manifest = EmptyProject();
|
40
|
-
}
|
41
|
-
manifest.dependencies[plugin.packageName] = plugin.version;
|
42
|
-
save(this.manifestFilePath, manifest);
|
43
|
-
};
|
44
|
-
|
45
|
-
Project.prototype.remove = function (plugin) {
|
46
|
-
if(typeof Plugin !== 'object' && plugin.constructor !== Plugin) {
|
47
|
-
plugin = new Plugin(plugin);
|
48
|
-
}
|
49
|
-
var manifest = parse(this.manifestFilePath);
|
50
|
-
delete manifest.dependencies[plugin.packageName];
|
51
|
-
save(this.manifestFilePath, manifest);
|
52
|
-
};
|
53
|
-
|
54
|
-
Project.prototype.getFrameworkVersion = function () {
|
55
|
-
return parsePackage(this.frameworkPackagePath).version;
|
56
|
-
};
|
57
|
-
|
58
|
-
Project.prototype.isProjectContainsManifestFile = function() {
|
59
|
-
return fs.existsSync(this.manifestFilePath);
|
60
|
-
};
|
61
|
-
|
62
|
-
function parse(manifestFilePath) {
|
63
|
-
if(!manifestFilePath) return EmptyProject();
|
64
|
-
|
65
|
-
return JsonLoader.readJSONSync(manifestFilePath);
|
66
|
-
}
|
67
|
-
|
68
|
-
function parsePackage(frameworkPackagePath) {
|
69
|
-
var EmptyPackage = function () {
|
70
|
-
return { "version": "0.0.0" }
|
71
|
-
};
|
72
|
-
|
73
|
-
if(!frameworkPackagePath) return EmptyPackage();
|
74
|
-
|
75
|
-
try {
|
76
|
-
return JsonLoader.readJSONSync(frameworkPackagePath);
|
77
|
-
}
|
78
|
-
catch (ex) {
|
79
|
-
return EmptyPackage();
|
80
|
-
}
|
81
|
-
}
|
82
|
-
|
83
|
-
function save(manifestFilePath, manifest) {
|
84
|
-
if(manifestFilePath) {
|
85
|
-
JsonWriter.writeJSONSync(manifestFilePath, manifest);
|
86
|
-
}
|
87
|
-
}
|
88
|
-
|
89
|
-
module.exports = Project;
|
package/lib/RendererHelpers.js
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
var chalk = require('chalk'),
|
2
|
-
inquirer = require('inquirer'),
|
3
|
-
Q = require('q');
|
4
|
-
|
5
|
-
module.exports = {
|
6
|
-
reportCompatibilityWarning : function (renderer, plugin) {
|
7
|
-
renderer.log(chalk.yellow('The plugin'), chalk.white(plugin), chalk.yellow('is not compatible with this version of Adapt.', 'Installing it may cause unexpected behaviour.'));
|
8
|
-
return confirm(plugin);
|
9
|
-
},
|
10
|
-
reportFailure : function (renderer, done) {
|
11
|
-
return function (err) {
|
12
|
-
renderer.log(chalk.red('Oh dear, something went wrong.'), err.message);
|
13
|
-
done(err);
|
14
|
-
};
|
15
|
-
},
|
16
|
-
reportInvalidFrameworkDirectory : function (renderer, done) {
|
17
|
-
return function (err) {
|
18
|
-
renderer.log(chalk.red('Fatal error: please run above commands in adapt course directory.'));
|
19
|
-
done(err);
|
20
|
-
};
|
21
|
-
},
|
22
|
-
};
|
23
|
-
|
24
|
-
function confirm(plugin) {
|
25
|
-
var deferred = Q.defer();
|
26
|
-
var schema = [
|
27
|
-
{
|
28
|
-
name: 'continueWithInstall',
|
29
|
-
message: 'Install this plugin anyway?',
|
30
|
-
type: 'confirm',
|
31
|
-
default: false
|
32
|
-
}
|
33
|
-
];
|
34
|
-
inquirer.prompt(schema).then(properties => {
|
35
|
-
deferred.resolve({
|
36
|
-
plugin: plugin,
|
37
|
-
continueWithInstall: properties.continueWithInstall
|
38
|
-
});
|
39
|
-
}).catch(err => deferred.reject(err));
|
40
|
-
return deferred.promise;
|
41
|
-
}
|
@@ -1,64 +0,0 @@
|
|
1
|
-
var Constants = require('./Constants'),
|
2
|
-
urljoin = require('url-join'),
|
3
|
-
path = require('path'),
|
4
|
-
Q = require('q');
|
5
|
-
|
6
|
-
var RepositoryDownloader = function(options) {
|
7
|
-
if (!options.branch && !options.repository)
|
8
|
-
throw new Error('Repository details are required.');
|
9
|
-
this.options = options;
|
10
|
-
|
11
|
-
Object.defineProperty(this, 'url', {
|
12
|
-
get: function() {
|
13
|
-
return urljoin(this.options.repository, 'archive', this.options.branch + '.zip');
|
14
|
-
}
|
15
|
-
});
|
16
|
-
};
|
17
|
-
|
18
|
-
RepositoryDownloader.prototype.fetch = function(destination) {
|
19
|
-
var deferred = Q.defer(),
|
20
|
-
download = require('download'),
|
21
|
-
previousPercent = 0,
|
22
|
-
fileName = '';
|
23
|
-
|
24
|
-
download(this.url, destination, {
|
25
|
-
extract: true
|
26
|
-
})
|
27
|
-
.on('response', function (response) {
|
28
|
-
fileName = getFileName(response.headers['content-disposition']);
|
29
|
-
})
|
30
|
-
.on('downloadProgress', function(progress) {
|
31
|
-
var state = {
|
32
|
-
receivedSize: progress.transferred,
|
33
|
-
percent: Math.round(progress.transferred / progress.total * 100)
|
34
|
-
};
|
35
|
-
|
36
|
-
if(state.percent > previousPercent) {
|
37
|
-
previousPercent = state.percent;
|
38
|
-
deferred.notify(state, progress);
|
39
|
-
}
|
40
|
-
})
|
41
|
-
.on('error', function(err) {
|
42
|
-
deferred.reject(err);
|
43
|
-
})
|
44
|
-
.then(function() {
|
45
|
-
deferred.resolve(fileName);
|
46
|
-
});
|
47
|
-
|
48
|
-
return deferred.promise;
|
49
|
-
};
|
50
|
-
|
51
|
-
function getFileName(disposition) {
|
52
|
-
var fileName = "";
|
53
|
-
if (disposition && disposition.indexOf('attachment') !== -1) {
|
54
|
-
var regex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
|
55
|
-
var matches = regex.exec(disposition);
|
56
|
-
if (matches != null && matches[1]) {
|
57
|
-
fileName = matches[1].replace(/['"]/g, '');
|
58
|
-
}
|
59
|
-
}
|
60
|
-
return fileName;
|
61
|
-
}
|
62
|
-
|
63
|
-
module.exports = RepositoryDownloader;
|
64
|
-
|
package/lib/Slug.js
DELETED
package/lib/VersionChecker.js
DELETED
package/lib/commands/index.js
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
var _ = require('lodash'),
|
2
|
-
fs = require('fs'),
|
3
|
-
commands = {},
|
4
|
-
files = fs.readdirSync(__dirname);
|
5
|
-
|
6
|
-
module.exports = files.filter(excludeIndex).reduce(function (commands, filename) {
|
7
|
-
var useDefaultDependencies = {},
|
8
|
-
command = require('./' + filename);
|
9
|
-
|
10
|
-
if(typeof command === 'function') command = command(useDefaultDependencies);
|
11
|
-
return _.extend(commands, command);
|
12
|
-
}, {});
|
13
|
-
|
14
|
-
function excludeIndex (filename) {
|
15
|
-
return !/^index.js$/.test(filename);
|
16
|
-
}
|
@@ -1,32 +0,0 @@
|
|
1
|
-
var readline = require('readline');
|
2
|
-
|
3
|
-
var isLoggingProgress = false;
|
4
|
-
var lastProgressStr = '';
|
5
|
-
|
6
|
-
module.exports = {
|
7
|
-
logProgress:function(str) {
|
8
|
-
lastProgressStr = str;
|
9
|
-
isLoggingProgress = true;
|
10
|
-
readline.cursorTo(process.stdout, 0);
|
11
|
-
process.stdout.write(str);
|
12
|
-
},
|
13
|
-
|
14
|
-
logProgressConclusion(str) {
|
15
|
-
lastProgressStr = str;
|
16
|
-
isLoggingProgress = false;
|
17
|
-
readline.cursorTo(process.stdout, 0);
|
18
|
-
process.stdout.write(str);
|
19
|
-
process.stdout.write('\n');
|
20
|
-
},
|
21
|
-
|
22
|
-
log:function() {
|
23
|
-
if (isLoggingProgress) {
|
24
|
-
readline.clearLine(process.stdout, 0);
|
25
|
-
readline.cursorTo(process.stdout, 0);
|
26
|
-
console.log.apply(console, arguments);
|
27
|
-
this.logProgress(lastProgressStr);
|
28
|
-
} else {
|
29
|
-
console.log.apply(console, arguments);
|
30
|
-
}
|
31
|
-
}
|
32
|
-
}
|
@@ -1,259 +0,0 @@
|
|
1
|
-
var bower = require('bower'),
|
2
|
-
_ = require('lodash'),
|
3
|
-
Q = require('q'),
|
4
|
-
readline = require('readline'),
|
5
|
-
endpointParser = require('bower-endpoint-parser'),
|
6
|
-
semver = require('semver'),
|
7
|
-
Plugin = require('../../Plugin'),
|
8
|
-
InstallLog = require('./InstallLog'),
|
9
|
-
Constants = require('../../Constants'),
|
10
|
-
extend = require('./extend');
|
11
|
-
|
12
|
-
var any = '*';
|
13
|
-
var BOWER_MAX_TRY = 5;
|
14
|
-
|
15
|
-
var InstallTarget = extend(Plugin, {
|
16
|
-
|
17
|
-
constructor: function(name, requestedVersion, isCompatibleEnabled) {
|
18
|
-
var endpoint = name+'#'+(isCompatibleEnabled ? any : requestedVersion),
|
19
|
-
ep = endpointParser.decompose(endpoint),
|
20
|
-
version = /^\*$/.test(ep.target) ? any : ep.target,
|
21
|
-
proposal;
|
22
|
-
|
23
|
-
Plugin.call(this, ep.name || ep.source, version);
|
24
|
-
|
25
|
-
if (this.version !== any) {
|
26
|
-
proposal = this.version;
|
27
|
-
this._isConstrained = true;
|
28
|
-
this.version = semver.validRange(proposal);
|
29
|
-
|
30
|
-
if (!this.version) {
|
31
|
-
throw new Error(this.packageName+' "'+proposal+'" is not a valid constraint');
|
32
|
-
}
|
33
|
-
}
|
34
|
-
|
35
|
-
// the constraint given by the user
|
36
|
-
this._requestedVersion = requestedVersion;
|
37
|
-
// the result of the current query to the server
|
38
|
-
this._rawInfo = undefined;
|
39
|
-
// information about a particular version of the plugin
|
40
|
-
this._versionInfo = undefined;
|
41
|
-
// the number of attempts made to query the server
|
42
|
-
this._bowerCmdCount = 0;
|
43
|
-
// a list of tags denoting the versions of the plugin
|
44
|
-
this._versions = undefined;
|
45
|
-
// an index denoting which version is being queried
|
46
|
-
this._versionIndex = 0;
|
47
|
-
// whether querying the server for plugin information failed at all
|
48
|
-
this._isMissingAtRepo = false;
|
49
|
-
// the most recent version of the plugin compatible with the given framework
|
50
|
-
this._latestCompatibleVersion = undefined;
|
51
|
-
// the most recent version of the plugin
|
52
|
-
this._latestVersion = undefined;
|
53
|
-
// whether the user supplied a constraint that is not supported by the plugin
|
54
|
-
this._isBadConstraint = false;
|
55
|
-
// whether the constraint has been checked for compatibility
|
56
|
-
this._constraintChecked = false;
|
57
|
-
// a non-wildcard constraint resolved to the highest version of the plugin that satisfies the constraint and is compatible with the framework
|
58
|
-
this._resolvedConstraint = undefined;
|
59
|
-
// the version to be installed
|
60
|
-
this._versionToInstall = undefined;
|
61
|
-
},
|
62
|
-
|
63
|
-
getInitialInfo: function() {
|
64
|
-
return this.getInfo().then(_.bind(processInfo, this));
|
65
|
-
|
66
|
-
function processInfo() {
|
67
|
-
if (!this._isMissingAtRepo) {
|
68
|
-
this._latestVersion = this._versionInfo.version;
|
69
|
-
|
70
|
-
if (this._rawInfo.versions) {
|
71
|
-
this._versions = this._rawInfo.versions;
|
72
|
-
if (this._versions.length > 0) {
|
73
|
-
// check if the user supplied a constraint that cannot be met
|
74
|
-
this._isBadConstraint = semver.maxSatisfying(this._versions, this.version) === null;
|
75
|
-
}
|
76
|
-
}
|
77
|
-
}
|
78
|
-
}
|
79
|
-
},
|
80
|
-
|
81
|
-
getInfo: function(deferred) {
|
82
|
-
// presence of deferred signifies a retry
|
83
|
-
if (!deferred) this._bowerCmdCount = 0;
|
84
|
-
|
85
|
-
deferred = deferred || Q.defer();
|
86
|
-
|
87
|
-
try {
|
88
|
-
var versionString = this._versions ? '#'+this._versions[this._versionIndex] : '';
|
89
|
-
this._bowerCmdCount++;
|
90
|
-
bower.commands.info(this.packageName+versionString, null, {registry:Constants.getRegistry(), cwd: Constants.cwd}).on('end', _.bind(onSuccess, this)).on('error', _.bind(onFail, this));
|
91
|
-
} catch(err) {
|
92
|
-
onFail.call(this, err);
|
93
|
-
}
|
94
|
-
|
95
|
-
function onSuccess(results) {
|
96
|
-
this._rawInfo = results;
|
97
|
-
this._versionInfo = results.latest || results;
|
98
|
-
deferred.notify();
|
99
|
-
deferred.resolve(results);
|
100
|
-
}
|
101
|
-
|
102
|
-
function onFail() {
|
103
|
-
if (this._bowerCmdCount < BOWER_MAX_TRY) {
|
104
|
-
this.getInfo(deferred);
|
105
|
-
} else {
|
106
|
-
this._isMissingAtRepo = true;
|
107
|
-
deferred.notify();
|
108
|
-
deferred.resolve();
|
109
|
-
}
|
110
|
-
}
|
111
|
-
|
112
|
-
return deferred.promise;
|
113
|
-
},
|
114
|
-
|
115
|
-
findCompatibleVersion: function(framework) {
|
116
|
-
if (this._isMissingAtRepo) return Q.resolve();
|
117
|
-
|
118
|
-
// check if the latest version is compatible
|
119
|
-
if (semver.satisfies(framework, this._versionInfo.framework)) {
|
120
|
-
this._latestCompatibleVersion = this._versionInfo.version || '*';
|
121
|
-
return Q.resolve();
|
122
|
-
}
|
123
|
-
|
124
|
-
// if the plugin has no tags then there are no other versions to check
|
125
|
-
if (!this._versions || this._versions.length == 0) return Q.resolve();
|
126
|
-
|
127
|
-
this._versionIndex = 0;
|
128
|
-
|
129
|
-
return this.checkProposedVersion(framework);
|
130
|
-
},
|
131
|
-
|
132
|
-
checkConstraint: function(framework) {
|
133
|
-
// check that the plugin exists
|
134
|
-
if (this._isMissingAtRepo) {
|
135
|
-
this._constraintChecked = true;
|
136
|
-
//InstallLog.log(this.packageName, 'cannot resolve constraint due to missing info');
|
137
|
-
return Q.resolve();
|
138
|
-
}
|
139
|
-
|
140
|
-
// check that there are other versions to be considered
|
141
|
-
if (!this._versions || this._versions.length == 0) {
|
142
|
-
this._constraintChecked = true;
|
143
|
-
//InstallLog.log(this.packageName, 'cannot resolve constraint because there are no tags');
|
144
|
-
return Q.resolve();
|
145
|
-
}
|
146
|
-
|
147
|
-
// check that a valid constraint exists
|
148
|
-
if (this.version == any || this._isBadConstraint) {
|
149
|
-
this._constraintChecked = true;
|
150
|
-
//InstallLog.log(this.packageName, 'cannot resolve constraint because a valid constraint has not been given');
|
151
|
-
return Q.resolve();
|
152
|
-
}
|
153
|
-
|
154
|
-
this._versionIndex = 0;
|
155
|
-
|
156
|
-
return this.getInfo().then(_.bind(function() {
|
157
|
-
return this.checkConstraintCompatibility(framework);
|
158
|
-
}, this));
|
159
|
-
},
|
160
|
-
|
161
|
-
// find the highest version that satisfies the constraint and is compatible with the framework
|
162
|
-
checkConstraintCompatibility: function(framework, deferred) {
|
163
|
-
deferred = deferred || Q.defer();
|
164
|
-
|
165
|
-
// give up if there is any failure to obtain version info
|
166
|
-
if (this._isMissingAtRepo) {
|
167
|
-
this._constraintChecked = true;
|
168
|
-
//InstallLog.log(this.packageName, 'cannot resolve constraint due to missing info');
|
169
|
-
deferred.notify();
|
170
|
-
deferred.resolve();
|
171
|
-
return deferred.promise;
|
172
|
-
}
|
173
|
-
|
174
|
-
//InstallLog.log(this.packageName, 'checking', this._versionInfo.version, 'against', this.version, 'framework', framework);
|
175
|
-
|
176
|
-
// check if the version satisfies the constraint and whether the version is compatible
|
177
|
-
if (semver.satisfies(this._versionInfo.version, this.version) && semver.satisfies(framework, this._versionInfo.framework)) {
|
178
|
-
this._resolvedConstraint = this._versionInfo.version;
|
179
|
-
this._constraintChecked = true;
|
180
|
-
//InstallLog.log(this.packageName, 'resolved constraint to', this._resolvedConstraint);
|
181
|
-
deferred.notify();
|
182
|
-
deferred.resolve();
|
183
|
-
} else {
|
184
|
-
if (this._versionIndex + 1 < this._versions.length) {
|
185
|
-
this._versionIndex++;
|
186
|
-
|
187
|
-
this.getInfo().then(_.bind(function() {
|
188
|
-
return this.checkConstraintCompatibility(framework, deferred);
|
189
|
-
}, this));
|
190
|
-
|
191
|
-
} else {
|
192
|
-
this._resolvedConstraint = null;
|
193
|
-
this._constraintChecked = true;
|
194
|
-
//InstallLog.log(this.packageName, 'cannot resolve constraint');
|
195
|
-
deferred.notify();
|
196
|
-
deferred.resolve();
|
197
|
-
}
|
198
|
-
}
|
199
|
-
|
200
|
-
return deferred.promise;
|
201
|
-
},
|
202
|
-
|
203
|
-
// find the highest version that is compatible with the framework
|
204
|
-
checkProposedVersion: function(framework, deferred) {
|
205
|
-
deferred = deferred || Q.defer();
|
206
|
-
|
207
|
-
// give up if there is any failure to obtain version info
|
208
|
-
if (this._isMissingAtRepo) {
|
209
|
-
this._latestCompatibleVersion = null;
|
210
|
-
deferred.notify();
|
211
|
-
deferred.resolve();
|
212
|
-
return deferred.promise;
|
213
|
-
}
|
214
|
-
|
215
|
-
// check that the proposed plugin is compatible with the installed framework
|
216
|
-
if (semver.satisfies(framework, this._versionInfo.framework)) {
|
217
|
-
this._latestCompatibleVersion = this._versionInfo.version;
|
218
|
-
deferred.notify();
|
219
|
-
deferred.resolve();
|
220
|
-
} else {
|
221
|
-
if (this._versionIndex + 1 < this._versions.length) {
|
222
|
-
this._versionIndex++;
|
223
|
-
|
224
|
-
this.getInfo().then(_.bind(function() {
|
225
|
-
this.checkProposedVersion(framework, deferred);
|
226
|
-
}, this));
|
227
|
-
|
228
|
-
} else {
|
229
|
-
this._latestCompatibleVersion = null;
|
230
|
-
deferred.notify();
|
231
|
-
deferred.resolve();
|
232
|
-
}
|
233
|
-
}
|
234
|
-
|
235
|
-
return deferred.promise;
|
236
|
-
},
|
237
|
-
|
238
|
-
markRequestedForInstallation:function() {
|
239
|
-
if (this._resolvedConstraint != undefined && this._resolvedConstraint != null) {
|
240
|
-
this._versionToInstall = this._resolvedConstraint;
|
241
|
-
} else {
|
242
|
-
this._versionToInstall = semver.maxSatisfying(this._versions, this.version);
|
243
|
-
}
|
244
|
-
},
|
245
|
-
|
246
|
-
markLatestCompatibleForInstallation:function() {
|
247
|
-
this._versionToInstall = this._latestCompatibleVersion;
|
248
|
-
},
|
249
|
-
|
250
|
-
markLatestForInstallation:function() {
|
251
|
-
this._versionToInstall = this._latestVersion;
|
252
|
-
},
|
253
|
-
|
254
|
-
logToConsole:function() {
|
255
|
-
console.log(this.packageName, this.version, this._versionInfo ? this._versionInfo.framework : 'missing');
|
256
|
-
}
|
257
|
-
});
|
258
|
-
|
259
|
-
module.exports = InstallTarget;
|