From 7bd21509415ca3d9cd5cf63ebf6a2d94036d2f84 Mon Sep 17 00:00:00 2001 From: seanwlawrence Date: Thu, 27 Sep 2018 17:17:34 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20bug=20with=20error=20on?= =?UTF-8?q?=20existing=20directory?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Was throwing error if directory already exists. Update the existsSync function to check the directory path, not the file path, so new files can be written to an existing directory and if it doesn't exist, it will be created --- bin/index.js | 7 ++++--- index.ts | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/bin/index.js b/bin/index.js index 47209c1..6b3626b 100755 --- a/bin/index.js +++ b/bin/index.js @@ -59,8 +59,9 @@ function createPage(answers) { var templateAsString = fs_1.readFileSync(internalTemplatePath, 'utf8'); var fileContent = mustache_1.render(templateAsString, { props: props, name: outputName }); var _b = process.argv, args = _b.slice(2); - var outputPath = path_1.join(process.cwd(), args[0], outputName + "." + extension); - if (fs_1.existsSync(outputPath)) { + var outputDirectory = path_1.join(process.cwd(), args[0]); + var outputPath = path_1.join(outputDirectory, outputName + "." + extension); + if (fs_1.existsSync(outputDirectory)) { fs_1.writeFileSync(outputPath, fileContent); } else { @@ -112,4 +113,4 @@ function main() { } main(); console.log('hello, world!'); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBRUEsNkJBQTRCO0FBQzVCLHFDQUFrQztBQUVsQyxxQ0FBOEM7QUFDOUMseUJBTVk7QUFDWix1Q0FBNkM7QUFDN0MsNkNBQWlFO0FBR2pFLFNBQXdCLFVBQVUsQ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UFHO0lBQ3BCLE9BQU8sRUFBRSxxR0FBcUc7SUFDOUcsSUFBSSxFQUFFLE9BQU87SUFDYixJQUFJLEVBQUUsT0FBTztDQUNiLENBQUM7QUFFRixTQUFlLElBQUk7Ozs7O3dCQUNJLHFCQUFNLGlCQUFNLENBQUMsV0FBVyxDQUFDLEVBQUE7O29CQUF6QyxRQUFRLEdBQVEsU0FBeUI7b0JBQ3ZCLHFCQUFNLGlCQUFNLENBQUMsYUFBYSxDQUFDLEVBQUE7O29CQUE3QyxVQUFVLEdBQVEsU0FBMkI7b0JBQzVCLHFCQUFNLGlCQUFNLENBQUMsWUFBWSxDQUFDLEVBQUE7O29CQUEzQyxTQUFTLEdBQVEsU0FBMEI7b0JBRWpELFVBQVUsY0FDTixRQUFRLEVBQ1IsVUFBVSxJQUNiLEtBQUssRUFBRSxvQkFBVyxDQUFDLFNBQVMsQ0FBQyxLQUFLLENBQUMsSUFDbEMsQ0FBQzs7Ozs7Q0FDSDtBQUVELElBQUksRUFBRSxDQUFDO0FBRVAsT0FBTyxDQUFDLEdBQUcsQ0FBQyxlQUFlLENBQUMsQ0FBQyJ9 \ No newline at end of file diff --git a/index.ts b/index.ts index 51f8df8..ed11799 100644 --- a/index.ts +++ b/index.ts @@ -30,13 +30,14 @@ export default function createPage(answers: Answers) { const [, , ...args] = process.argv; + const outputDirectory: string = join(process.cwd(), args[0]); + const outputPath: string = join( - process.cwd(), - args[0], + outputDirectory, `${outputName}.${extension}`, ); - if (existsSync(outputPath)) { + if (existsSync(outputDirectory)) { writeFileSync(outputPath, fileContent); } else { mkdirSync(join(process.cwd(), args[0]));