UNPKG

@cypress/schematic

Version:
73 lines 3.32 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const schematics_1 = require("@angular-devkit/schematics"); const core_1 = require("@angular-devkit/core"); const utils_1 = require("../../utils"); function createSpec(tree) { return { readFile(path) { return __awaiter(this, void 0, void 0, function* () { const data = tree.read(path); if (!data) { throw new schematics_1.SchematicsException('File not found.'); } return core_1.virtualFs.fileBufferToString(data); }); }, writeFile(path, data) { return __awaiter(this, void 0, void 0, function* () { return tree.overwrite(path, data); }); }, isDirectory(path) { return __awaiter(this, void 0, void 0, function* () { return !tree.exists(path) && tree.getDir(path).subfiles.length > 0; }); }, isFile(path) { return __awaiter(this, void 0, void 0, function* () { return tree.exists(path); }); }, }; } function default_1(options) { return (tree) => __awaiter(this, void 0, void 0, function* () { const host = createSpec(tree); const { workspace } = yield core_1.workspaces.readWorkspace('/', host); const testType = options.component ? 'component' : 'e2e'; let project; if (!options.project) { project = workspace.projects.get(workspace.extensions.defaultProject); } else { project = workspace.projects.get(options.project); } if (!project) { throw new schematics_1.SchematicsException(`Invalid project name: ${options.project}`); } if (options.name === undefined) { throw new schematics_1.SchematicsException(`No file name specified. This is required to generate a new Cypress file.`); } if (options.path === undefined) { options.path = testType === 'component' ? `${project.sourceRoot}/${project.prefix}` : `${project.root}/cypress/e2e`; } console.log(`Creating new ${testType} spec named: ${options.name}`); const templatePath = testType === 'component' ? '../files/ct/__path__' : '../files/e2e/__path__'; const templateSource = (0, utils_1.createTemplate)({ templatePath, options }); return (0, schematics_1.chain)([ (0, schematics_1.mergeWith)(templateSource), ]); }); } exports.default = default_1; //# sourceMappingURL=index.js.map