hammerjs-import.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. /**
  3. * @license
  4. * Copyright Google LLC All Rights Reserved.
  5. *
  6. * Use of this source code is governed by an MIT-style license that can be
  7. * found in the LICENSE file at https://angular.io/license
  8. */
  9. Object.defineProperty(exports, "__esModule", { value: true });
  10. const schematics_1 = require("@angular/cdk/schematics");
  11. const config_1 = require("@schematics/angular/utility/config");
  12. const hammerjsImportStatement = `import 'hammerjs';`;
  13. /** Adds HammerJS to the main file of the specified Angular CLI project. */
  14. function addHammerJsToMain(options) {
  15. return (host) => {
  16. const workspace = config_1.getWorkspace(host);
  17. const project = schematics_1.getProjectFromWorkspace(workspace, options.project);
  18. const mainFile = schematics_1.getProjectMainFile(project);
  19. const recorder = host.beginUpdate(mainFile);
  20. const buffer = host.read(mainFile);
  21. if (!buffer) {
  22. return console.error(`Could not read the project main file (${mainFile}). Please manually ` +
  23. `import HammerJS in your main TypeScript file.`);
  24. }
  25. const fileContent = buffer.toString('utf8');
  26. if (fileContent.includes(hammerjsImportStatement)) {
  27. return console.log(`HammerJS is already imported in the project main file (${mainFile}).`);
  28. }
  29. recorder.insertRight(0, `${hammerjsImportStatement}\n`);
  30. host.commitUpdate(recorder);
  31. };
  32. }
  33. exports.addHammerJsToMain = addHammerJsToMain;
  34. //# sourceMappingURL=hammerjs-import.js.map