Format .github code

This commit is contained in:
lowlighter
2021-08-19 22:39:50 +02:00
parent c9a1ef7102
commit fc9d97fd14
5 changed files with 187 additions and 187 deletions

View File

@@ -1,43 +1,43 @@
//Imports
import fs from "fs"
import paths from "path"
import url from "url"
import ejs from "ejs"
import fs from "fs"
import paths from "path"
import url from "url"
import ejs from "ejs"
//Mode
const [mode, name] = process.argv.slice(2)
const [mode, name] = process.argv.slice(2)
//Paths
const __metrics = paths.join(paths.dirname(url.fileURLToPath(import.meta.url)), "../..")
const __quickstart = paths.join(__metrics, ".github/quickstart")
const __metrics = paths.join(paths.dirname(url.fileURLToPath(import.meta.url)), "../..")
const __quickstart = paths.join(__metrics, ".github/quickstart")
//Check arguments
if ((!mode)||(!name))
throw new Error(`Usage is "npm run quickstart -- <mode> <name>"`)
if (!["plugin", "template"].includes(mode))
throw new Error(`Unsupported mode ${mode}`)
if ((!mode)||(!name))
throw new Error(`Usage is "npm run quickstart -- <mode> <name>"`)
if (!["plugin", "template"].includes(mode))
throw new Error(`Unsupported mode ${mode}`)
//Check if target directory already exists
const target = paths.join(__metrics, `source/${mode}s`, name)
if (fs.existsSync(target))
throw new Error(`A ${mode} named ${name} already exists!`)
const target = paths.join(__metrics, `source/${mode}s`, name)
if (fs.existsSync(target))
throw new Error(`A ${mode} named ${name} already exists!`)
//Copy quickstart content
console.log(`quickstart for ${mode}`)
await fs.promises.mkdir(target)
await rcopy(paths.join(__quickstart, mode), target)
console.log(`quickstart for ${mode}`)
await fs.promises.mkdir(target)
await rcopy(paths.join(__quickstart, mode), target)
//Recursive copy
async function rcopy(from, to) {
for (const file of await fs.promises.readdir(from)) {
const path = paths.join(from, file)
if ((await fs.promises.lstat(path)).isDirectory()) {
await fs.promises.mkdir(paths.join(to, file))
await rcopy(path, paths.join(to, file))
}
else {
console.log(`copying ${path} to ${paths.join(to, file)}`)
await fs.promises.writeFile(paths.join(to, file), await ejs.renderFile(path, {name}, {async:true}))
}
async function rcopy(from, to) {
for (const file of await fs.promises.readdir(from)) {
const path = paths.join(from, file)
if ((await fs.promises.lstat(path)).isDirectory()) {
await fs.promises.mkdir(paths.join(to, file))
await rcopy(path, paths.join(to, file))
}
else {
console.log(`copying ${path} to ${paths.join(to, file)}`)
await fs.promises.writeFile(paths.join(to, file), await ejs.renderFile(path, {name}, {async:true}))
}
}
}