hammerjs-import.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. /**
  3. * Use of this source code is governed by an MIT-style license that can be
  4. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  5. */
  6. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  7. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  8. return new (P || (P = Promise))(function (resolve, reject) {
  9. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  10. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  11. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  12. step((generator = generator.apply(thisArg, _arguments || [])).next());
  13. });
  14. };
  15. Object.defineProperty(exports, "__esModule", { value: true });
  16. exports.hammerjsImport = hammerjsImport;
  17. const schematics_1 = require("@angular/cdk/schematics");
  18. const workspace_1 = require("@schematics/angular/utility/workspace");
  19. const chalk_1 = require("chalk");
  20. const hammerjsImportStatement = `import 'hammerjs';`;
  21. /** Adds HammerJS to the main file of the specified Angular CLI project. */
  22. function hammerjsImport(options) {
  23. return (host) => __awaiter(this, void 0, void 0, function* () {
  24. const workspace = yield (0, workspace_1.getWorkspace)(host);
  25. const project = (0, schematics_1.getProjectFromWorkspace)(workspace, options.project);
  26. const mainFile = (0, schematics_1.getProjectMainFile)(project);
  27. const recorder = host.beginUpdate(mainFile);
  28. const buffer = host.read(mainFile);
  29. if (!buffer) {
  30. console.log();
  31. console.error((0, chalk_1.red)(`Could not read the project main file (${(0, chalk_1.blue)(mainFile)}). Please manually ` +
  32. `import HammerJS in your main TypeScript file.`));
  33. return;
  34. }
  35. const fileContent = buffer.toString('utf8');
  36. if (fileContent.includes(hammerjsImportStatement)) {
  37. console.log();
  38. console.log(`HammerJS is already imported in the project main file (${(0, chalk_1.blue)(mainFile)}).`);
  39. return;
  40. }
  41. recorder.insertRight(0, `${hammerjsImportStatement}\n`);
  42. host.commitUpdate(recorder);
  43. });
  44. }
  45. //# sourceMappingURL=hammerjs-import.js.map