Skip to content

Commit

Permalink
build: customize package process
Browse files Browse the repository at this point in the history
  • Loading branch information
metonym committed Jan 1, 2024
1 parent 5a2c528 commit b24ec5d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ jobs:
# https://docs.npmjs.com/generating-provenance-statements
run: |
npm install --force
npm run package
cd package
npm publish --provenance --access public
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/test-results/
/playwright-report/
/playwright/.cache/
/package
26 changes: 12 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@
"description": "Detect if an element is in the viewport using the Intersection Observer API",
"author": "Eric Liu (https://github.com/metonym)",
"type": "module",
"svelte": "./src/index.js",
"main": "./src/index.js",
"types": "./src/index.d.ts",
"svelte": "./index.js",
"main": "./index.js",
"types": "./index.d.ts",
"exports": {
".": {
"types": "./types/index.d.ts",
"svelte": "./src/index.js"
"types": "./index.d.ts",
"svelte": "./index.js"
},
"./src/*.svelte": {
"types": "./src/*.svelte.d.ts",
"import": "./src/*.svelte"
"./*.svelte": {
"types": "./*.svelte.d.ts",
"import": "./*.svelte"
},
"./src/*": {
"types": "./src/*.d.ts",
"import": "./src/*.js"
"./*": {
"types": "./*.d.ts",
"import": "./*.js"
}
},
"scripts": {
"dev": "rollup -cw",
"build": "rollup -c",
"package": "node scripts/npm-package",
"test:types": "svelte-check --workspace tests",
"test:e2e": "playwright test",
"format": "prettier --write '.'"
Expand Down Expand Up @@ -54,9 +55,6 @@
"lazy-loading",
"conditional"
],
"files": [
"src"
],
"prettier": {
"plugins": [
"prettier-plugin-svelte"
Expand Down
34 changes: 34 additions & 0 deletions scripts/npm-package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// @ts-check

import fs from "node:fs";
import fsp from "node:fs/promises";

(async () => {
console.time("package");

if (fs.existsSync("./package")) {
await fsp.rm("./package", { recursive: true });
}

await fsp.mkdir("./package");

await fsp.cp("./src", "./package", { recursive: true });
await fsp.copyFile("./package.json", "./package/package.json");
await fsp.copyFile("./README.md", "./package/README.md");
await fsp.copyFile("./LICENSE", "./package/LICENSE");

const pkgJson = JSON.parse(
fs.readFileSync("./package/package.json", "utf-8"),
);

delete pkgJson.scripts;
delete pkgJson.devDependencies;
delete pkgJson.prettier;

await fsp.writeFile(
"./package/package.json",
JSON.stringify(pkgJson, null, 2),
);

console.timeEnd("package");
})();

0 comments on commit b24ec5d

Please sign in to comment.