From 5c53602842c5dd127343f1eeea99b34e01882379 Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Sun, 11 Jan 2026 19:02:55 +0000 Subject: [PATCH] feat(tsbundle): add npmextra-driven custom bundles, base64-ts output and interactive init wizard --- changelog.md | 10 ++ npmextra.json | 16 +- package.json | 2 + pnpm-lock.yaml | 312 ++++++++++++++++++++++++++++++++ ts/00_commitinfo_data.ts | 2 +- ts/interfaces/index.ts | 22 +++ ts/mod_custom/index.ts | 203 +++++++++++++++++++++ ts/mod_custom/plugins.ts | 1 + ts/mod_init/index.ts | 377 +++++++++++++++++++++++++++++++++++++++ ts/mod_init/plugins.ts | 5 + ts/mod_output/index.ts | 113 ++++++++++++ ts/mod_output/plugins.ts | 1 + ts/plugins.ts | 4 + ts/tsbundle.cli.ts | 69 ++----- 14 files changed, 1073 insertions(+), 64 deletions(-) create mode 100644 ts/mod_custom/index.ts create mode 100644 ts/mod_custom/plugins.ts create mode 100644 ts/mod_init/index.ts create mode 100644 ts/mod_init/plugins.ts create mode 100644 ts/mod_output/index.ts create mode 100644 ts/mod_output/plugins.ts diff --git a/changelog.md b/changelog.md index ab33f7c..b2834fc 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,15 @@ # Changelog +## 2026-01-11 - 2.7.0 - feat(tsbundle) +add npmextra-driven custom bundles, base64-ts output and interactive init wizard + +- Add CustomBundleHandler to process bundle configs from npmextra.json (ts/mod_custom/*) +- Implement Base64TsOutput for embedding bundled files as base64 TypeScript (ts/mod_output/*) +- Add interactive 'init' wizard to scaffold npmextra.json bundle presets (ts/mod_init/*) +- Wire new features into CLI: default command runs custom bundles, added 'custom' and 'init' commands (ts/tsbundle.cli.ts) +- Expose @push.rocks/npmextra and @push.rocks/smartinteract in plugins and add them to package.json dependencies +- Update npmextra.json structure and release registries configuration + ## 2025-12-02 - 2.6.3 - fix(cli) Use basename when collecting HTML files for the website CLI command to ensure correct relative paths diff --git a/npmextra.json b/npmextra.json index d4ec776..51c5a99 100644 --- a/npmextra.json +++ b/npmextra.json @@ -1,5 +1,5 @@ { - "gitzone": { + "@git.zone/cli": { "projectType": "npm", "module": { "githost": "gitlab.com", @@ -9,10 +9,16 @@ "npmPackagename": "@git.zone/tsbundle", "license": "MIT", "projectDomain": "git.zone" + }, + "release": { + "registries": [ + "https://verdaccio.lossless.one", + "https://registry.npmjs.org" + ], + "accessLevel": "public" } }, - "npmci": { - "npmGlobalTools": [], - "npmAccessLevel": "public" + "@ship.zone/szci": { + "npmGlobalTools": [] } -} +} \ No newline at end of file diff --git a/package.json b/package.json index 33b0014..b17e007 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,9 @@ }, "dependencies": { "@push.rocks/early": "^4.0.4", + "@push.rocks/npmextra": "^5.1.3", "@push.rocks/smartcli": "^4.0.19", + "@push.rocks/smartinteract": "^2.0.16", "@push.rocks/smartdelay": "^3.0.5", "@push.rocks/smartfs": "^1.1.3", "@push.rocks/smartlog": "^3.1.8", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 21dccbb..11f14de 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,6 +11,9 @@ importers: '@push.rocks/early': specifier: ^4.0.4 version: 4.0.4 + '@push.rocks/npmextra': + specifier: ^5.1.3 + version: 5.3.3 '@push.rocks/smartcli': specifier: ^4.0.19 version: 4.0.19 @@ -20,6 +23,9 @@ importers: '@push.rocks/smartfs': specifier: ^1.1.3 version: 1.1.3 + '@push.rocks/smartinteract': + specifier: ^2.0.16 + version: 2.0.16 '@push.rocks/smartlog': specifier: ^3.1.8 version: 3.1.10 @@ -695,6 +701,62 @@ packages: resolution: {integrity: sha512-mfOoUlIw8VBiJYPrl5RZfMzkXC/z7gbSpi2ecycrj/gRWLq2CMV+Q+0G+JPjeOmuNFgg0skEIzkVFzVYFP6URw==} engines: {node: '>=18.0.0'} + '@inquirer/checkbox@3.0.1': + resolution: {integrity: sha512-0hm2nrToWUdD6/UHnel/UKGdk1//ke5zGUpHIvk5ZWmaKezlGxZkOJXNSWsdxO/rEqTkbB3lNC2J6nBElV2aAQ==} + engines: {node: '>=18'} + + '@inquirer/confirm@4.0.1': + resolution: {integrity: sha512-46yL28o2NJ9doViqOy0VDcoTzng7rAb6yPQKU7VDLqkmbCaH4JqK4yk4XqlzNWy9PVC5pG1ZUXPBQv+VqnYs2w==} + engines: {node: '>=18'} + + '@inquirer/core@9.2.1': + resolution: {integrity: sha512-F2VBt7W/mwqEU4bL0RnHNZmC/OxzNx9cOYxHqnXX3MP6ruYvZUZAW9imgN9+h/uBT/oP8Gh888J2OZSbjSeWcg==} + engines: {node: '>=18'} + + '@inquirer/editor@3.0.1': + resolution: {integrity: sha512-VA96GPFaSOVudjKFraokEEmUQg/Lub6OXvbIEZU1SDCmBzRkHGhxoFAVaF30nyiB4m5cEbDgiI2QRacXZ2hw9Q==} + engines: {node: '>=18'} + + '@inquirer/expand@3.0.1': + resolution: {integrity: sha512-ToG8d6RIbnVpbdPdiN7BCxZGiHOTomOX94C2FaT5KOHupV40tKEDozp12res6cMIfRKrXLJyexAZhWVHgbALSQ==} + engines: {node: '>=18'} + + '@inquirer/figures@1.0.15': + resolution: {integrity: sha512-t2IEY+unGHOzAaVM5Xx6DEWKeXlDDcNPeDyUpsRc6CUhBfU3VQOEl+Vssh7VNp1dR8MdUJBWhuObjXCsVpjN5g==} + engines: {node: '>=18'} + + '@inquirer/input@3.0.1': + resolution: {integrity: sha512-BDuPBmpvi8eMCxqC5iacloWqv+5tQSJlUafYWUe31ow1BVXjW2a5qe3dh4X/Z25Wp22RwvcaLCc2siHobEOfzg==} + engines: {node: '>=18'} + + '@inquirer/number@2.0.1': + resolution: {integrity: sha512-QpR8jPhRjSmlr/mD2cw3IR8HRO7lSVOnqUvQa8scv1Lsr3xoAMMworcYW3J13z3ppjBFBD2ef1Ci6AE5Qn8goQ==} + engines: {node: '>=18'} + + '@inquirer/password@3.0.1': + resolution: {integrity: sha512-haoeEPUisD1NeE2IanLOiFr4wcTXGWrBOyAyPZi1FfLJuXOzNmxCJPgUrGYKVh+Y8hfGJenIfz5Wb/DkE9KkMQ==} + engines: {node: '>=18'} + + '@inquirer/prompts@6.0.1': + resolution: {integrity: sha512-yl43JD/86CIj3Mz5mvvLJqAOfIup7ncxfJ0Btnl0/v5TouVUyeEdcpknfgc+yMevS/48oH9WAkkw93m7otLb/A==} + engines: {node: '>=18'} + + '@inquirer/rawlist@3.0.1': + resolution: {integrity: sha512-VgRtFIwZInUzTiPLSfDXK5jLrnpkuSOh1ctfaoygKAdPqjcjKYmGh6sCY1pb0aGnCGsmhUxoqLDUAU0ud+lGXQ==} + engines: {node: '>=18'} + + '@inquirer/search@2.0.1': + resolution: {integrity: sha512-r5hBKZk3g5MkIzLVoSgE4evypGqtOannnB3PKTG9NRZxyFRKcfzrdxXXPcoJQsxJPzvdSU2Rn7pB7lw0GCmGAg==} + engines: {node: '>=18'} + + '@inquirer/select@3.0.1': + resolution: {integrity: sha512-lUDGUxPhdWMkN/fHy1Lk7pF3nK1fh/gqeyWXmctefhxLYxlDsc7vsPBEpxrfVGDsVdyYJsiJoD4bJ1b623cV1Q==} + engines: {node: '>=18'} + + '@inquirer/type@2.0.0': + resolution: {integrity: sha512-XvJRx+2KR3YXyYtPUUy+qd9i7p+GO9Ko6VIIpWlBrpWwXDv8WLFeHTxz35CfQFUiBMLXlGHhGzys7lqit9gWag==} + engines: {node: '>=18'} + '@isaacs/balanced-match@4.0.1': resolution: {integrity: sha512-yzMTt9lEb8Gv7zRioUilSglI0c0smZ9k5D65677DLWLtWJaXIS3CqcGyUFByYKlnUj6TkjLVs54fBl6+TiGQDQ==} engines: {node: 20 || >=22} @@ -824,6 +886,9 @@ packages: '@push.rocks/mongodump@1.1.0': resolution: {integrity: sha512-kW0ZUGyf1e4nwloVwBQjNId+MzgTcNS834C+RxH21i1NqyOubbpWZtJtPP+K+s35nSJRyCTy3ICfBMdDBTAm2w==} + '@push.rocks/npmextra@5.3.3': + resolution: {integrity: sha512-snLpSHwaQ5OXlZzF1KX/FY71W5LwajjBzor82Vue0smjEPnSeUPY5/JcVdMwtdprdJe13pc/EQQuIiL/zw4/yg==} + '@push.rocks/qenv@6.1.3': resolution: {integrity: sha512-+z2hsAU/7CIgpYLFqvda8cn9rUBMHqLdQLjsFfRn5jPoD7dJ5rFlpkbhfM4Ws8mHMniwWaxGKo+q/YBhtzRBLg==} @@ -902,6 +967,9 @@ packages: '@push.rocks/smarthash@3.2.6': resolution: {integrity: sha512-Mq/WNX0Tjjes3X1gHd/ZBwOOKSrAG/Z3Xoc0OcCm3P20WKpniihkMpsnlE7wGjvpHLi/ZRe/XkB3KC3d5r9X4g==} + '@push.rocks/smartinteract@2.0.16': + resolution: {integrity: sha512-eltvVRRUKBKd77DSFA4DPY2g4V4teZLNe8A93CDy/WglglYcUjxMoLY/b0DFTWCWKYT+yjk6Fe6p0FRrvX9Yvg==} + '@push.rocks/smartjson@5.2.0': resolution: {integrity: sha512-710e8UwovRfPgUtaBHcd6unaODUjV5fjxtGcGCqtaTcmvOV6VpasdVfT66xMDzQmWH2E9ZfHDJeso9HdDQzNQA==} @@ -1549,9 +1617,15 @@ packages: '@types/ms@2.1.0': resolution: {integrity: sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA==} + '@types/mute-stream@0.0.4': + resolution: {integrity: sha512-CPM9nzrCPPJHQNA9keH9CVkVI+WR5kMa+7XEs5jcGQ0VoAGnLv242w8lIVgwAEfmE4oufJRaTc9PNLQl0ioAow==} + '@types/node-forge@1.3.14': resolution: {integrity: sha512-mhVF2BnD4BO+jtOp7z1CdzaK4mbuK0LLQYAvdOLqHTavxFNq4zA1EmYkpnFjP8HOUzedfQkRnp0E2ulSAYSzAw==} + '@types/node@22.19.5': + resolution: {integrity: sha512-HfF8+mYcHPcPypui3w3mvzuIErlNOh2OAG+BCeBZCEwyiD5ls2SiCwEyT47OELtf7M3nHxBdu0FsmzdKxkN52Q==} + '@types/node@24.10.1': resolution: {integrity: sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ==} @@ -1615,6 +1689,9 @@ packages: '@types/which@3.0.4': resolution: {integrity: sha512-liyfuo/106JdlgSchJzXEQCVArk0CvevqPote8F8HgWgJ3dRCcTHgJIsLDuee0kxk/mhbInzIZk3QWSZJ8R+2w==} + '@types/wrap-ansi@3.0.0': + resolution: {integrity: sha512-ltIpx+kM7g/MLRZfkbL7EsCEjfzCcScLpkg37eXEtx5kmrAKBkTJwd1GIAjDSL8wTpM6Hzn5YO4pSb91BEwu1g==} + '@types/ws@8.18.1': resolution: {integrity: sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg==} @@ -1648,6 +1725,10 @@ packages: resolution: {integrity: sha1-kQ3lDvzHwJ49gvL4er1rcAwYgYo=} engines: {node: '>=0.10.0'} + ansi-escapes@4.3.2: + resolution: {integrity: sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ==} + engines: {node: '>=8'} + ansi-regex@5.0.1: resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==} engines: {node: '>=8'} @@ -1832,6 +1913,9 @@ packages: character-entities@2.0.2: resolution: {integrity: sha512-shx7oQ0Awen/BRIdkjkvz54PnEEI/EjwXDSIZp86/KKdbafHh1Df/RYGBhn4hbe2+uKC9FnT5UCEdyPz3ai9hQ==} + chardet@0.7.0: + resolution: {integrity: sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==} + chokidar@4.0.3: resolution: {integrity: sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA==} engines: {node: '>= 14.16.0'} @@ -1849,6 +1933,10 @@ packages: resolution: {integrity: sha1-noIVAa6XmYbEax1m0tQy2y/UrjE=} engines: {node: '>=4'} + cli-width@4.1.0: + resolution: {integrity: sha512-ouuZd4/dm2Sw5Gmqy6bGyNNNe1qt9RpmxveLSO7KcgsTnU7RXfsw+/bukWGo1abgBiMAic068rclZsO4IWmmxQ==} + engines: {node: '>= 12'} + cliui@8.0.1: resolution: {integrity: sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==} engines: {node: '>=12'} @@ -2129,6 +2217,10 @@ packages: extend@3.0.2: resolution: {integrity: sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==} + external-editor@3.1.0: + resolution: {integrity: sha512-hMQ4CX1p1izmuLYyZqLMO/qGNw10wSv9QDCPfzXfyFrOaCSSoRfqE1Kf1s5an66J5JZC62NewG+mK49jOCtQew==} + engines: {node: '>=4'} + extract-zip@2.0.1: resolution: {integrity: sha512-GDhU9ntwuKyGXdZBUgTIe+vXnWj0fppUEtMDL0+idd5Sta8TGpHssn/eusA9mrPr9qNDym6SxAYZjNvCn/9RBg==} engines: {node: '>= 10.17.0'} @@ -2369,6 +2461,10 @@ packages: humanize-ms@1.2.1: resolution: {integrity: sha1-xG4xWaKT9riW2ikxbYtv6Lt5u+0=} + iconv-lite@0.4.24: + resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==} + engines: {node: '>=0.10.0'} + iconv-lite@0.6.3: resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==} engines: {node: '>=0.10.0'} @@ -2393,6 +2489,10 @@ packages: ini@1.3.8: resolution: {integrity: sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==} + inquirer@11.1.0: + resolution: {integrity: sha512-CmLAZT65GG/v30c+D2Fk8+ceP6pxD6RL+hIUOWAltCmeyEqWYwqu9v76q03OvjyZ3AB0C1Ala2stn1z/rMqGEw==} + engines: {node: '>=18'} + ip-address@10.1.0: resolution: {integrity: sha512-XXADHxXmvT9+CRxhXg56LJovE+bmWnEWB78LB83VZTprKTmaC5QfruXocxzTZ2Kl0DNwKuBdlIhjL8LeY8Sf8Q==} engines: {node: '>= 12'} @@ -2834,6 +2934,10 @@ packages: ms@2.1.3: resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==} + mute-stream@1.0.0: + resolution: {integrity: sha512-avsJQhyd+680gKXyG/sQc0nXaC6rBkPOfyHYcFb9+hdkqQkR9bdnkJ0AMZhke0oesPqIO+mFFJ+IdBc7mst4IA==} + engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} + nanoid@4.0.2: resolution: {integrity: sha512-7ZtY5KTCNheRGfEFxnedV5zFiORN1+Y1N6zvPTnHQd8ENUvfaDBeuJDZb2bN/oXwXxu3qkTXDzy57W5vAmDTBw==} engines: {node: ^14 || ^16 || >=18} @@ -2900,6 +3004,10 @@ packages: resolution: {integrity: sha512-7x81NCL719oNbsq/3mh+hVrAWmFuEYUqrq/Iw3kUzH8ReypT9QQ0BLoJS7/G9k6N81XjW4qHWtjWwe/9eLy1EQ==} engines: {node: '>=12'} + os-tmpdir@1.0.2: + resolution: {integrity: sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=} + engines: {node: '>=0.10.0'} + p-cancelable@3.0.0: resolution: {integrity: sha512-mlVgR3PGuzlo0MmTdk4cXqXWlwQDLnONTAg6sm62XkMJEiRxN3GL3SffkYvqwonbkJBcrI7Uvv5Zh9yjvn2iUw==} engines: {node: '>=12.20'} @@ -3163,6 +3271,10 @@ packages: resolution: {integrity: sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ==} engines: {node: '>= 18'} + run-async@3.0.0: + resolution: {integrity: sha512-540WwVDOMxA6dN6We19EcT9sc3hkXPw5mzRNGM3FkdN/vtE9NFvj5lFAPNwUDmJjXidm3v7TC1cTE7t17Ulm1Q==} + engines: {node: '>=0.12.0'} + rxjs@7.8.2: resolution: {integrity: sha512-dhKf903U/PQZY6boNNtAGdWbG85WAbjT/1xYoZIC7FAY0yWapOBQVsVrDl58W86//e1VpMNBtRV4MaXfdMySFA==} @@ -3352,6 +3464,10 @@ packages: tiny-worker@2.3.0: resolution: {integrity: sha512-pJ70wq5EAqTAEl9IkGzA+fN0836rycEuz2Cn6yeZ6FRzlVS5IDOkFHpIoEsksPRQV34GDqXm65+OlnZqUSyK2g==} + tmp@0.0.33: + resolution: {integrity: sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==} + engines: {node: '>=0.6.0'} + toidentifier@1.0.1: resolution: {integrity: sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==} engines: {node: '>=0.6'} @@ -3395,6 +3511,10 @@ packages: turndown@7.2.2: resolution: {integrity: sha512-1F7db8BiExOKxjSMU2b7if62D/XOyQyZbPKq/nUwopfgnHlqXHqQ0lvfUTeUIr1lZJzOPFn43dODyMSIfvWRKQ==} + type-fest@0.21.3: + resolution: {integrity: sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==} + engines: {node: '>=10'} + type-fest@2.19.0: resolution: {integrity: sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==} engines: {node: '>=12.20'} @@ -3429,6 +3549,9 @@ packages: resolution: {integrity: sha512-rvKSBiC5zqCCiDZ9kAOszZcDvdAHwwIKJG33Ykj43OKcWsnmcBRL09YTU4nOeHZ8Y2a7l1MgTd08SBe9A8Qj6A==} engines: {node: '>=18'} + undici-types@6.21.0: + resolution: {integrity: sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==} + undici-types@7.16.0: resolution: {integrity: sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==} @@ -3510,6 +3633,10 @@ packages: engines: {node: ^18.17.0 || >=20.5.0} hasBin: true + wrap-ansi@6.2.0: + resolution: {integrity: sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==} + engines: {node: '>=8'} + wrap-ansi@7.0.0: resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==} engines: {node: '>=10'} @@ -3577,6 +3704,10 @@ packages: resolution: {integrity: sha512-Ow9nuGZE+qp1u4JIPvg+uCiUr7xGQWdff7JQSk5VGYTAZMDe2q8lxJ10ygv10qmSj031Ty/6FNJpLO4o1Sgc+w==} engines: {node: '>=12'} + yoctocolors-cjs@2.1.3: + resolution: {integrity: sha512-U/PBtDf35ff0D8X8D0jfdzHYEPFxAI7jJlxZXwCSez5M3190m+QobIfh+sWDWSHMCWWJN2AWamkegn6vr6YBTw==} + engines: {node: '>=18'} + zod@3.25.76: resolution: {integrity: sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==} @@ -4837,6 +4968,102 @@ snapshots: dependencies: happy-dom: 15.11.7 + '@inquirer/checkbox@3.0.1': + dependencies: + '@inquirer/core': 9.2.1 + '@inquirer/figures': 1.0.15 + '@inquirer/type': 2.0.0 + ansi-escapes: 4.3.2 + yoctocolors-cjs: 2.1.3 + + '@inquirer/confirm@4.0.1': + dependencies: + '@inquirer/core': 9.2.1 + '@inquirer/type': 2.0.0 + + '@inquirer/core@9.2.1': + dependencies: + '@inquirer/figures': 1.0.15 + '@inquirer/type': 2.0.0 + '@types/mute-stream': 0.0.4 + '@types/node': 22.19.5 + '@types/wrap-ansi': 3.0.0 + ansi-escapes: 4.3.2 + cli-width: 4.1.0 + mute-stream: 1.0.0 + signal-exit: 4.1.0 + strip-ansi: 6.0.1 + wrap-ansi: 6.2.0 + yoctocolors-cjs: 2.1.3 + + '@inquirer/editor@3.0.1': + dependencies: + '@inquirer/core': 9.2.1 + '@inquirer/type': 2.0.0 + external-editor: 3.1.0 + + '@inquirer/expand@3.0.1': + dependencies: + '@inquirer/core': 9.2.1 + '@inquirer/type': 2.0.0 + yoctocolors-cjs: 2.1.3 + + '@inquirer/figures@1.0.15': {} + + '@inquirer/input@3.0.1': + dependencies: + '@inquirer/core': 9.2.1 + '@inquirer/type': 2.0.0 + + '@inquirer/number@2.0.1': + dependencies: + '@inquirer/core': 9.2.1 + '@inquirer/type': 2.0.0 + + '@inquirer/password@3.0.1': + dependencies: + '@inquirer/core': 9.2.1 + '@inquirer/type': 2.0.0 + ansi-escapes: 4.3.2 + + '@inquirer/prompts@6.0.1': + dependencies: + '@inquirer/checkbox': 3.0.1 + '@inquirer/confirm': 4.0.1 + '@inquirer/editor': 3.0.1 + '@inquirer/expand': 3.0.1 + '@inquirer/input': 3.0.1 + '@inquirer/number': 2.0.1 + '@inquirer/password': 3.0.1 + '@inquirer/rawlist': 3.0.1 + '@inquirer/search': 2.0.1 + '@inquirer/select': 3.0.1 + + '@inquirer/rawlist@3.0.1': + dependencies: + '@inquirer/core': 9.2.1 + '@inquirer/type': 2.0.0 + yoctocolors-cjs: 2.1.3 + + '@inquirer/search@2.0.1': + dependencies: + '@inquirer/core': 9.2.1 + '@inquirer/figures': 1.0.15 + '@inquirer/type': 2.0.0 + yoctocolors-cjs: 2.1.3 + + '@inquirer/select@3.0.1': + dependencies: + '@inquirer/core': 9.2.1 + '@inquirer/figures': 1.0.15 + '@inquirer/type': 2.0.0 + ansi-escapes: 4.3.2 + yoctocolors-cjs: 2.1.3 + + '@inquirer/type@2.0.0': + dependencies: + mute-stream: 1.0.0 + '@isaacs/balanced-match@4.0.1': {} '@isaacs/brace-expansion@5.0.0': @@ -5092,6 +5319,23 @@ snapshots: - snappy - socks + '@push.rocks/npmextra@5.3.3': + dependencies: + '@push.rocks/qenv': 6.1.3 + '@push.rocks/smartfile': 11.2.7 + '@push.rocks/smartjson': 5.2.0 + '@push.rocks/smartlog': 3.1.10 + '@push.rocks/smartpath': 6.0.0 + '@push.rocks/smartpromise': 4.2.3 + '@push.rocks/smartrx': 3.0.10 + '@push.rocks/taskbuffer': 3.4.0 + '@tsclass/tsclass': 9.3.0 + transitivePeerDependencies: + - '@nuxt/kit' + - react + - supports-color + - vue + '@push.rocks/qenv@6.1.3': dependencies: '@api.global/typedrequest': 3.1.10 @@ -5342,6 +5586,13 @@ snapshots: '@types/through2': 2.0.41 through2: 4.0.2 + '@push.rocks/smartinteract@2.0.16': + dependencies: + '@push.rocks/lik': 6.2.2 + '@push.rocks/smartobject': 1.0.12 + '@push.rocks/smartpromise': 4.2.3 + inquirer: 11.1.0 + '@push.rocks/smartjson@5.2.0': dependencies: '@push.rocks/smartenv': 5.0.13 @@ -6340,10 +6591,18 @@ snapshots: '@types/ms@2.1.0': {} + '@types/mute-stream@0.0.4': + dependencies: + '@types/node': 24.10.1 + '@types/node-forge@1.3.14': dependencies: '@types/node': 24.10.1 + '@types/node@22.19.5': + dependencies: + undici-types: 6.21.0 + '@types/node@24.10.1': dependencies: undici-types: 7.16.0 @@ -6405,6 +6664,8 @@ snapshots: '@types/which@3.0.4': {} + '@types/wrap-ansi@3.0.0': {} + '@types/ws@8.18.1': dependencies: '@types/node': 24.10.1 @@ -6444,6 +6705,10 @@ snapshots: ansi-256-colors@1.1.0: {} + ansi-escapes@4.3.2: + dependencies: + type-fest: 0.21.3 + ansi-regex@5.0.1: {} ansi-regex@6.2.2: {} @@ -6628,6 +6893,8 @@ snapshots: character-entities@2.0.2: {} + chardet@0.7.0: {} + chokidar@4.0.3: dependencies: readdirp: 4.1.2 @@ -6644,6 +6911,8 @@ snapshots: clean-stack@1.3.0: {} + cli-width@4.1.0: {} + cliui@8.0.1: dependencies: string-width: 4.2.3 @@ -6980,6 +7249,12 @@ snapshots: extend@3.0.2: {} + external-editor@3.1.0: + dependencies: + chardet: 0.7.0 + iconv-lite: 0.4.24 + tmp: 0.0.33 + extract-zip@2.0.1: dependencies: debug: 4.4.3 @@ -7290,6 +7565,10 @@ snapshots: dependencies: ms: 2.1.3 + iconv-lite@0.4.24: + dependencies: + safer-buffer: 2.1.2 + iconv-lite@0.6.3: dependencies: safer-buffer: 2.1.2 @@ -7314,6 +7593,17 @@ snapshots: ini@1.3.8: {} + inquirer@11.1.0: + dependencies: + '@inquirer/core': 9.2.1 + '@inquirer/prompts': 6.0.1 + '@inquirer/type': 2.0.0 + '@types/mute-stream': 0.0.4 + ansi-escapes: 4.3.2 + mute-stream: 1.0.0 + run-async: 3.0.0 + rxjs: 7.8.2 + ip-address@10.1.0: {} ipaddr.js@1.9.1: {} @@ -7905,6 +8195,8 @@ snapshots: ms@2.1.3: {} + mute-stream@1.0.0: {} + nanoid@4.0.2: {} negotiator@0.6.3: {} @@ -7955,6 +8247,8 @@ snapshots: is-docker: 2.2.1 is-wsl: 2.2.0 + os-tmpdir@1.0.2: {} + p-cancelable@3.0.0: {} p-finally@1.0.0: {} @@ -8280,6 +8574,8 @@ snapshots: transitivePeerDependencies: - supports-color + run-async@3.0.0: {} + rxjs@7.8.2: dependencies: tslib: 2.8.1 @@ -8550,6 +8846,10 @@ snapshots: dependencies: esm: 3.2.25 + tmp@0.0.33: + dependencies: + os-tmpdir: 1.0.2 + toidentifier@1.0.1: {} token-types@6.1.1: @@ -8589,6 +8889,8 @@ snapshots: dependencies: '@mixmark-io/domino': 2.2.0 + type-fest@0.21.3: {} + type-fest@2.19.0: {} type-fest@4.41.0: {} @@ -8609,6 +8911,8 @@ snapshots: uint8array-extras@1.5.0: {} + undici-types@6.21.0: {} + undici-types@7.16.0: {} unified@11.0.5: @@ -8692,6 +8996,12 @@ snapshots: dependencies: isexe: 3.1.1 + wrap-ansi@6.2.0: + dependencies: + ansi-styles: 4.3.0 + string-width: 4.2.3 + strip-ansi: 6.0.1 + wrap-ansi@7.0.0: dependencies: ansi-styles: 4.3.0 @@ -8740,6 +9050,8 @@ snapshots: buffer-crc32: 0.2.13 pend: 1.2.0 + yoctocolors-cjs@2.1.3: {} + zod@3.25.76: {} zwitch@2.0.4: {} diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 158fb93..c3c8966 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@git.zone/tsbundle', - version: '2.6.3', + version: '2.7.0', description: 'a multi-bundler tool supporting esbuild, rolldown, and rspack for painless bundling of web projects' } diff --git a/ts/interfaces/index.ts b/ts/interfaces/index.ts index fdef355..5858162 100644 --- a/ts/interfaces/index.ts +++ b/ts/interfaces/index.ts @@ -12,3 +12,25 @@ export interface IEnvTransportOptions { mode: 'test' | 'production'; argv: ICliOptions; } + +// Custom bundle configuration types +export type TOutputMode = 'bundle' | 'base64ts'; +export type TBundler = 'esbuild' | 'rolldown' | 'rspack'; + +export interface IBundleConfig { + from: string; + to: string; + outputMode?: TOutputMode; + bundler?: TBundler; + production?: boolean; + includeFiles?: string[]; +} + +export interface ITsbundleConfig { + bundles: IBundleConfig[]; +} + +export interface IBase64File { + path: string; + contentBase64: string; +} diff --git a/ts/mod_custom/index.ts b/ts/mod_custom/index.ts new file mode 100644 index 0000000..9e4ae66 --- /dev/null +++ b/ts/mod_custom/index.ts @@ -0,0 +1,203 @@ +import * as plugins from './plugins.js'; +import * as paths from '../paths.js'; +import * as interfaces from '../interfaces/index.js'; +import { TsBundle } from '../tsbundle.class.tsbundle.js'; +import { HtmlHandler } from '../mod_html/index.js'; +import { Base64TsOutput } from '../mod_output/index.js'; + +const TEMP_DIR = '.nogit/tsbundle-temp'; + +export class CustomBundleHandler { + private cwd: string; + private config: interfaces.ITsbundleConfig; + + constructor(cwd: string = paths.cwd) { + this.cwd = cwd; + } + + /** + * Load configuration from npmextra.json + */ + public async loadConfig(): Promise { + const npmextraInstance = new plugins.npmextra.Npmextra(this.cwd); + this.config = npmextraInstance.dataFor('@git.zone/tsbundle', { + bundles: [], + }); + + if (!this.config.bundles || this.config.bundles.length === 0) { + console.log('No bundle configuration found.'); + console.log('Run `tsbundle init` to create one.'); + return false; + } + + console.log(`Found ${this.config.bundles.length} bundle configuration(s)`); + return true; + } + + /** + * Process all configured bundles + */ + public async processAllBundles(): Promise { + for (let i = 0; i < this.config.bundles.length; i++) { + const bundleConfig = this.config.bundles[i]; + console.log(`\nProcessing bundle ${i + 1}/${this.config.bundles.length}: ${bundleConfig.from} -> ${bundleConfig.to}`); + await this.processSingleBundle(bundleConfig); + } + } + + /** + * Process a single bundle configuration + */ + private async processSingleBundle(bundleConfig: interfaces.IBundleConfig): Promise { + const outputMode = bundleConfig.outputMode || 'bundle'; + const bundler = bundleConfig.bundler || 'esbuild'; + + // Determine temp output path + const tempDir = plugins.path.join(this.cwd, TEMP_DIR); + const tempBundlePath = plugins.path.join(tempDir, `bundle-${Date.now()}.js`); + + // Ensure temp directory exists + await plugins.fs.directory(tempDir).create(); + + // Build the bundle to temp location + const tsbundle = new TsBundle(); + await tsbundle.build( + this.cwd, + bundleConfig.from, + tempBundlePath, + { + bundler, + production: bundleConfig.production || false, + } + ); + + if (outputMode === 'base64ts') { + await this.handleBase64TsOutput(bundleConfig, tempBundlePath); + } else { + await this.handleBundleOutput(bundleConfig, tempBundlePath); + } + + // Clean up temp file + const tempFileExists = await plugins.fs.file(tempBundlePath).exists(); + if (tempFileExists) { + await plugins.fs.file(tempBundlePath).delete(); + } + } + + /** + * Handle base64ts output mode + */ + private async handleBase64TsOutput( + bundleConfig: interfaces.IBundleConfig, + tempBundlePath: string + ): Promise { + const base64Output = new Base64TsOutput(this.cwd); + + // Add the bundle itself + const bundleContent = await plugins.fs.file(tempBundlePath).read(); + base64Output.addFile('bundle.js', bundleContent); + + // Add included files + if (bundleConfig.includeFiles && bundleConfig.includeFiles.length > 0) { + for (const pattern of bundleConfig.includeFiles) { + await base64Output.addFilesFromGlob(pattern); + } + } + + // Write the TypeScript output + await base64Output.writeToFile(bundleConfig.to); + } + + /** + * Handle standard bundle output mode + */ + private async handleBundleOutput( + bundleConfig: interfaces.IBundleConfig, + tempBundlePath: string + ): Promise { + // Move bundle to final destination + const toPath = plugins.smartpath.transform.toAbsolute(bundleConfig.to, this.cwd) as string; + const toDir = plugins.path.dirname(toPath); + await plugins.fs.directory(toDir).create(); + + const bundleContent = await plugins.fs.file(tempBundlePath).read(); + await plugins.fs.file(toPath).write(bundleContent); + console.log(`Bundle written to: ${bundleConfig.to}`); + + // Process included files (copy them) + if (bundleConfig.includeFiles && bundleConfig.includeFiles.length > 0) { + const htmlHandler = new HtmlHandler(); + const outputDir = plugins.path.dirname(toPath); + + for (const pattern of bundleConfig.includeFiles) { + await this.copyIncludedFiles(pattern, outputDir); + } + } + } + + /** + * Copy files matching a pattern to the output directory + */ + private async copyIncludedFiles(pattern: string, outputDir: string): Promise { + const absolutePattern = plugins.smartpath.transform.toAbsolute(pattern, this.cwd) as string; + const patternDir = plugins.path.dirname(absolutePattern); + const patternBase = plugins.path.basename(absolutePattern); + const isGlobPattern = patternBase.includes('*'); + + if (isGlobPattern) { + const dirPath = patternDir.replace(/\/\*\*$/, ''); + const dirExists = await plugins.fs.directory(dirPath).exists(); + if (!dirExists) { + console.log(`Directory does not exist: ${dirPath}`); + return; + } + + const isRecursive = pattern.includes('**'); + let entries; + if (isRecursive) { + entries = await plugins.fs.directory(dirPath).recursive().list(); + } else { + entries = await plugins.fs.directory(dirPath).list(); + } + + const filePattern = patternBase.replace('*', '.*'); + const regex = new RegExp(filePattern); + + for (const entry of entries) { + if (!entry.isDirectory && regex.test(entry.name)) { + const fullPath = plugins.path.join(dirPath, entry.path); + const relativePath = plugins.path.relative(this.cwd, fullPath); + const destPath = plugins.path.join(outputDir, plugins.path.basename(entry.path)); + await plugins.fs.directory(plugins.path.dirname(destPath)).create(); + await plugins.fs.file(fullPath).copy(destPath); + console.log(`Copied: ${relativePath} -> ${destPath}`); + } + } + } else { + const fileExists = await plugins.fs.file(absolutePattern).exists(); + if (!fileExists) { + console.log(`File does not exist: ${absolutePattern}`); + return; + } + const fileName = plugins.path.basename(absolutePattern); + const destPath = plugins.path.join(outputDir, fileName); + await plugins.fs.file(absolutePattern).copy(destPath); + console.log(`Copied: ${pattern} -> ${destPath}`); + } + } +} + +/** + * Run the custom bundle command + */ +export async function runCustomBundles(): Promise { + const handler = new CustomBundleHandler(); + const hasConfig = await handler.loadConfig(); + + if (!hasConfig) { + return; + } + + await handler.processAllBundles(); + console.log('\nCustom bundle processing complete!'); +} diff --git a/ts/mod_custom/plugins.ts b/ts/mod_custom/plugins.ts new file mode 100644 index 0000000..0bafc30 --- /dev/null +++ b/ts/mod_custom/plugins.ts @@ -0,0 +1 @@ +export * from '../plugins.js'; diff --git a/ts/mod_init/index.ts b/ts/mod_init/index.ts new file mode 100644 index 0000000..603ea5e --- /dev/null +++ b/ts/mod_init/index.ts @@ -0,0 +1,377 @@ +import * as plugins from './plugins.js'; +import * as paths from '../paths.js'; +import * as interfaces from '../interfaces/index.js'; + +// Preset configurations +const PRESETS: Record = { + element: { + description: 'Web component / element bundle', + config: { + from: './ts_web/index.ts', + to: './dist_bundle/bundle.js', + outputMode: 'bundle', + bundler: 'esbuild', + }, + }, + website: { + description: 'Full website with HTML and assets', + config: { + from: './ts_web/index.ts', + to: './dist_serve/bundle.js', + outputMode: 'bundle', + bundler: 'esbuild', + includeFiles: ['./html/**/*.html', './assets/**/*'], + }, + }, + npm: { + description: 'NPM package bundle (from ts/)', + config: { + from: './ts/index.ts', + to: './dist_bundle/bundle.js', + outputMode: 'bundle', + bundler: 'esbuild', + }, + }, +}; + +export class InitHandler { + private cwd: string; + private npmextraPath: string; + + constructor(cwd: string = paths.cwd) { + this.cwd = cwd; + this.npmextraPath = plugins.path.join(this.cwd, 'npmextra.json'); + } + + /** + * Load existing npmextra.json or create empty config + */ + private async loadExistingConfig(): Promise { + const fileExists = await plugins.fs.file(this.npmextraPath).exists(); + if (fileExists) { + const content = (await plugins.fs.file(this.npmextraPath).encoding('utf8').read()) as string; + try { + return JSON.parse(content); + } catch { + return {}; + } + } + return {}; + } + + /** + * Save config to npmextra.json + */ + private async saveConfig(config: any): Promise { + const content = JSON.stringify(config, null, 2); + await plugins.fs.file(this.npmextraPath).encoding('utf8').write(content); + console.log(`\nāœ… Configuration saved to npmextra.json`); + } + + /** + * Run the interactive init wizard + */ + public async runWizard(): Promise { + console.log('\nšŸš€ tsbundle configuration wizard\n'); + console.log('This wizard will help you configure bundle settings in npmextra.json.\n'); + + const npmextraJson = await this.loadExistingConfig(); + + if (!npmextraJson['@git.zone/tsbundle']) { + npmextraJson['@git.zone/tsbundle'] = { bundles: [] }; + } + + const existingBundles = npmextraJson['@git.zone/tsbundle'].bundles || []; + + if (existingBundles.length > 0) { + console.log(`Found ${existingBundles.length} existing bundle configuration(s):\n`); + existingBundles.forEach((bundle: interfaces.IBundleConfig, i: number) => { + console.log(` ${i + 1}. ${bundle.from} → ${bundle.to} (${bundle.outputMode || 'bundle'})`); + }); + console.log(''); + } + + let addMore = true; + while (addMore) { + const bundle = await this.configureSingleBundle(); + if (bundle) { + npmextraJson['@git.zone/tsbundle'].bundles.push(bundle); + console.log(`\nāœ… Bundle configuration added!`); + } + + const continueInteract = new plugins.smartinteract.SmartInteract(); + continueInteract.addQuestions([ + { + type: 'confirm', + name: 'addAnother', + message: 'Would you like to add another bundle configuration?', + default: false, + }, + ]); + const answers = await continueInteract.runQueue(); + addMore = answers.getAnswerFor('addAnother'); + } + + await this.saveConfig(npmextraJson); + + console.log('\nšŸ“‹ Final configuration:\n'); + const bundles = npmextraJson['@git.zone/tsbundle'].bundles; + bundles.forEach((bundle: interfaces.IBundleConfig, i: number) => { + console.log(` Bundle ${i + 1}:`); + console.log(` From: ${bundle.from}`); + console.log(` To: ${bundle.to}`); + console.log(` Mode: ${bundle.outputMode || 'bundle'}`); + console.log(` Bundler: ${bundle.bundler || 'esbuild'}`); + if (bundle.includeFiles && bundle.includeFiles.length > 0) { + console.log(` Include: ${bundle.includeFiles.join(', ')}`); + } + console.log(''); + }); + + console.log('Run `tsbundle` to build your bundles.\n'); + } + + /** + * Configure a single bundle interactively + */ + private async configureSingleBundle(): Promise { + // First, ask for preset or custom + const presetInteract = new plugins.smartinteract.SmartInteract(); + presetInteract.addQuestions([ + { + type: 'list', + name: 'preset', + message: 'Choose a configuration:', + choices: [ + { name: 'element - Web component / element bundle', value: 'element' }, + { name: 'website - Full website with HTML and assets', value: 'website' }, + { name: 'npm - NPM package bundle (from ts/)', value: 'npm' }, + { name: 'custom - Configure manually', value: 'custom' }, + ], + default: 'element', + }, + ]); + + const presetAnswers = await presetInteract.runQueue(); + const selectedPreset = presetAnswers.getAnswerFor('preset') as string; + + // If custom, go to full manual configuration + if (selectedPreset === 'custom') { + return this.configureManualBundle(); + } + + // Show preset config and ask if user wants to use it or customize + const preset = PRESETS[selectedPreset]; + console.log(`\nšŸ“¦ ${preset.description}:`); + console.log(` From: ${preset.config.from}`); + console.log(` To: ${preset.config.to}`); + console.log(` Mode: ${preset.config.outputMode}`); + console.log(` Bundler: ${preset.config.bundler}`); + if (preset.config.includeFiles && preset.config.includeFiles.length > 0) { + console.log(` Include: ${preset.config.includeFiles.join(', ')}`); + } + + const confirmInteract = new plugins.smartinteract.SmartInteract(); + confirmInteract.addQuestions([ + { + type: 'list', + name: 'action', + message: 'Use this configuration?', + choices: [ + { name: 'Yes, use as-is', value: 'use' }, + { name: 'Customize it', value: 'customize' }, + ], + default: 'use', + }, + ]); + + const confirmAnswers = await confirmInteract.runQueue(); + const action = confirmAnswers.getAnswerFor('action') as string; + + if (action === 'use') { + // Return the preset config directly + return { ...preset.config }; + } + + // Customize: pre-fill with preset values + return this.configureManualBundle(preset.config); + } + + /** + * Configure a bundle manually with optional pre-filled values + */ + private async configureManualBundle( + prefill?: Partial + ): Promise { + const interact = new plugins.smartinteract.SmartInteract(); + + // Basic configuration questions + interact.addQuestions([ + { + type: 'input', + name: 'from', + message: 'Entry point TypeScript file:', + default: prefill?.from || './ts_web/index.ts', + }, + { + type: 'input', + name: 'to', + message: 'Output file path:', + default: prefill?.to || './dist_bundle/bundle.js', + }, + { + type: 'list', + name: 'outputMode', + message: 'Output mode:', + choices: [ + { name: 'bundle - Standard JavaScript bundle file', value: 'bundle' }, + { + name: 'base64ts - TypeScript file with base64-encoded content (for Deno compile)', + value: 'base64ts', + }, + ], + default: prefill?.outputMode || 'bundle', + }, + { + type: 'list', + name: 'bundler', + message: 'Bundler to use:', + choices: [ + { name: 'esbuild (fastest, recommended)', value: 'esbuild' }, + { name: 'rolldown (Rust-based, Rollup compatible)', value: 'rolldown' }, + { name: 'rspack (Webpack compatible)', value: 'rspack' }, + ], + default: prefill?.bundler || 'esbuild', + }, + { + type: 'confirm', + name: 'production', + message: 'Enable production mode (minification)?', + default: prefill?.production || false, + }, + { + type: 'confirm', + name: 'hasIncludeFiles', + message: 'Include additional files (HTML, assets)?', + default: prefill?.includeFiles && prefill.includeFiles.length > 0 ? true : false, + }, + ]); + + const answers = await interact.runQueue(); + + const bundle: interfaces.IBundleConfig = { + from: answers.getAnswerFor('from'), + to: answers.getAnswerFor('to'), + outputMode: answers.getAnswerFor('outputMode') as interfaces.TOutputMode, + bundler: answers.getAnswerFor('bundler') as interfaces.TBundler, + production: answers.getAnswerFor('production'), + }; + + // Update default output path based on mode + if (bundle.outputMode === 'base64ts' && bundle.to === './dist_bundle/bundle.js') { + const suggestInteract = new plugins.smartinteract.SmartInteract(); + suggestInteract.addQuestions([ + { + type: 'input', + name: 'to', + message: 'For base64ts mode, suggest a .ts output path:', + default: './ts/embedded-bundle.ts', + }, + ]); + const suggestAnswers = await suggestInteract.runQueue(); + bundle.to = suggestAnswers.getAnswerFor('to'); + } + + // Handle include files + if (answers.getAnswerFor('hasIncludeFiles')) { + bundle.includeFiles = await this.configureIncludeFiles(prefill?.includeFiles); + } + + return bundle; + } + + /** + * Configure files to include + */ + private async configureIncludeFiles(prefill?: string[]): Promise { + const includeFiles: string[] = []; + let addMore = true; + + // If we have prefilled values, show them first + if (prefill && prefill.length > 0) { + console.log('\nPre-configured include patterns:'); + prefill.forEach((p) => console.log(` - ${p}`)); + + const keepInteract = new plugins.smartinteract.SmartInteract(); + keepInteract.addQuestions([ + { + type: 'confirm', + name: 'keepPrefill', + message: 'Keep these patterns?', + default: true, + }, + ]); + const keepAnswers = await keepInteract.runQueue(); + if (keepAnswers.getAnswerFor('keepPrefill')) { + includeFiles.push(...prefill); + } + } + + console.log('\nAdd files or glob patterns to include (e.g., ./html/index.html, ./assets/**/*):\n'); + + // Ask if user wants to add more patterns + const addInteract = new plugins.smartinteract.SmartInteract(); + addInteract.addQuestions([ + { + type: 'confirm', + name: 'addPatterns', + message: includeFiles.length > 0 ? 'Add more patterns?' : 'Add include patterns?', + default: includeFiles.length === 0, + }, + ]); + const addAnswers = await addInteract.runQueue(); + addMore = addAnswers.getAnswerFor('addPatterns'); + + while (addMore) { + const fileInteract = new plugins.smartinteract.SmartInteract(); + fileInteract.addQuestions([ + { + type: 'input', + name: 'pattern', + message: 'File or glob pattern:', + default: includeFiles.length === 0 ? './html/index.html' : '', + }, + ]); + + const fileAnswers = await fileInteract.runQueue(); + const pattern = fileAnswers.getAnswerFor('pattern'); + + if (pattern && pattern.trim()) { + includeFiles.push(pattern.trim()); + console.log(` Added: ${pattern}`); + } + + const continueInteract = new plugins.smartinteract.SmartInteract(); + continueInteract.addQuestions([ + { + type: 'confirm', + name: 'addMore', + message: 'Add another file/pattern?', + default: false, + }, + ]); + const continueAnswers = await continueInteract.runQueue(); + addMore = continueAnswers.getAnswerFor('addMore'); + } + + return includeFiles; + } +} + +/** + * Run the init command + */ +export async function runInit(): Promise { + const handler = new InitHandler(); + await handler.runWizard(); +} diff --git a/ts/mod_init/plugins.ts b/ts/mod_init/plugins.ts new file mode 100644 index 0000000..7bddba2 --- /dev/null +++ b/ts/mod_init/plugins.ts @@ -0,0 +1,5 @@ +export * from '../plugins.js'; + +import * as smartinteract from '@push.rocks/smartinteract'; + +export { smartinteract }; diff --git a/ts/mod_output/index.ts b/ts/mod_output/index.ts new file mode 100644 index 0000000..3071b0f --- /dev/null +++ b/ts/mod_output/index.ts @@ -0,0 +1,113 @@ +import * as plugins from './plugins.js'; +import * as paths from '../paths.js'; +import * as interfaces from '../interfaces/index.js'; + +export class Base64TsOutput { + private files: interfaces.IBase64File[] = []; + private cwd: string; + + constructor(cwd: string = paths.cwd) { + this.cwd = cwd; + } + + /** + * Add a file with its content to the output + */ + public addFile(filePath: string, content: Buffer | string): void { + const contentBuffer = typeof content === 'string' ? Buffer.from(content, 'utf-8') : content; + const contentBase64 = contentBuffer.toString('base64'); + this.files.push({ + path: filePath, + contentBase64, + }); + } + + /** + * Add files matching a glob pattern + */ + public async addFilesFromGlob(pattern: string): Promise { + const absolutePattern = plugins.smartpath.transform.toAbsolute(pattern, this.cwd) as string; + const patternDir = plugins.path.dirname(absolutePattern); + const patternBase = plugins.path.basename(absolutePattern); + + // Check if it's a directory pattern or file pattern + const isGlobPattern = patternBase.includes('*'); + + if (isGlobPattern) { + // Handle glob patterns + const dirPath = patternDir.replace(/\/\*\*$/, ''); + const dirExists = await plugins.fs.directory(dirPath).exists(); + if (!dirExists) { + console.log(`Directory does not exist: ${dirPath}`); + return; + } + + const isRecursive = pattern.includes('**'); + let entries; + if (isRecursive) { + entries = await plugins.fs.directory(dirPath).recursive().list(); + } else { + entries = await plugins.fs.directory(dirPath).list(); + } + + // Filter by pattern if needed + const filePattern = patternBase.replace('*', '.*'); + const regex = new RegExp(filePattern); + + for (const entry of entries) { + if (!entry.isDirectory && regex.test(entry.name)) { + const fullPath = plugins.path.join(dirPath, entry.path); + const relativePath = plugins.path.relative(this.cwd, fullPath); + const content = await plugins.fs.file(fullPath).read(); + this.addFile(relativePath, content); + } + } + } else { + // Handle single file path + const fileExists = await plugins.fs.file(absolutePattern).exists(); + if (!fileExists) { + console.log(`File does not exist: ${absolutePattern}`); + return; + } + const relativePath = plugins.path.relative(this.cwd, absolutePattern); + const content = await plugins.fs.file(absolutePattern).read(); + this.addFile(relativePath, content); + } + } + + /** + * Generate TypeScript file content + */ + public generateTypeScript(): string { + const filesJson = JSON.stringify(this.files, null, 2); + return `// Auto-generated by tsbundle - do not edit +export const files: { path: string; contentBase64: string }[] = ${filesJson}; +`; + } + + /** + * Write the TypeScript file to disk + */ + public async writeToFile(outputPath: string): Promise { + const absolutePath = plugins.smartpath.transform.toAbsolute(outputPath, this.cwd) as string; + const outputDir = plugins.path.dirname(absolutePath); + await plugins.fs.directory(outputDir).create(); + const content = this.generateTypeScript(); + await plugins.fs.file(absolutePath).encoding('utf8').write(content); + console.log(`Generated base64ts output: ${outputPath}`); + } + + /** + * Get all collected files + */ + public getFiles(): interfaces.IBase64File[] { + return this.files; + } + + /** + * Clear all collected files + */ + public clear(): void { + this.files = []; + } +} diff --git a/ts/mod_output/plugins.ts b/ts/mod_output/plugins.ts new file mode 100644 index 0000000..0bafc30 --- /dev/null +++ b/ts/mod_output/plugins.ts @@ -0,0 +1 @@ +export * from '../plugins.js'; diff --git a/ts/plugins.ts b/ts/plugins.ts index d7bbfe3..6781776 100644 --- a/ts/plugins.ts +++ b/ts/plugins.ts @@ -4,8 +4,10 @@ import * as path from 'path'; export { path }; // pushrocks scope +import * as npmextra from '@push.rocks/npmextra'; import * as smartcli from '@push.rocks/smartcli'; import * as smartfs from '@push.rocks/smartfs'; +import * as smartinteract from '@push.rocks/smartinteract'; import * as smartlog from '@push.rocks/smartlog'; import * as smartlogDestinationLocal from '@push.rocks/smartlog-destination-local'; import * as smartpath from '@push.rocks/smartpath'; @@ -13,8 +15,10 @@ import * as smartpromise from '@push.rocks/smartpromise'; import * as smartspawn from '@push.rocks/smartspawn'; export { + npmextra, smartcli, smartfs, + smartinteract, smartlog, smartlogDestinationLocal, smartpath, diff --git a/ts/tsbundle.cli.ts b/ts/tsbundle.cli.ts index 9c513a7..c0f8c48 100644 --- a/ts/tsbundle.cli.ts +++ b/ts/tsbundle.cli.ts @@ -1,70 +1,23 @@ import * as plugins from './plugins.js'; -import { TsBundle } from './tsbundle.class.tsbundle.js'; -import { HtmlHandler } from './mod_html/index.js'; -import { logger } from './tsbundle.logging.js'; -import { AssetsHandler } from './mod_assets/index.js'; +import { runCustomBundles } from './mod_custom/index.js'; +import { runInit } from './mod_init/index.js'; export const runCli = async () => { const tsBundleCli = new plugins.smartcli.Smartcli(); + + // Default command: run custom bundles from npmextra.json tsBundleCli.standardCommand().subscribe(async (argvArg) => { - const tsbundle = new TsBundle(); - await tsbundle.build(process.cwd(), argvArg.from, argvArg.to, argvArg); - return; + await runCustomBundles(); }); - tsBundleCli.addCommand('element').subscribe(async (argvArg) => { - const tsbundle = new TsBundle(); - await tsbundle.build( - process.cwd(), - './ts_web/index.ts', - './dist_bundle/bundle.js', - argvArg, - ); + // Explicit custom command (same as default) + tsBundleCli.addCommand('custom').subscribe(async (argvArg) => { + await runCustomBundles(); }); - tsBundleCli.addCommand('npm').subscribe(async (argvArg) => { - const tsbundle = new TsBundle(); - const htmlHandler = new HtmlHandler(); - await tsbundle.build( - process.cwd(), - './ts/index.ts', - './dist_bundle/bundle.js', - argvArg, - ); - }); - - tsBundleCli.addCommand('website').subscribe(async (argvArg) => { - const tsbundle = new TsBundle(); - - // lets deal with the html - const htmlHandler = new HtmlHandler(); - await tsbundle.build( - process.cwd(), - './ts_web/index.ts', - './dist_serve/bundle.js', - argvArg, - ); - const htmlDirPath = plugins.path.join(process.cwd(), './html'); - let htmlFiles: string[] = []; - const htmlDirExists = await plugins.fs.directory(htmlDirPath).exists(); - if (htmlDirExists) { - const entries = await plugins.fs - .directory(htmlDirPath) - .filter(/\.html$/) - .list(); - htmlFiles = entries.map((entry) => plugins.path.basename(entry.path)); - } - for (const htmlFile of htmlFiles) { - await htmlHandler.processHtml({ - from: `./html/${htmlFile}`, - to: `./dist_serve/${htmlFile}`, - minify: true, - }); - } - - // lets deal with the assets - const assetsHandler = new AssetsHandler(); - await assetsHandler.processAssets(); + // Interactive init wizard + tsBundleCli.addCommand('init').subscribe(async (argvArg) => { + await runInit(); }); tsBundleCli.startParse();