"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.oneTimePackages = oneTimePackages;
const tasks_1 = require("@angular-devkit/schematics/tasks");
const dependencies_1 = require("@schematics/angular/utility/dependencies");
/**
 * Adds the packages to the project temporarily.
 * @param packagesToInstall
 */
function oneTimePackages(packagesToInstall) {
    const packages = [];
    return [
        (tree, context) => {
            packagesToInstall.forEach((packageName) => {
                const packageVersion = (0, dependencies_1.getPackageJsonDependency)(tree, packageName);
                if (!packageVersion) {
                    (0, dependencies_1.addPackageJsonDependency)(tree, {
                        type: dependencies_1.NodeDependencyType.Dev,
                        name: packageName,
                        version: 'latest'
                    });
                    packages.push(packageName);
                }
            });
            if (packages.length) {
                context.addTask(new tasks_1.NodePackageInstallTask());
            }
        },
        (tree, context) => {
            if (packages.length) {
                packages.forEach((packageName) => {
                    (0, dependencies_1.removePackageJsonDependency)(tree, packageName);
                });
                context.addTask(new tasks_1.NodePackageInstallTask());
            }
        }
    ];
}
//# sourceMappingURL=one-time-packages.js.map