import { Rule, Tree } from '@angular-devkit/schematics'; import { Schema } from './schema'; export function ngAdd(_options: Schema): Rule { return addDeliveryVerificationScript; } function addDeliveryVerificationScript(tree: Tree): void { const packageJson = readJson(tree, '/package.json'); const scripts = packageJson.scripts ?? {}; if (scripts.verify) { return; } const verifyCommands = [ scripts.test ? 'npm test -- --watch=false' : undefined, scripts.e2e ? 'npm run e2e' : undefined, scripts.build ? 'npm run build' : undefined, scripts.lint ? 'npm run lint' : undefined, ].filter((command): command is string => Boolean(command)); if (verifyCommands.length === 0) { return; } packageJson.scripts = { ...scripts, verify: verifyCommands.join(' && '), }; writeJson(tree, '/package.json', packageJson); } function readJson(tree: Tree, path: string): Record { const content = tree.readText(path); return JSON.parse(content) as Record; } function writeJson(tree: Tree, path: string, value: Record): void { tree.overwrite(path, `${JSON.stringify(value, null, 2)}\n`); }