Last active
March 20, 2022 19:46
-
-
Save sigmaSd/69a45af461e7a6acc6c43f7099186393 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const $ = async (e: string) => { | |
await Deno.run({ | |
cmd: ["sh", "-c", e], | |
}).status(); | |
}; | |
const MAKE = "make"; | |
const PUBLIC_DIR = "public"; | |
const OUT_DIR = "build"; | |
const BUNDLED = `${OUT_DIR}/bundle.js`; | |
const MINIFIED = `${OUT_DIR}/bundle.min.js`; | |
const IGNORE = `--ignore=${PUBLIC_DIR},${OUT_DIR},docs,README.md`; | |
const CONFIG = "--config tsconfig.json"; | |
export const tasks: { | |
[key: string]: () => Promise<void>; | |
} = { | |
all: async () => { | |
await tasks.hooks(); | |
await tasks.install(); | |
await tasks["fmt-check"](); | |
await tasks.lint(); | |
await tasks.build(); | |
}, | |
// deno-lint-ignore require-await | |
help: async () => { | |
console.log(Object.keys(tasks)); | |
}, | |
h: async () => { | |
await tasks.help(); | |
}, | |
hooks: async () => { | |
await $(`cd .git/hooks && ln -s -f ../../hooks/pre-push pre-push`); | |
}, | |
install: async () => { | |
await $(`deno cache deps.ts`); | |
await $(`deno cache dev_deps.ts`); | |
}, | |
upgrade: async () => { | |
await $(`deno cache --reload deps.ts`); | |
await $(`deno cache --reload dev_deps.ts`); | |
}, | |
fmt: async () => { | |
await $(`deno fmt ${IGNORE} --unstable`); | |
}, | |
"fmt-check": async () => { | |
await $(`deno fmt --check ${IGNORE} --unstable`); | |
}, | |
lint: async () => { | |
await $(`deno lint --unstable ${IGNORE}`); | |
}, | |
l: async () => { | |
await tasks.lint(); | |
}, | |
clean: async () => { | |
await $(`rm -rf ${OUT_DIR}`); | |
}, | |
assets: async () => { | |
await $(`mkdir -p ${OUT_DIR}`); | |
await $(`cp ${PUBLIC_DIR}/styles.css ${OUT_DIR}`); | |
}, | |
"bundle-dev": async () => { | |
await $(`cp ${PUBLIC_DIR}/dev.html ${OUT_DIR}/index.html`); | |
await $(`deno bundle --watch ${CONFIG} src/index.jsx ${BUNDLED}`); | |
}, | |
"bundle-prod": async () => { | |
await $(`cp ${PUBLIC_DIR}/prod.html ${OUT_DIR}/index.html`); | |
await $(`deno bundle ${CONFIG} src/index.jsx ${BUNDLED}`); | |
}, | |
"static-server": async () => { | |
await $(`deno run ${CONFIG} --allow-net --allow-read static.ts`); | |
}, | |
serve: async () => { | |
await $(`${MAKE} -j 2 bundle-dev static-server`); | |
}, | |
s: async () => { | |
await tasks.serve(); | |
}, | |
minify: async () => { | |
await $(`npx esbuild ${BUNDLED} \ | |
--outfile=${MINIFIED} \ | |
--minify \ | |
--sourcemap \ | |
--define:'process.env.NODE_ENV="production"'`); | |
}, | |
build: async () => { | |
await tasks["bundle-prod"](); | |
await tasks.minify(); | |
}, | |
}; | |
await tasks[Deno.args[0] || "install"](); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment