Skip to content

Commit

Permalink
Better build scripting
Browse files Browse the repository at this point in the history
  • Loading branch information
zerodevx committed Feb 27, 2023
1 parent 5c3ffa9 commit 518b67a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
3 changes: 0 additions & 3 deletions .tokeignore

This file was deleted.

37 changes: 37 additions & 0 deletions build-all.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env zx

await $`npm run lint`
await $`npm run check`
await $`npm run build`
await $`npx svelte-package`
const out = await $`npx vite build -c vite.dist.config.js`

// Calculate stats
const sizes = out.stdout
.split('\n')
.find((i) => i.includes('index.umd.cjs'))
.split(' ')
.filter((i) => !isNaN(parseFloat(i)))
const cloc = JSON.parse(await $`npx cloc src/lib --json`).SUM.code.toString()

// Write stats into `/build`
const shields = { schemaVersion: 1, color: 'blue' }
await fs.writeJson('build/_min.json', { ...shields, label: 'minified', message: `${sizes[0]} kB` })
await fs.writeJson('build/_gzip.json', { ...shields, label: 'gzipped', message: `${sizes[1]} kB` })
await fs.writeJson('build/_loc.json', { ...shields, label: 'lines of code', message: cloc })

// Prepare `/dist`
const pkg = await fs.readJson('package.json')
pkg.scripts = undefined
await fs.writeJson('dist/package.json', pkg, { spaces: 2 })
await fs.copy('README.md', 'dist/README.md')
await fs.copy('LICENSE', 'dist/LICENSE')
await $`cd dist && npx publint`

echo`
To deploy the demo, run:
$ npx gh-pages -d build -t -f
To publish into npm, run:
$ cd dist && npm publish --access public
`
4 changes: 2 additions & 2 deletions vite.dist.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export default defineConfig({
})
],
build: {
outDir: './package/dist',
outDir: './dist/dist',
minify: 'terser',
lib: {
entry: './src/lib/index.js',
name: 'window',
fileName: (format) => `index.${format}.js`
fileName: (format) => `index.${format === 'umd' ? 'umd.cjs' : 'es.js'}`
},
rollupOptions: {
output: {
Expand Down

0 comments on commit 518b67a

Please sign in to comment.