text: "use strict";
  // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
  // See LICENSE in the project root for license information.
  Object.defineProperty(exports, "__esModule", { value: true });
  const GulpTask_1 = require("./GulpTask");
  const child_process = require("child_process");
  const rimraf = require("rimraf");
  const os = require("os");
  const path = require("path");
  /**
   * This provides a convenient way to more consistently generate a shrinkwrap file in
   * a desired manner as a gulp task, as there are many consistency issues with just
   * running npm-shrinkwrap directly.
   * @public
   */
  class GenerateShrinkwrapTask extends GulpTask_1.GulpTask {
      /**
       * Instantiates a GenerateShrinkwrap task which will regenerate the shrinkwrap for a particular project
       */
      constructor() {
          super('generate-shrinkwrap');
      }
      /**
       * Runs npm `prune` and `update` on a package before running `shrinkwrap --dev`
       */
      executeTask(gulp, completeCallback) {
          const pathToShrinkwrap = path.join(this.buildConfig.rootPath, 'npm-shrinkwrap.json');
          if (this.fileExists(pathToShrinkwrap)) {
              this.log(`Remove existing shrinkwrap file.`);
              this._dangerouslyDeletePath(pathToShrinkwrap);
          }
          this.log(`Running npm prune`);
          child_process.execSync('npm prune');
          this.log(`Running npm update`);
          child_process.execSync('npm update');
          this.log(`Running npm shrinkwrap --dev`);
          child_process.execSync('npm shrinkwrap --dev');
          completeCallback();
          return;
      }
      _dangerouslyDeletePath(folderPath) {
          try {
              rimraf.sync(folderPath);
          }
          catch (e) {
              throw new Error(`${e.message}${os.EOL}Often this is caused by a file lock from a process
         such as your text editor, command prompt, or "gulp serve"`);
          }
      }
  }
  exports.GenerateShrinkwrapTask = GenerateShrinkwrapTask;
  
  //# sourceMappingURL=GenerateShrinkwrapTask.js.map
  