diff --git a/.copier-answers.yaml b/.copier-answers.yaml index a264426..7edcecf 100644 --- a/.copier-answers.yaml +++ b/.copier-answers.yaml @@ -1,5 +1,5 @@ # Changes here will be overwritten by Copier -_commit: cb37079 +_commit: d814faa _src_path: https://github.com/python-project-templates/base.git add_docs: true add_extension: js diff --git a/js/build.mjs b/js/build.mjs index 3399cf6..8428338 100644 --- a/js/build.mjs +++ b/js/build.mjs @@ -18,23 +18,33 @@ const BUNDLES = [ ]; async function build() { + fs.rmSync("dist", { recursive: true, force: true }); + fs.rmSync("../python_template_js/extension", { + recursive: true, + force: true, + }); + // Bundle css await bundle_css(); // Copy HTML - cpy("src/html/*", "dist/"); + await cpy("src/html/*", "dist/"); // Copy images - fs.mkdirSync("dist/img", { recursive: true }); - cpy("src/img/*", "dist/img"); + if (fs.existsSync("src/img")) { + fs.mkdirSync("dist/img", { recursive: true }); + await cpy("src/img/*", "dist/img"); + } await Promise.all(BUNDLES.map(bundle)).catch(() => process.exit(1)); // Copy servable assets to python extension (exclude esm/) fs.mkdirSync("../python_template_js/extension", { recursive: true }); - cpy("dist/**/*", "../python_template_js/extension", { - filter: (file) => !file.relativePath.startsWith("esm"), + await cpy("dist/**/*", "../python_template_js/extension", { + filter: (file) => + !file.relativePath.startsWith("esm/") && + !file.relativePath.startsWith("dist/esm/"), }); } -build(); +await build(); diff --git a/js/package.json b/js/package.json index a9af323..8578df7 100644 --- a/js/package.json +++ b/js/package.json @@ -18,8 +18,7 @@ "./package.json": "./package.json" }, "files": [ - "dist/**/*", - "index.d.ts" + "dist/**/*" ], "types": "./dist/esm/index.d.ts", "publishConfig": { @@ -27,7 +26,9 @@ }, "scripts": { "build:debug": "node build.mjs --debug", - "build": "node build.mjs", + "build:prod": "node build.mjs", + "build:types": "tsc", + "build": "npm-run-all build:prod build:types", "clean": "rm -rf dist playwright-report ../python_template_js/extension", "dev": "npm-run-all -p start watch", "lint": "oxlint . && oxfmt --check \"src/**/*.{js,ts,jsx,tsx,css}\" \"tests/**/*.{js,ts,jsx,tsx}\" \"*.mjs\" \"*.json\"", diff --git a/js/tsconfig.json b/js/tsconfig.json index b25bdae..b507e71 100644 --- a/js/tsconfig.json +++ b/js/tsconfig.json @@ -14,11 +14,11 @@ "noFallthroughCasesInSwitch": true, "outDir": "./dist/esm", "resolveJsonModule": true, - "rootDir": ".", + "rootDir": "./src/ts", "skipLibCheck": true, "strict": true, "target": "ES2020", "useDefineForClassFields": true }, - "include": ["./src/ts/*.ts", "./tests/*.ts"] + "include": ["./src/ts/*.ts"] }