UNPKG

@aws-amplify/cli-internal

Version:
54 lines 2.13 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GitIgnoreGenerator = void 0; const node_path_1 = __importDefault(require("node:path")); const promises_1 = __importDefault(require("node:fs/promises")); const GEN2_GITIGNORE_ENTRIES = [ '.gen2-migration', '.amplify', 'amplify_outputs*', 'amplifyconfiguration*', 'aws-exports*', 'node_modules', 'build', 'dist', ]; class GitIgnoreGenerator { async plan() { return [ { validate: () => undefined, describe: async () => ['Update .gitignore with Gen2 entries'], execute: async () => { const gitignorePath = node_path_1.default.join(process.cwd(), '.gitignore'); let content = ''; try { content = await promises_1.default.readFile(gitignorePath, 'utf-8'); } catch (e) { if (!(e.code === 'ENOENT')) { throw e; } } const gen1BlockRegex = /#amplify-do-not-edit-begin[\s\S]*#amplify-do-not-edit-end/g; content = content.replace(gen1BlockRegex, ''); if (!content.includes('.amplify')) { content = `${content}\n# amplify\n.amplify`; } for (const entry of GEN2_GITIGNORE_ENTRIES.slice(1)) { if (!content.includes(entry)) { content = `${content}\n${entry}`; } } content = content.replace(/^\s*[\r\n]/gm, ''); await promises_1.default.writeFile(gitignorePath, `${content}\n`, 'utf-8'); }, }, ]; } } exports.GitIgnoreGenerator = GitIgnoreGenerator; //# sourceMappingURL=gitignore.generator.js.map