-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
232 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
dist | ||
.env |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
dist | ||
.env |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
.pnpm-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Snowpack dependency directory (https://snowpack.dev/) | ||
web_modules/ | ||
|
||
# TypeScript cache | ||
*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional stylelint cache | ||
.stylelintcache | ||
|
||
# Microbundle cache | ||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# dotenv environment variable files | ||
.env | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.env.local | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
.cache | ||
.parcel-cache | ||
|
||
# Next.js build output | ||
.next | ||
out | ||
|
||
# Nuxt.js build / generate output | ||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
.cache/ | ||
# Comment in the public line in if your project uses Gatsby and not Next.js | ||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
# public | ||
|
||
# vuepress build output | ||
.vuepress/dist | ||
|
||
# vuepress v2.x temp and cache directory | ||
.temp | ||
.cache | ||
|
||
# Docusaurus cache and generated files | ||
.docusaurus | ||
|
||
# Serverless directories | ||
.serverless/ | ||
|
||
# FuseBox cache | ||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
.dynamodb/ | ||
|
||
# TernJS port file | ||
.tern-port | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
.vscode-test | ||
|
||
# yarn v2 | ||
.yarn/cache | ||
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.* | ||
|
||
# Core Dump | ||
core | ||
core.* |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
dist | ||
dist | ||
.env |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { readdirSync, statSync, watch as watchDir } from 'node:fs'; | ||
import { extname, join } from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
|
||
import esbuild from 'esbuild'; | ||
|
||
const __dirname = fileURLToPath(new URL('.', import.meta.url)); | ||
|
||
let args = process.argv.slice(2); | ||
const watch = args.includes('--watch'); | ||
if (watch) args = args.filter(script => script !== '--watch'); | ||
|
||
async function findFiles(dir, ext) { | ||
let results = []; | ||
|
||
try { | ||
const list = readdirSync(dir); | ||
|
||
for (const file of list) { | ||
const filePath = join(dir, file); | ||
const fileStat = statSync(filePath); | ||
|
||
if (fileStat.isDirectory()) { | ||
results = results.concat(await findFiles(filePath, ext)); | ||
} else if (extname(file) === ext) { | ||
results.push(filePath); | ||
} | ||
} | ||
} catch (err) { | ||
// Slient error, skip. | ||
} | ||
|
||
return results; | ||
} | ||
|
||
async function build(files, exit = true) { | ||
console.log('Building...'); | ||
|
||
const start = Date.now(); | ||
const basePath = join(__dirname, '..'); | ||
|
||
try { | ||
await esbuild.build({ | ||
entryPoints: files, | ||
bundle: false, | ||
outdir: join(__dirname, '..', 'dist'), | ||
platform: 'node', | ||
target: 'esnext', | ||
format: 'esm', | ||
sourcemap: true, | ||
packages: 'external', | ||
}); | ||
} catch (err) { | ||
console.error('[ESBuild]', err); | ||
if (exit) process.exit(1); | ||
} | ||
|
||
console.log([ | ||
'', | ||
`Built ${files.length} files:`, | ||
files.map(file => ` - ${file.replace(basePath, '')}`).join('\n'), | ||
'' | ||
].join('\n')); | ||
|
||
console.log(`Build completed in ${Date.now() - start}ms.`); | ||
} | ||
|
||
const srcDir = join(__dirname, '..', args[0] ?? 'src'); | ||
|
||
const files = await findFiles(srcDir, args[1] ?? '.ts'); | ||
|
||
if (watch) { | ||
let lastBuild = Date.now(); | ||
|
||
watchDir(srcDir, { recursive: true }, async (_, filename) => { | ||
if (Date.now() - lastBuild < 1000) return; | ||
lastBuild = Date.now(); | ||
|
||
console.log(`File changed: ${filename}`); | ||
|
||
const files = await findFiles(srcDir, args[1] ?? '.ts'); | ||
await build(files, false); | ||
}); | ||
} else build(files); |