diff --git a/.gitignore b/.gitignore index 7446492add..bb69261165 100755 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ build/ exts/ !scripts/build/ .vscode/ +publish/LICENSE +publish/README.md diff --git a/package.json b/package.json index eec2df66f0..26d0c45b0d 100755 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "zui", "version": "3.0.0-alpha.1", "type": "module", + "private": true, "engines": { "node": ">=14", "pnpm": ">=8" @@ -32,7 +33,8 @@ "docs:build:exts": "pnpm docs:prepare -- --copy --exts --lib=zui*exts && cd docs && pnpm build", "docs:serve": "cd docs && pnpm serve", "docs:prepare": "tsx ./scripts/docs/prepare.ts", - "extend-lib": "tsx ./scripts/libs/extend-lib.ts" + "extend-lib": "tsx ./scripts/libs/extend-lib.ts", + "publish:npm": "pnpm build -- --ignoreNotReady && tsx ./scripts/build/publish.ts && cd ./publish && npm publish" }, "workspaces": [ "./lib" diff --git a/publish/package.json b/publish/package.json new file mode 100644 index 0000000000..0cc90ae2b3 --- /dev/null +++ b/publish/package.json @@ -0,0 +1,23 @@ +{ + "name": "zui", + "version": "3.0.0-alpha.1", + "type": "module", + "engines": { + "node": ">=14", + "pnpm": ">=8" + }, + "files": ["dist"], + "main": "./dist/zui.js", + "module": "./dist/zui.esm.js", + "exports": { + ".": { + "import": "./dist/zui.esm.js", + "require": "./dist/zui.js" + }, + "./css": "./dist/zui.css" + }, + "dependencies": { + }, + "devDependencies": { + } + } diff --git a/scripts/build/publish.ts b/scripts/build/publish.ts new file mode 100644 index 0000000000..0f35c6392b --- /dev/null +++ b/scripts/build/publish.ts @@ -0,0 +1,18 @@ +import path from 'path'; +import fs from 'fs-extra'; + +const publishPath = path.resolve(process.cwd(), './publish'); +const publishDistPath = path.resolve(publishPath, 'dist'); + +await fs.emptyDir(publishDistPath); +await fs.copy(path.resolve(process.cwd(), './dist/zui'), publishDistPath); +await fs.copyFile(path.resolve(process.cwd(), './README.md'), path.resolve(publishPath, './README.md')) +await fs.copyFile(path.resolve(process.cwd(), './LICENSE'), path.resolve(publishPath, './LICENSE')) + +const packageJson = await fs.readJSON(path.resolve(process.cwd(), './package.json')); +const publishPackageJson = await fs.readJSON(path.resolve(publishPath, './package.json')); + +if (publishPackageJson.version !== packageJson.version) { + publishPackageJson.version = packageJson.version; + await fs.writeJSON(path.resolve(publishPath, './package.json'), publishPackageJson); +}