|
| 1 | +import { urlJoin } from 'https://deno.land/x/url_join/mod.ts'; |
| 2 | +import { exec } from 'https://cdn.depjs.com/exec/mod.ts' |
| 3 | + |
| 4 | +const libDir = 'lib' |
| 5 | +const libTemplateDir = urlJoin(libDir, 'template') |
| 6 | +const libNuxtDir = urlJoin(libTemplateDir, 'frameworks/nuxt') |
| 7 | + |
| 8 | +const templatePathNuxtConfig = urlJoin(libNuxtDir, 'nuxt.config.ejs') |
| 9 | +const outputPathNuxtConfig = urlJoin(libNuxtDir, 'nuxt.config.ts') |
| 10 | + |
| 11 | +const templatePathTsConfig = urlJoin(libNuxtDir, 'tsconfig.ejs') |
| 12 | +const outputPathTsConfig = urlJoin(libNuxtDir, 'tsconfig.json') |
| 13 | + |
| 14 | +const readNuxtConfigTemplate = Deno.run({ |
| 15 | + cmd: [ |
| 16 | + 'deno', |
| 17 | + 'run', |
| 18 | + '--allow-read', |
| 19 | + './readConfigTemplate.ts', |
| 20 | + templatePathNuxtConfig |
| 21 | + ], |
| 22 | + stdout: 'piped', |
| 23 | + stderr: 'piped', |
| 24 | +}); |
| 25 | + |
| 26 | +const readTsConfigTemplate = Deno.run({ |
| 27 | + cmd: [ |
| 28 | + 'deno', |
| 29 | + 'run', |
| 30 | + '--allow-read', |
| 31 | + './readConfigTemplate.ts', |
| 32 | + templatePathTsConfig |
| 33 | + ], |
| 34 | + stdout: 'piped', |
| 35 | + stderr: 'piped', |
| 36 | +}); |
| 37 | + |
| 38 | +// nuxt.config |
| 39 | +const statusNuxtConfig = await readNuxtConfigTemplate.status(); |
| 40 | + |
| 41 | +if (statusNuxtConfig.code === 0) { |
| 42 | + const rawOutput = await readNuxtConfigTemplate.output(); |
| 43 | + const string = new TextDecoder().decode(rawOutput) |
| 44 | + |
| 45 | + await Deno.writeTextFile(outputPathNuxtConfig, string); |
| 46 | + |
| 47 | + // await exec({ |
| 48 | + // cmd: ['yarn', 'lint:fix'], |
| 49 | + // cwd: `./${libNuxtDir}`, |
| 50 | + // }) |
| 51 | + |
| 52 | + console.log(`\n🎉 Successfully created ${outputPathNuxtConfig}\n`) |
| 53 | +} else { |
| 54 | + const rawError = await readNuxtConfigTemplate.stderrOutput(); |
| 55 | + const errorString = new TextDecoder().decode(rawError); |
| 56 | + |
| 57 | + console.log(errorString); |
| 58 | +} |
| 59 | + |
| 60 | +// tsconfig |
| 61 | +const statusTsConfig = await readTsConfigTemplate.status(); |
| 62 | + |
| 63 | +if (statusTsConfig.code === 0) { |
| 64 | + const rawOutput = await readTsConfigTemplate.output(); |
| 65 | + const string = new TextDecoder().decode(rawOutput) |
| 66 | + |
| 67 | + await Deno.writeTextFile(outputPathTsConfig, string); |
| 68 | + |
| 69 | + console.log(`\n🥳 Successfully created ${outputPathTsConfig}\n`) |
| 70 | +} else { |
| 71 | + const rawError = await readTsConfigTemplate.stderrOutput(); |
| 72 | + const errorString = new TextDecoder().decode(rawError); |
| 73 | + |
| 74 | + console.log(errorString); |
| 75 | +} |
| 76 | + |
| 77 | +Deno.exit(); |
0 commit comments