From 61f4904145a624476b8346718fdfb68193b49c54 Mon Sep 17 00:00:00 2001 From: truehazker <40111175+truehazker@users.noreply.github.com> Date: Sun, 4 Jan 2026 14:56:14 +0400 Subject: [PATCH 1/2] fix: :bug: fix .gitignores not being included to the package --- .gitignore | 3 +++ bun.lock | 6 ++++++ package.json | 10 +++++++--- scripts/postinstall.ts | 36 ++++++++++++++++++++++++++++++++++++ scripts/prepare.ts | 39 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 scripts/postinstall.ts create mode 100644 scripts/prepare.ts diff --git a/.gitignore b/.gitignore index e9de00a..ec663aa 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,9 @@ out dist *.tgz +# generated templates archive (created during prepare script) +templates.zip + # code coverage coverage *.lcov diff --git a/bun.lock b/bun.lock index 706f8db..e7c3b35 100644 --- a/bun.lock +++ b/bun.lock @@ -6,9 +6,11 @@ "name": "create-elysiajs", "dependencies": { "@clack/prompts": "^0.11.0", + "adm-zip": "^0.5.16", }, "devDependencies": { "@biomejs/biome": "2.3.10", + "@types/adm-zip": "^0.5.7", "@types/bun": "^1.3.5", }, }, @@ -36,10 +38,14 @@ "@clack/prompts": ["@clack/prompts@0.11.0", "", { "dependencies": { "@clack/core": "0.5.0", "picocolors": "^1.0.0", "sisteransi": "^1.0.5" } }, "sha512-pMN5FcrEw9hUkZA4f+zLlzivQSeQf5dRGJjSUbvVYDLvpKCdQx5OaknvKzgbtXOizhP+SJJJjqEbOe55uKKfAw=="], + "@types/adm-zip": ["@types/adm-zip@0.5.7", "", { "dependencies": { "@types/node": "*" } }, "sha512-DNEs/QvmyRLurdQPChqq0Md4zGvPwHerAJYWk9l2jCbD1VPpnzRJorOdiq4zsw09NFbYnhfsoEhWtxIzXpn2yw=="], + "@types/bun": ["@types/bun@1.3.5", "", { "dependencies": { "bun-types": "1.3.5" } }, "sha512-RnygCqNrd3srIPEWBd5LFeUYG7plCoH2Yw9WaZGyNmdTEei+gWaHqydbaIRkIkcbXwhBT94q78QljxN0Sk838w=="], "@types/node": ["@types/node@25.0.3", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-W609buLVRVmeW693xKfzHeIV6nJGGz98uCPfeXI1ELMLXVeKYZ9m15fAMSaUPBHYLGFsVRcMmSCksQOrZV9BYA=="], + "adm-zip": ["adm-zip@0.5.16", "", {}, "sha512-TGw5yVi4saajsSEgz25grObGHEUaDrniwvA2qwSC060KfqGPdglhvPMA2lPIoxs3PQIItj2iag35fONcQqgUaQ=="], + "bun-types": ["bun-types@1.3.5", "", { "dependencies": { "@types/node": "*" } }, "sha512-inmAYe2PFLs0SUbFOWSVD24sg1jFlMPxOjOSSCYqUgn4Hsc3rDc7dFvfVYjFPNHtov6kgUeulV4SxbuIV/stPw=="], "picocolors": ["picocolors@1.1.1", "", {}, "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA=="], diff --git a/package.json b/package.json index 5229aa0..e509753 100644 --- a/package.json +++ b/package.json @@ -38,10 +38,12 @@ "bin": { "create-ely": "./src/index.ts" }, - "files": ["src", "templates", "README.md", "LICENSE"], + "files": ["src", "templates.zip", "scripts/postinstall.ts", "README.md", "LICENSE"], "scripts": { "dev": "bun run src/index.ts", - "build": "bun build src/index.ts --compile --outfile dist/create-ely" + "build": "bun build src/index.ts --compile --outfile dist/create-ely", + "prepare": "bun run scripts/prepare.ts", + "postinstall": "bun run scripts/postinstall.ts" }, "engines": { "bun": ">=1.0.0" @@ -51,10 +53,12 @@ "registry": "https://registry.npmjs.org/" }, "dependencies": { - "@clack/prompts": "^0.11.0" + "@clack/prompts": "^0.11.0", + "adm-zip": "^0.5.16" }, "devDependencies": { "@biomejs/biome": "2.3.10", + "@types/adm-zip": "^0.5.7", "@types/bun": "^1.3.5" } } diff --git a/scripts/postinstall.ts b/scripts/postinstall.ts new file mode 100644 index 0000000..b831d51 --- /dev/null +++ b/scripts/postinstall.ts @@ -0,0 +1,36 @@ +#!/usr/bin/env bun +import { existsSync } from 'node:fs'; +import { join } from 'node:path'; +import AdmZip from 'adm-zip'; + +/** + * Postinstall script that runs after package installation + * Unzips the templates folder to restore .gitignore files + * See: https://johnnyreilly.com/smuggling-gitignore-npmrc-in-npm-packages + */ +const templatesPath = join(import.meta.dir, '..', 'templates'); +const zipPath = join(import.meta.dir, '..', 'templates.zip'); + +// Skip if templates folder already exists (source repo or already extracted) +if (existsSync(templatesPath)) { + process.exit(0); +} + +// Zip file must exist in installed package +if (!existsSync(zipPath)) { + console.error('ERROR: templates.zip not found. Installation may be corrupted.'); + process.exit(1); +} + +try { + const zip = new AdmZip(zipPath); + zip.extractAllTo(templatesPath, true); + + if (!existsSync(templatesPath)) { + throw new Error('Templates folder was not created after extraction'); + } +} catch (error) { + console.error('ERROR: Failed to extract templates:', error instanceof Error ? error.message : error); + console.error('Report this issue: https://github.com/truehazker/create-ely/issues'); + process.exit(1); +} diff --git a/scripts/prepare.ts b/scripts/prepare.ts new file mode 100644 index 0000000..0e35198 --- /dev/null +++ b/scripts/prepare.ts @@ -0,0 +1,39 @@ +#!/usr/bin/env bun +import { existsSync, unlinkSync } from 'node:fs'; +import { join } from 'node:path'; +import AdmZip from 'adm-zip'; + +/** + * Prepare script that runs before publishing + * Zips the templates folder to preserve .gitignore files + * See: https://johnnyreilly.com/smuggling-gitignore-npmrc-in-npm-packages + */ +const templatesPath = join(import.meta.dir, '..', 'templates'); +const zipPath = join(import.meta.dir, '..', 'templates.zip'); + +// Templates folder must exist +if (!existsSync(templatesPath)) { + console.error('ERROR: templates folder not found. Cannot create archive.'); + process.exit(1); +} + +try { + // Remove existing zip if it exists + if (existsSync(zipPath)) { + unlinkSync(zipPath); + } + + // Create zip archive + const zip = new AdmZip(); + zip.addLocalFolder(templatesPath); + zip.writeZip(zipPath); + + if (!existsSync(zipPath)) { + throw new Error('templates.zip was not created'); + } + + console.log('✓ templates.zip created successfully'); +} catch (error) { + console.error('ERROR: Failed to create templates.zip:', error instanceof Error ? error.message : error); + process.exit(1); +} From 83bf92a320d1a9fc2c748f77346dac5f5e44d466 Mon Sep 17 00:00:00 2001 From: truehazker <40111175+truehazker@users.noreply.github.com> Date: Sun, 4 Jan 2026 14:57:32 +0400 Subject: [PATCH 2/2] style: :rotating_light: fix linter warnings --- package.json | 8 +++++++- scripts/postinstall.ts | 13 ++++++++++--- scripts/prepare.ts | 5 ++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index e509753..2f22a62 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,13 @@ "bin": { "create-ely": "./src/index.ts" }, - "files": ["src", "templates.zip", "scripts/postinstall.ts", "README.md", "LICENSE"], + "files": [ + "src", + "templates.zip", + "scripts/postinstall.ts", + "README.md", + "LICENSE" + ], "scripts": { "dev": "bun run src/index.ts", "build": "bun build src/index.ts --compile --outfile dist/create-ely", diff --git a/scripts/postinstall.ts b/scripts/postinstall.ts index b831d51..00734ad 100644 --- a/scripts/postinstall.ts +++ b/scripts/postinstall.ts @@ -18,7 +18,9 @@ if (existsSync(templatesPath)) { // Zip file must exist in installed package if (!existsSync(zipPath)) { - console.error('ERROR: templates.zip not found. Installation may be corrupted.'); + console.error( + 'ERROR: templates.zip not found. Installation may be corrupted.', + ); process.exit(1); } @@ -30,7 +32,12 @@ try { throw new Error('Templates folder was not created after extraction'); } } catch (error) { - console.error('ERROR: Failed to extract templates:', error instanceof Error ? error.message : error); - console.error('Report this issue: https://github.com/truehazker/create-ely/issues'); + console.error( + 'ERROR: Failed to extract templates:', + error instanceof Error ? error.message : error, + ); + console.error( + 'Report this issue: https://github.com/truehazker/create-ely/issues', + ); process.exit(1); } diff --git a/scripts/prepare.ts b/scripts/prepare.ts index 0e35198..06bedba 100644 --- a/scripts/prepare.ts +++ b/scripts/prepare.ts @@ -34,6 +34,9 @@ try { console.log('✓ templates.zip created successfully'); } catch (error) { - console.error('ERROR: Failed to create templates.zip:', error instanceof Error ? error.message : error); + console.error( + 'ERROR: Failed to create templates.zip:', + error instanceof Error ? error.message : error, + ); process.exit(1); }