refactor(docs-infra): minor refactorings and code simplification in `NgPackagesInstaller` (#31985)
PR Close #31985
This commit is contained in:
parent
7db269ba6a
commit
bc8eb8508b
|
@ -29,12 +29,10 @@ class NgPackagesInstaller {
|
||||||
* Create a new installer for a project in the specified directory.
|
* Create a new installer for a project in the specified directory.
|
||||||
*
|
*
|
||||||
* @param {string} projectDir - the path to the directory containing the project.
|
* @param {string} projectDir - the path to the directory containing the project.
|
||||||
* @param {object} options - a hash of options for the install
|
* @param {object} options - a hash of options for the install:
|
||||||
* * `debug` (`boolean`) - whether to display debug messages.
|
* * `debug` (`boolean`) - whether to display debug messages.
|
||||||
* * `force` (`boolean`) - whether to force a local installation
|
* * `force` (`boolean`) - whether to force a local installation even if there is a local marker file.
|
||||||
* even if there is a local marker file.
|
* * `ignorePackages` (`string[]`) - a collection of names of packages that should not be copied over.
|
||||||
* * `ignorePackages` (`string[]`) - a collection of names of packages
|
|
||||||
* that should not be copied over.
|
|
||||||
*/
|
*/
|
||||||
constructor(projectDir, options = {}) {
|
constructor(projectDir, options = {}) {
|
||||||
this.debug = options.debug;
|
this.debug = options.debug;
|
||||||
|
@ -184,13 +182,14 @@ class NgPackagesInstaller {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A hash of Angular package configs.
|
* A hash of Angular package configs.
|
||||||
* (Detected as directories in '/packages/' that contain a top-level 'package.json' file.)
|
* (Detected as directories in '/dist/packages-dist/' that contain a top-level 'package.json' file.)
|
||||||
*/
|
*/
|
||||||
_getDistPackages() {
|
_getDistPackages() {
|
||||||
const packageConfigs = Object.create(null);
|
const packageConfigs = Object.create(null);
|
||||||
|
const distDir = ANGULAR_DIST_PACKAGES;
|
||||||
|
|
||||||
[ANGULAR_DIST_PACKAGES].forEach(distDir => {
|
|
||||||
this._log(`Angular distributable directory: ${distDir}.`);
|
this._log(`Angular distributable directory: ${distDir}.`);
|
||||||
|
|
||||||
shelljs
|
shelljs
|
||||||
.find(distDir)
|
.find(distDir)
|
||||||
.map(filePath => filePath.slice(distDir.length + 1))
|
.map(filePath => filePath.slice(distDir.length + 1))
|
||||||
|
@ -209,8 +208,6 @@ class NgPackagesInstaller {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
this._log('Found the following Angular distributables:', Object.keys(packageConfigs).map(key => `\n - ${key}`));
|
this._log('Found the following Angular distributables:', Object.keys(packageConfigs).map(key => `\n - ${key}`));
|
||||||
return packageConfigs;
|
return packageConfigs;
|
||||||
}
|
}
|
||||||
|
@ -287,6 +284,11 @@ class NgPackagesInstaller {
|
||||||
function main() {
|
function main() {
|
||||||
shelljs.set('-e');
|
shelljs.set('-e');
|
||||||
|
|
||||||
|
const createInstaller = argv => {
|
||||||
|
const {projectDir, ...options} = argv;
|
||||||
|
return new NgPackagesInstaller(projectDir, options);
|
||||||
|
};
|
||||||
|
|
||||||
yargs
|
yargs
|
||||||
.usage('$0 <cmd> [args]')
|
.usage('$0 <cmd> [args]')
|
||||||
|
|
||||||
|
@ -295,16 +297,13 @@ function main() {
|
||||||
.option('ignore-packages', { describe: 'List of Angular packages that should not be used in local mode.', default: [], array: true })
|
.option('ignore-packages', { describe: 'List of Angular packages that should not be used in local mode.', default: [], array: true })
|
||||||
|
|
||||||
.command('overwrite <projectDir> [--force] [--debug] [--ignore-packages package1 package2]', 'Install dependencies from the locally built Angular distributables.', () => {}, argv => {
|
.command('overwrite <projectDir> [--force] [--debug] [--ignore-packages package1 package2]', 'Install dependencies from the locally built Angular distributables.', () => {}, argv => {
|
||||||
const installer = new NgPackagesInstaller(argv.projectDir, argv);
|
createInstaller(argv).installLocalDependencies();
|
||||||
installer.installLocalDependencies();
|
|
||||||
})
|
})
|
||||||
.command('restore <projectDir> [--debug]', 'Install dependencies from the npm registry.', () => {}, argv => {
|
.command('restore <projectDir> [--debug]', 'Install dependencies from the npm registry.', () => {}, argv => {
|
||||||
const installer = new NgPackagesInstaller(argv.projectDir, argv);
|
createInstaller(argv).restoreNpmDependencies();
|
||||||
installer.restoreNpmDependencies();
|
|
||||||
})
|
})
|
||||||
.command('check <projectDir> [--debug]', 'Check that dependencies came from npm. Otherwise display a warning message.', () => {}, argv => {
|
.command('check <projectDir> [--debug]', 'Check that dependencies came from npm. Otherwise display a warning message.', () => {}, argv => {
|
||||||
const installer = new NgPackagesInstaller(argv.projectDir, argv);
|
createInstaller(argv).checkDependencies();
|
||||||
installer.checkDependencies();
|
|
||||||
})
|
})
|
||||||
.demandCommand(1, 'Please supply a command from the list above.')
|
.demandCommand(1, 'Please supply a command from the list above.')
|
||||||
.strict()
|
.strict()
|
||||||
|
|
Loading…
Reference in New Issue