UNPKG

@nstudio/schematics

Version:

Cross-platform (xplat) tools for Nx workspaces.

114 lines 4.66 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const fs = require("fs"); const path = require("path"); const util_1 = require("util"); const fsExists = util_1.promisify(fs.exists); const fsWriteFile = util_1.promisify(fs.writeFile); const fsReadFile = util_1.promisify(fs.readFile); function updateConfig() { return __awaiter(this, void 0, void 0, function* () { const cwd = process.cwd(); if (cwd.indexOf('node_modules/@nstudio/schematics') === -1 && cwd.indexOf('node_modules\\@nstudio\\schematics') === -1) { // ignore: local development return; } const ngCliConfigPath = path.join(process.cwd(), '/../../..', 'angular.json'); // console.log(ngCliConfigPath); try { const config = fs.readFileSync(ngCliConfigPath, 'UTF-8'); if (config) { const ngCli = JSON.parse(config); // update default ngCli.cli.defaultCollection = "@nstudio/schematics"; fs.writeFileSync(ngCliConfigPath, JSON.stringify(ngCli, null, 2)); } } catch (err) { console.warn('An issue was detected during installation: angular.json does not exist.'); } try { // Prevent Nrwl formatter from walking into {N} platforms folder yield fixFormatter(); } catch (err) { console.error('An issue were detected during patching the nx-formatter', err); } try { yield makePrettierIgnore(); } catch (err) { console.error('An issue were detected during patching the nx-formatter', err); } }); } exports.updateConfig = updateConfig; /** * @nrwl/nx's formatter doesn't include files in the xplat-folder. * This function patches their formatter cli to include the xplat-folder */ function fixFormatter() { return __awaiter(this, void 0, void 0, function* () { const formatPath = path.join(process.cwd(), '/../..', '@nrwl/schematics/src/command-line/format.js'); let formatContent = yield fsReadFile(formatPath, 'UTF-8'); const patchLine = ` // PATCHED by @nstudio/schematics\n patterns.push('"xplat/**/*"');`; if (formatContent.indexOf(patchLine) !== -1) { console.log(`Patch for nx format have already been applied`); return; } const patchRegExp = /(^\s+var chunkList)/m; if (!patchRegExp.test(formatContent)) { throw new Error(`Apply couldn't patch for nx format`); } const newFormatContent = formatContent.replace(patchRegExp, `${patchLine}\n$1`); if (formatContent !== newFormatContent) { yield fsWriteFile(formatPath, newFormatContent); console.log('Patch for nx format have been applied'); } else { throw new Error(`Apply couldn't patch for nx format`); } }); } exports.fixFormatter = fixFormatter; /** * To avoid @nrwl/nx's formatter tries to format App_Resources, platforms-files etc. * Create a .prettierignore file at the root of the project. */ function makePrettierIgnore() { return __awaiter(this, void 0, void 0, function* () { const prettierIgnorePath = path.join(process.cwd(), '/../..', '.prettierignore'); const prettierIgnore = `.DS_Store **/*.d.ts **/apps/**/platforms/**/* **/App_Resources/**/* **/apps/nativescript-*/hooks/**/* **/apps/nativescript-*/tools/**/* **/apps/nativescript-*/app/assets/*.min.css **/xplat/nativescript/plugins/**/* **/webpack.config.js **/package.json **/package-lock.json **/tslint.json **/tsconfig.*.json **/tsconfig.json **/*.conf.js `; if (!(yield fsExists(prettierIgnorePath))) { console.log(`"${prettierIgnorePath}" already exists`); return; } yield fsWriteFile(prettierIgnorePath, prettierIgnore, 'UTF-8'); }); } exports.makePrettierIgnore = makePrettierIgnore; updateConfig(); //# sourceMappingURL=postinstall.js.map