Skip to content

Commit

Permalink
Add cleaning to dev script
Browse files Browse the repository at this point in the history
  • Loading branch information
JamDon2 committed Jul 31, 2022
1 parent e20842f commit 345c235
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
52 changes: 36 additions & 16 deletions scripts/clean.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
const fse = require("fs-extra")
const path = require("path")

const target = process.argv[2]
if (process.argv[3] === "npm") {
const target = process.argv[2]

switch (target) {
case "all": {
fse.removeSync(process.env.DEV_PATH)
fse.removeSync(path.join(__dirname, "../dist"))
break
}
case "dev": {
fse.removeSync(process.env.DEV_PATH)
break
}
case "build": {
fse.removeSync(path.join(__dirname, "../dist"))
break
clean(target)
}

function replaceEnv(str) {
const envKeys = Object.keys(process.env)

for (const envKey of envKeys) {
str = str
.replaceAll(`%${envKey}%`, process.env[envKey])
.replaceAll(`$${envKey}`, process.env[envKey])
}
default: {
throw new Error("Invalid target")

return str
}

function clean(target) {
switch (target) {
case "all": {
fse.removeSync(replaceEnv(process.env.DEV_PATH))
fse.removeSync(path.join(__dirname, "../dist"))
break
}
case "dev": {
fse.removeSync(replaceEnv(process.env.DEV_PATH))
break
}
case "build": {
fse.removeSync(path.join(__dirname, "../dist"))
break
}
default: {
throw new Error("Invalid target")
}
}
}

module.exports.clean = clean
4 changes: 4 additions & 0 deletions scripts/dev.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const spawn = require("cross-spawn")
const fse = require("fs-extra")
const path = require("path")
const { clean } = require("./clean")

function replaceEnv(str) {
const envKeys = Object.keys(process.env)
Expand All @@ -15,6 +17,8 @@ function replaceEnv(str) {

const buildDir = replaceEnv(process.env.DEV_PATH)

clean("dev")

spawn("npx", ["tstl", "-outDir", buildDir])

fse.copySync("src/", buildDir, {
Expand Down

0 comments on commit 345c235

Please sign in to comment.