Skip to content

Commit 37745b5

Browse files
committed
feat: update build process and examples
1 parent ecedf3e commit 37745b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+4333
-5205
lines changed

.browserslistrc

-8
This file was deleted.

.eslintrc.js

-34
This file was deleted.

.github/workflows/github-ci.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ jobs:
2424
- name: Set up pnpm
2525
uses: pnpm/action-setup@v2
2626
with:
27-
version: 7
27+
version: 9
2828

2929
- name: Set up node
3030
uses: actions/setup-node@v3
3131
with:
32-
node-version: 18
32+
node-version: 20
3333
cache: 'pnpm'
3434

3535
- name: Install dependencies
@@ -38,16 +38,16 @@ jobs:
3838
- name: Run test
3939
run: pnpm run test
4040

41-
- name: Build assets
41+
- name: Build lib
4242
run: pnpm run build
4343

44-
- name: Copy public
45-
run: cp public/** dist
44+
- name: Build example
45+
run: cd examples/basic && pnpm run build
4646

4747
- name: Upload artifact
4848
uses: actions/upload-pages-artifact@v1
4949
with:
50-
path: 'dist'
50+
path: 'examples/basic/dist'
5151

5252
- name: Deploy to GitHub Pages
5353
id: deployment

.husky/pre-commit

-3
This file was deleted.

api-extractor.json

-55
This file was deleted.

build/build.mjs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { execSync } from 'child_process'
2+
import fs from 'fs-extra'
3+
import path from 'path'
4+
5+
const run = command => execSync(command, { stdio: 'inherit' })
6+
const resolve = file => path.join(import.meta.dirname, '../packages/html-diff', file)
7+
const p = resolve('tsconfig.json')
8+
const outDir = resolve('dist-ts')
9+
const c = path.join(import.meta.dirname, 'rollup.config.mjs')
10+
const distDir = resolve('dist')
11+
12+
await fs.remove(distDir)
13+
run(`tsc -p ${p} --outDir ${outDir} -d --emitDeclarationOnly`)
14+
run(`rollup -c ${c}`)
15+
await fs.remove(outDir)
16+
17+
process.on('exit', exitCode => {
18+
if (exitCode === 1) {
19+
fs.removeSync(distDir)
20+
fs.removeSync(outDir)
21+
}
22+
})

build/release.mjs

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import chalk from 'chalk'
2+
import { execSync } from 'child_process'
3+
import enquirer from 'enquirer'
4+
import fs from 'fs'
5+
import path from 'path'
6+
import semver from 'semver'
7+
8+
const { prompt } = enquirer
9+
const run = command => execSync(command, { stdio: 'inherit' })
10+
const stepLog = msg => console.log(chalk.cyan(msg))
11+
const errorLog = msg => console.log(chalk.red(`\nError: ${msg}`))
12+
const successLog = msg => console.log(chalk.green(msg))
13+
14+
// ensure no staged files before commit
15+
if (execSync('git diff --staged').length) {
16+
errorLog('There has some changes to be committed')
17+
process.exit(1)
18+
}
19+
20+
const resolve = file => path.join(import.meta.dirname, '../packages/html-diff', file)
21+
const pkgPath = resolve('package.json')
22+
const pkgJson = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
23+
const { name: pkgName, version: currentVersion } = pkgJson
24+
let targetVersion
25+
26+
const { level } = await prompt({
27+
type: 'select',
28+
name: 'level',
29+
message: 'Select release level',
30+
choices: ['prerelease', 'patch', 'prepatch', 'minor', 'preminor', 'major', 'premajor']
31+
.map(level => {
32+
const options = undefined
33+
// prerelease level use beta identifier default
34+
const identifier = level.startsWith('pre') ? 'beta' : undefined
35+
return `${level} (${semver.inc(currentVersion, level, options, identifier)})`
36+
})
37+
.concat(['custom']),
38+
})
39+
40+
if (level === 'custom') {
41+
targetVersion = (
42+
await prompt({
43+
type: 'input',
44+
name: 'version',
45+
message: 'Input custom version',
46+
initial: currentVersion,
47+
})
48+
).version
49+
} else {
50+
targetVersion = level.match(/\(([^)]*)\)/)[1]
51+
}
52+
53+
if (!semver.valid(targetVersion)) {
54+
errorLog(`Invalid target version: ${targetVersion}`)
55+
process.exit(1)
56+
}
57+
58+
const { tag } = await prompt({
59+
type: 'select',
60+
name: 'tag',
61+
message: 'Select npm dist-tag type',
62+
choices: ['latest', 'beta', 'next'],
63+
})
64+
65+
const { yes: tagOk } = await prompt({
66+
type: 'confirm',
67+
name: 'yes',
68+
message: `Releasing v${targetVersion} with the "${tag}" tag. Confirm?`,
69+
})
70+
71+
if (!tagOk) {
72+
process.exit()
73+
}
74+
75+
// check targetVersion (should be larger than current released version)
76+
const viewCmd = `npm v ${pkgName} dist-tags.${tag}`
77+
try {
78+
const curVersion = execSync(viewCmd, {
79+
stdio: ['pipe', 'pipe', 'inherit'],
80+
})
81+
.toString()
82+
.trim()
83+
if (targetVersion === curVersion || semver.lt(targetVersion, curVersion)) {
84+
errorLog(`The target version ${targetVersion} must be larger than ${curVersion}.`)
85+
process.exit(1)
86+
}
87+
} catch (e) {
88+
// Maybe 404 not found, should publish manually at 1st time
89+
// npm publish . --access public --tag latest
90+
errorLog(e.message)
91+
process.exit(1)
92+
}
93+
94+
// run tests before release
95+
stepLog('\nRunning tests...')
96+
run('pnpm run test')
97+
98+
// Build the package.
99+
stepLog('\nBuilding the package...')
100+
run('pnpm run build')
101+
102+
// Publish the package.
103+
stepLog('\nPublishing the package...')
104+
pkgJson.version = targetVersion
105+
fs.writeFileSync(pkgPath, JSON.stringify(pkgJson, null, 2) + '\n')
106+
run(`cd packages/html-diff && npm publish . --access public --tag ${tag}`)
107+
108+
// Commit changes to the Git.
109+
stepLog('\nCommitting changes...')
110+
run('git add packages/html-diff/package.json')
111+
run(`git commit -m "release: v${targetVersion}"`)
112+
113+
// Push to GitHub.
114+
stepLog('\nPushing to GitHub...')
115+
run(`git tag v${targetVersion}`)
116+
run(`git push origin refs/tags/v${targetVersion}`)
117+
118+
successLog(`\nReleased successfully at v${targetVersion}`)
119+
process.exit()

build/rollup.config.mjs

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { nodeResolve } from '@rollup/plugin-node-resolve'
2+
import typescript from '@rollup/plugin-typescript'
3+
import path from 'path'
4+
import postcssNested from 'postcss-nested'
5+
import postcssPresetEnv from 'postcss-preset-env'
6+
import { dts } from 'rollup-plugin-dts'
7+
import rollupPostcss from 'rollup-plugin-postcss'
8+
9+
const resolve = file => path.join(import.meta.dirname, '../packages/html-diff', file)
10+
11+
const dtsTask = {
12+
input: resolve('dist-ts/index.d.ts'),
13+
output: {
14+
file: resolve('dist/index.d.ts'),
15+
format: 'es',
16+
},
17+
plugins: [dts()],
18+
}
19+
20+
const mjsTask = {
21+
input: resolve('src/index.ts'),
22+
output: {
23+
file: resolve('dist/index.mjs'),
24+
format: 'es',
25+
},
26+
plugins: [
27+
typescript({
28+
tsconfig: resolve('tsconfig.json'),
29+
}),
30+
nodeResolve(),
31+
],
32+
}
33+
34+
const cssTask = {
35+
input: resolve('src/index.css'),
36+
output: {
37+
file: resolve('dist/index.css'),
38+
format: 'es',
39+
},
40+
plugins: [
41+
rollupPostcss({
42+
extract: true,
43+
plugins: [
44+
postcssNested,
45+
postcssPresetEnv({
46+
stage: 2,
47+
enableClientSidePolyfills: true,
48+
browsers: '> 0.5%, last 2 versions, not dead',
49+
}),
50+
],
51+
}),
52+
],
53+
}
54+
55+
export default [dtsTask, mjsTask, cssTask]
File renamed without changes.
File renamed without changes.

examples/basic/index.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite + React</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/main.jsx"></script>
12+
</body>
13+
</html>

examples/basic/package.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "basic",
3+
"private": true,
4+
"version": "0.0.0",
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite",
8+
"build": "vite build",
9+
"preview": "vite preview"
10+
},
11+
"dependencies": {
12+
"@armantang/html-diff": "workspace:*",
13+
"clsx": "^2.1.1",
14+
"github-markdown-css": "^5.7.0",
15+
"react": "^18.3.1",
16+
"react-dom": "^18.3.1"
17+
},
18+
"devDependencies": {
19+
"@types/react": "^18.3.12",
20+
"@types/react-dom": "^18.3.1",
21+
"@vitejs/plugin-react": "^4.3.3",
22+
"autoprefixer": "^10.4.20",
23+
"daisyui": "^4.12.14",
24+
"postcss": "^8.4.49",
25+
"tailwindcss": "^3.4.14",
26+
"vite": "^5.4.10"
27+
}
28+
}

examples/basic/postcss.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
plugins: {
3+
tailwindcss: {},
4+
autoprefixer: {},
5+
},
6+
}

examples/basic/public/vite.svg

+1
Loading

0 commit comments

Comments
 (0)