@temir.ra/create-template 0.4.2 → 0.4.4-pre.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -44,7 +44,7 @@ npm run clean
44
44
  npm run build
45
45
  npm run tests
46
46
 
47
- npmx tsx dist/cli.bundle.js -- example/
47
+ npx tsx dist/cli.bundle.js -- example/
48
48
  ```
49
49
 
50
50
  ## Change Management
@@ -1,5 +1,14 @@
1
1
  # Version 0
2
2
 
3
+ ## 0.4.4-pre.5
4
+
5
+ 1. Synced template files with `ts-lib@0.13.0-pre.7` template.
6
+ 2. Synced files with `self` as template.
7
+
8
+ ## 0.4.3
9
+
10
+ 1. Fixed versioning issue.
11
+
3
12
  ## 0.4.2
4
13
 
5
14
  1. Updated from `ts-lib@0.12.0-pre.1` template.
@@ -0,0 +1 @@
1
+ 0.4.4-pre.5+c4abf3a
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ var __importMetaUrl = document.currentScript && document.currentScript.src || '';
3
+ "use strict";(()=>{var i=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(n,t)=>(typeof require<"u"?require:n)[t]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var r=i("node:fs"),o=i("node:path");var a=new URL("../",__importMetaUrl),l=new URL("dist/",a),m=new URL("buildinfo.txt",l),p=new URL("CHANGELOG.md",l),g=new URL("README.md",a),U=new URL("template/",a);try{let e=process.argv[2];if(!e)throw new Error('First argument must be the package name (e.g. "my-package" or "@my-scope/my-package").');let n=e.replace(/\\/g,"/"),t=(0,o.resolve)(process.cwd(),n);(0,r.cpSync)(U,t,{recursive:!0}),(0,r.cpSync)(p,(0,o.resolve)(t,"CHANGELOG-template.md")),(0,r.cpSync)(m,(0,o.resolve)(t,"buildinfo-template.txt")),(0,r.cpSync)(g,(0,o.resolve)(t,"README-template.md"));let c=(0,o.resolve)(t,"package.json"),s=JSON.parse((0,r.readFileSync)(c,"utf-8"));s.name=n,(0,r.writeFileSync)(c,JSON.stringify(s,null,2)),(0,r.renameSync)((0,o.resolve)(t,"gitignore"),(0,o.resolve)(t,".gitignore")),console.log(`Template has been successfully instantiated at '${t}' with package name '${n}'.`)}catch(e){let n=e instanceof Error?e:new Error(String(e));console.error("Error:",n.message),process.exit(1)}})();
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/cli.ts", "../src/package-urls.ts"],
4
+ "sourcesContent": ["#!/usr/bin/env node\r\n\r\nimport { cpSync, readFileSync, renameSync, writeFileSync } from 'node:fs';\r\nimport { resolve } from 'node:path';\r\nimport {\r\n templateUrl,\r\n changelogUrl,\r\n buildinfoUrl,\r\n readmeUrl\r\n} from './package-urls.js';\r\n\r\n\r\ntry {\r\n\r\n const packageNameArgument = process.argv[2];\r\n if (!packageNameArgument)\r\n throw new Error('First argument must be the package name (e.g. \"my-package\" or \"@my-scope/my-package\").');\r\n const packageName = packageNameArgument.replace(/\\\\/g, '/');\r\n\r\n const destinationPath = resolve(process.cwd(), packageName);\r\n\r\n cpSync(templateUrl, destinationPath, { recursive: true });\r\n cpSync(changelogUrl, resolve(destinationPath, 'CHANGELOG-template.md'));\r\n cpSync(buildinfoUrl, resolve(destinationPath, 'buildinfo-template.txt'));\r\n cpSync(readmeUrl, resolve(destinationPath, 'README-template.md'));\r\n\r\n const packageJsonPath = resolve(destinationPath, 'package.json');\r\n const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));\r\n packageJson.name = packageName;\r\n writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));\r\n\r\n renameSync(resolve(destinationPath, 'gitignore'), resolve(destinationPath, '.gitignore'));\r\n\r\n console.log(`Template has been successfully instantiated at '${destinationPath}' with package name '${packageName}'.`);\r\n\r\n}\r\ncatch (error) {\r\n const err = error instanceof Error ? error : new Error(String(error));\r\n console.error('Error:', err.message);\r\n process.exit(1);\r\n}\r\n", "export const packageUrl: URL = new URL('../', import.meta.url);\r\n\r\nexport const distUrl: URL = new URL('dist/', packageUrl);\r\nexport const buildinfoUrl: URL = new URL('buildinfo.txt', distUrl);\r\nexport const changelogUrl: URL = new URL('CHANGELOG.md', distUrl);\r\nexport const readmeUrl: URL = new URL('README.md', packageUrl);\r\n\r\nexport const templateUrl: URL = new URL('template/', packageUrl);\r\n"],
5
+ "mappings": ";;4QAEA,IAAAA,EAAgE,aAChEC,EAAwB,eCHjB,IAAMC,EAAkB,IAAI,IAAI,MAAO,eAAe,EAEhDC,EAAe,IAAI,IAAI,QAASD,CAAU,EAC1CE,EAAoB,IAAI,IAAI,gBAAiBD,CAAO,EACpDE,EAAoB,IAAI,IAAI,eAAgBF,CAAO,EACnDG,EAAiB,IAAI,IAAI,YAAaJ,CAAU,EAEhDK,EAAmB,IAAI,IAAI,YAAaL,CAAU,EDK/D,GAAI,CAEA,IAAMM,EAAsB,QAAQ,KAAK,CAAC,EAC1C,GAAI,CAACA,EACD,MAAM,IAAI,MAAM,wFAAwF,EAC5G,IAAMC,EAAcD,EAAoB,QAAQ,MAAO,GAAG,EAEpDE,KAAkB,WAAQ,QAAQ,IAAI,EAAGD,CAAW,KAE1D,UAAOE,EAAaD,EAAiB,CAAE,UAAW,EAAK,CAAC,KACxD,UAAOE,KAAc,WAAQF,EAAiB,uBAAuB,CAAC,KACtE,UAAOG,KAAc,WAAQH,EAAiB,wBAAwB,CAAC,KACvE,UAAOI,KAAW,WAAQJ,EAAiB,oBAAoB,CAAC,EAEhE,IAAMK,KAAkB,WAAQL,EAAiB,cAAc,EACzDM,EAAc,KAAK,SAAM,gBAAaD,EAAiB,OAAO,CAAC,EACrEC,EAAY,KAAOP,KACnB,iBAAcM,EAAiB,KAAK,UAAUC,EAAa,KAAM,CAAC,CAAC,KAEnE,iBAAW,WAAQN,EAAiB,WAAW,KAAG,WAAQA,EAAiB,YAAY,CAAC,EAExF,QAAQ,IAAI,mDAAmDA,CAAe,wBAAwBD,CAAW,IAAI,CAEzH,OACOQ,EAAO,CACV,IAAMC,EAAMD,aAAiB,MAAQA,EAAQ,IAAI,MAAM,OAAOA,CAAK,CAAC,EACpE,QAAQ,MAAM,SAAUC,EAAI,OAAO,EACnC,QAAQ,KAAK,CAAC,CAClB",
6
+ "names": ["import_node_fs", "import_node_path", "packageUrl", "distUrl", "buildinfoUrl", "changelogUrl", "readmeUrl", "templateUrl", "packageNameArgument", "packageName", "destinationPath", "templateUrl", "changelogUrl", "buildinfoUrl", "readmeUrl", "packageJsonPath", "packageJson", "error", "err"]
7
+ }
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{cpSync as a,readFileSync as g,renameSync as U,writeFileSync as d}from"node:fs";import{resolve as r}from"node:path";var n=new URL("../",import.meta.url),i=new URL("README.md",n),l=new URL("CHANGELOG.md",n),m=new URL("buildinfo.txt",n),u=new URL("dist/",n),p=new URL("template/",n);try{let t=process.argv[2];if(!t)throw new Error('First argument must be the package name (e.g. "my-package" or "@my-scope/my-package").');let o=t.replace(/\\/g,"/"),e=r(process.cwd(),o);a(p,e,{recursive:!0}),a(l,r(e,"CHANGELOG-template.md")),a(m,r(e,"buildinfo-template.txt")),a(i,r(e,"README-template.md"));let c=r(e,"package.json"),s=JSON.parse(g(c,"utf-8"));s.name=o,d(c,JSON.stringify(s,null,2)),U(r(e,"gitignore"),r(e,".gitignore")),console.log(`Template has been successfully instantiated at '${e}' with package name '${o}'.`)}catch(t){let o=t instanceof Error?t:new Error(String(t));console.error("Error:",o.message),process.exit(1)}
2
+ import{cpSync as n,readFileSync as U,renameSync as d,writeFileSync as u}from"node:fs";import{resolve as r}from"node:path";var a=new URL("../",import.meta.url),i=new URL("dist/",a),l=new URL("buildinfo.txt",i),m=new URL("CHANGELOG.md",i),p=new URL("README.md",a),g=new URL("template/",a);try{let t=process.argv[2];if(!t)throw new Error('First argument must be the package name (e.g. "my-package" or "@my-scope/my-package").');let o=t.replace(/\\/g,"/"),e=r(process.cwd(),o);n(g,e,{recursive:!0}),n(m,r(e,"CHANGELOG-template.md")),n(l,r(e,"buildinfo-template.txt")),n(p,r(e,"README-template.md"));let c=r(e,"package.json"),s=JSON.parse(U(c,"utf-8"));s.name=o,u(c,JSON.stringify(s,null,2)),d(r(e,"gitignore"),r(e,".gitignore")),console.log(`Template has been successfully instantiated at '${e}' with package name '${o}'.`)}catch(t){let o=t instanceof Error?t:new Error(String(t));console.error("Error:",o.message),process.exit(1)}
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/cli.ts", "../src/constants.ts"],
4
- "sourcesContent": ["#!/usr/bin/env node\r\n\r\nimport { cpSync, readFileSync, renameSync, writeFileSync } from 'node:fs';\r\nimport { resolve } from 'node:path';\r\nimport {\r\n templateUrl,\r\n changelogUrl,\r\n buildinfoUrl,\r\n readmeUrl\r\n} from './constants.js';\r\n\r\n\r\ntry {\r\n\r\n const packageNameArgument = process.argv[2];\r\n if (!packageNameArgument)\r\n throw new Error('First argument must be the package name (e.g. \"my-package\" or \"@my-scope/my-package\").');\r\n const packageName = packageNameArgument.replace(/\\\\/g, '/');\r\n\r\n const destinationPath = resolve(process.cwd(), packageName);\r\n\r\n cpSync(templateUrl, destinationPath, { recursive: true });\r\n cpSync(changelogUrl, resolve(destinationPath, 'CHANGELOG-template.md'));\r\n cpSync(buildinfoUrl, resolve(destinationPath, 'buildinfo-template.txt'));\r\n cpSync(readmeUrl, resolve(destinationPath, 'README-template.md'));\r\n\r\n const packageJsonPath = resolve(destinationPath, 'package.json');\r\n const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));\r\n packageJson.name = packageName;\r\n writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));\r\n\r\n renameSync(resolve(destinationPath, 'gitignore'), resolve(destinationPath, '.gitignore'));\r\n\r\n console.log(`Template has been successfully instantiated at '${destinationPath}' with package name '${packageName}'.`);\r\n\r\n}\r\ncatch (error) {\r\n const err = error instanceof Error ? error : new Error(String(error));\r\n console.error('Error:', err.message);\r\n process.exit(1);\r\n}\r\n", "export const packageUrl: URL = new URL('../', import.meta.url);\r\n\r\nexport const readmeUrl: URL = new URL('README.md', packageUrl);\r\nexport const changelogUrl: URL = new URL('CHANGELOG.md', packageUrl);\r\nexport const buildinfoUrl: URL = new URL('buildinfo.txt', packageUrl);\r\nexport const distUrl: URL = new URL('dist/', packageUrl);\r\n\r\nexport const templateUrl: URL = new URL('template/', packageUrl);\r\n"],
5
- "mappings": ";AAEA,OAAS,UAAAA,EAAQ,gBAAAC,EAAc,cAAAC,EAAY,iBAAAC,MAAqB,UAChE,OAAS,WAAAC,MAAe,YCHjB,IAAMC,EAAkB,IAAI,IAAI,MAAO,YAAY,GAAG,EAEhDC,EAAiB,IAAI,IAAI,YAAaD,CAAU,EAChDE,EAAoB,IAAI,IAAI,eAAgBF,CAAU,EACtDG,EAAoB,IAAI,IAAI,gBAAiBH,CAAU,EACvDI,EAAe,IAAI,IAAI,QAASJ,CAAU,EAE1CK,EAAmB,IAAI,IAAI,YAAaL,CAAU,EDK/D,GAAI,CAEA,IAAMM,EAAsB,QAAQ,KAAK,CAAC,EAC1C,GAAI,CAACA,EACD,MAAM,IAAI,MAAM,wFAAwF,EAC5G,IAAMC,EAAcD,EAAoB,QAAQ,MAAO,GAAG,EAEpDE,EAAkBC,EAAQ,QAAQ,IAAI,EAAGF,CAAW,EAE1DG,EAAOC,EAAaH,EAAiB,CAAE,UAAW,EAAK,CAAC,EACxDE,EAAOE,EAAcH,EAAQD,EAAiB,uBAAuB,CAAC,EACtEE,EAAOG,EAAcJ,EAAQD,EAAiB,wBAAwB,CAAC,EACvEE,EAAOI,EAAWL,EAAQD,EAAiB,oBAAoB,CAAC,EAEhE,IAAMO,EAAkBN,EAAQD,EAAiB,cAAc,EACzDQ,EAAc,KAAK,MAAMC,EAAaF,EAAiB,OAAO,CAAC,EACrEC,EAAY,KAAOT,EACnBW,EAAcH,EAAiB,KAAK,UAAUC,EAAa,KAAM,CAAC,CAAC,EAEnEG,EAAWV,EAAQD,EAAiB,WAAW,EAAGC,EAAQD,EAAiB,YAAY,CAAC,EAExF,QAAQ,IAAI,mDAAmDA,CAAe,wBAAwBD,CAAW,IAAI,CAEzH,OACOa,EAAO,CACV,IAAMC,EAAMD,aAAiB,MAAQA,EAAQ,IAAI,MAAM,OAAOA,CAAK,CAAC,EACpE,QAAQ,MAAM,SAAUC,EAAI,OAAO,EACnC,QAAQ,KAAK,CAAC,CAClB",
6
- "names": ["cpSync", "readFileSync", "renameSync", "writeFileSync", "resolve", "packageUrl", "readmeUrl", "changelogUrl", "buildinfoUrl", "distUrl", "templateUrl", "packageNameArgument", "packageName", "destinationPath", "resolve", "cpSync", "templateUrl", "changelogUrl", "buildinfoUrl", "readmeUrl", "packageJsonPath", "packageJson", "readFileSync", "writeFileSync", "renameSync", "error", "err"]
3
+ "sources": ["../src/cli.ts", "../src/package-urls.ts"],
4
+ "sourcesContent": ["#!/usr/bin/env node\r\n\r\nimport { cpSync, readFileSync, renameSync, writeFileSync } from 'node:fs';\r\nimport { resolve } from 'node:path';\r\nimport {\r\n templateUrl,\r\n changelogUrl,\r\n buildinfoUrl,\r\n readmeUrl\r\n} from './package-urls.js';\r\n\r\n\r\ntry {\r\n\r\n const packageNameArgument = process.argv[2];\r\n if (!packageNameArgument)\r\n throw new Error('First argument must be the package name (e.g. \"my-package\" or \"@my-scope/my-package\").');\r\n const packageName = packageNameArgument.replace(/\\\\/g, '/');\r\n\r\n const destinationPath = resolve(process.cwd(), packageName);\r\n\r\n cpSync(templateUrl, destinationPath, { recursive: true });\r\n cpSync(changelogUrl, resolve(destinationPath, 'CHANGELOG-template.md'));\r\n cpSync(buildinfoUrl, resolve(destinationPath, 'buildinfo-template.txt'));\r\n cpSync(readmeUrl, resolve(destinationPath, 'README-template.md'));\r\n\r\n const packageJsonPath = resolve(destinationPath, 'package.json');\r\n const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));\r\n packageJson.name = packageName;\r\n writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));\r\n\r\n renameSync(resolve(destinationPath, 'gitignore'), resolve(destinationPath, '.gitignore'));\r\n\r\n console.log(`Template has been successfully instantiated at '${destinationPath}' with package name '${packageName}'.`);\r\n\r\n}\r\ncatch (error) {\r\n const err = error instanceof Error ? error : new Error(String(error));\r\n console.error('Error:', err.message);\r\n process.exit(1);\r\n}\r\n", "export const packageUrl: URL = new URL('../', import.meta.url);\r\n\r\nexport const distUrl: URL = new URL('dist/', packageUrl);\r\nexport const buildinfoUrl: URL = new URL('buildinfo.txt', distUrl);\r\nexport const changelogUrl: URL = new URL('CHANGELOG.md', distUrl);\r\nexport const readmeUrl: URL = new URL('README.md', packageUrl);\r\n\r\nexport const templateUrl: URL = new URL('template/', packageUrl);\r\n"],
5
+ "mappings": ";AAEA,OAAS,UAAAA,EAAQ,gBAAAC,EAAc,cAAAC,EAAY,iBAAAC,MAAqB,UAChE,OAAS,WAAAC,MAAe,YCHjB,IAAMC,EAAkB,IAAI,IAAI,MAAO,YAAY,GAAG,EAEhDC,EAAe,IAAI,IAAI,QAASD,CAAU,EAC1CE,EAAoB,IAAI,IAAI,gBAAiBD,CAAO,EACpDE,EAAoB,IAAI,IAAI,eAAgBF,CAAO,EACnDG,EAAiB,IAAI,IAAI,YAAaJ,CAAU,EAEhDK,EAAmB,IAAI,IAAI,YAAaL,CAAU,EDK/D,GAAI,CAEA,IAAMM,EAAsB,QAAQ,KAAK,CAAC,EAC1C,GAAI,CAACA,EACD,MAAM,IAAI,MAAM,wFAAwF,EAC5G,IAAMC,EAAcD,EAAoB,QAAQ,MAAO,GAAG,EAEpDE,EAAkBC,EAAQ,QAAQ,IAAI,EAAGF,CAAW,EAE1DG,EAAOC,EAAaH,EAAiB,CAAE,UAAW,EAAK,CAAC,EACxDE,EAAOE,EAAcH,EAAQD,EAAiB,uBAAuB,CAAC,EACtEE,EAAOG,EAAcJ,EAAQD,EAAiB,wBAAwB,CAAC,EACvEE,EAAOI,EAAWL,EAAQD,EAAiB,oBAAoB,CAAC,EAEhE,IAAMO,EAAkBN,EAAQD,EAAiB,cAAc,EACzDQ,EAAc,KAAK,MAAMC,EAAaF,EAAiB,OAAO,CAAC,EACrEC,EAAY,KAAOT,EACnBW,EAAcH,EAAiB,KAAK,UAAUC,EAAa,KAAM,CAAC,CAAC,EAEnEG,EAAWV,EAAQD,EAAiB,WAAW,EAAGC,EAAQD,EAAiB,YAAY,CAAC,EAExF,QAAQ,IAAI,mDAAmDA,CAAe,wBAAwBD,CAAW,IAAI,CAEzH,OACOa,EAAO,CACV,IAAMC,EAAMD,aAAiB,MAAQA,EAAQ,IAAI,MAAM,OAAOA,CAAK,CAAC,EACpE,QAAQ,MAAM,SAAUC,EAAI,OAAO,EACnC,QAAQ,KAAK,CAAC,CAClB",
6
+ "names": ["cpSync", "readFileSync", "renameSync", "writeFileSync", "resolve", "packageUrl", "distUrl", "buildinfoUrl", "changelogUrl", "readmeUrl", "templateUrl", "packageNameArgument", "packageName", "destinationPath", "resolve", "cpSync", "templateUrl", "changelogUrl", "buildinfoUrl", "readmeUrl", "packageJsonPath", "packageJson", "readFileSync", "writeFileSync", "renameSync", "error", "err"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temir.ra/create-template",
3
- "version": "0.4.2",
3
+ "version": "0.4.4-pre.5",
4
4
  "description": "A template for a template package.",
5
5
  "private": false,
6
6
  "keywords": [
@@ -15,16 +15,15 @@
15
15
  },
16
16
  "type": "module",
17
17
  "files": [
18
- "scripts/buildinfo.ts",
19
- "scripts/build-bundle.ts",
20
- "scripts/import-map.json",
21
- "CHANGELOG.md",
22
- "buildinfo.txt",
23
18
  "dist/",
24
- "tests/",
25
19
  "template/"
26
20
  ],
27
21
  "bin": "./dist/cli.bundle.js",
22
+ "exports": {
23
+ ".": {
24
+ "entrypoint": "./src/cli.ts"
25
+ }
26
+ },
28
27
  "imports": {
29
28
  "#src/*.js": "./src/*.ts"
30
29
  },
@@ -37,8 +36,8 @@
37
36
  "clean": "npm run clean:dist && npm run clean:tsbuildinfo",
38
37
  "tests": "node --import tsx --test tests/**/*.test.ts",
39
38
  "prebuild": "npm run buildinfo",
40
- "build": "npm run build:cli-bundle",
41
- "build:cli-bundle": "esbuild src/cli.ts --outdir=dist --entry-names=[dir]/[name].bundle --platform=node --format=esm --bundle --minify --sourcemap=external"
39
+ "build": "npm run build:bundle",
40
+ "build:bundle": "tsx scripts/build-bundle.ts"
42
41
  },
43
42
  "devDependencies": {
44
43
  "@types/node": "latest",
@@ -44,7 +44,7 @@ npm run clean
44
44
  npm run build
45
45
  npm run tests
46
46
 
47
- npmx tsx dist/cli.bundle.js -- example/
47
+ npx tsx dist/cli.bundle.js -- example/
48
48
  ```
49
49
 
50
50
  ## Change Management
@@ -15,16 +15,15 @@
15
15
  },
16
16
  "type": "module",
17
17
  "files": [
18
- "scripts/buildinfo.ts",
19
- "scripts/build-bundle.ts",
20
- "scripts/import-map.json",
21
- "CHANGELOG.md",
22
- "buildinfo.txt",
23
18
  "dist/",
24
- "tests/",
25
19
  "template/"
26
20
  ],
27
21
  "bin": "./dist/cli.bundle.js",
22
+ "exports": {
23
+ ".": {
24
+ "entrypoint": "./src/cli.ts"
25
+ }
26
+ },
28
27
  "imports": {
29
28
  "#src/*.js": "./src/*.ts"
30
29
  },
@@ -37,8 +36,8 @@
37
36
  "clean": "npm run clean:dist && npm run clean:tsbuildinfo",
38
37
  "tests": "node --import tsx --test tests/**/*.test.ts",
39
38
  "prebuild": "npm run buildinfo",
40
- "build": "npm run build:cli-bundle",
41
- "build:cli-bundle": "esbuild src/cli.ts --outdir=dist --entry-names=[dir]/[name].bundle --platform=node --format=esm --bundle --minify --sourcemap=external"
39
+ "build": "npm run build:bundle",
40
+ "build:bundle": "tsx scripts/build-bundle.ts"
42
41
  },
43
42
  "devDependencies": {
44
43
  "@types/node": "latest",
@@ -1,4 +1,4 @@
1
- import { readFileSync } from 'node:fs';
1
+ import { cpSync, existsSync, readFileSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
3
  import {
4
4
  build,
@@ -122,6 +122,29 @@ const esbuildLog: EsbuildPlugin = {
122
122
  });
123
123
  }
124
124
  }
125
+ const COPY_FILES: string[] = [
126
+ "buildinfo.txt",
127
+ "buildinfo-template.txt",
128
+ "CHANGELOG.md",
129
+ ];
130
+ const copyFiles: EsbuildPlugin = {
131
+ name: 'copy-files',
132
+ setup(build: PluginBuild) {
133
+ build.onEnd((result: BuildResult<BuildOptions>) => {
134
+ const outDir = build.initialOptions.outdir || 'dist/';
135
+ console.log(`[copy-files plugin] Copying additional files to '${outDir}'...`);
136
+ for (const file of COPY_FILES) {
137
+ const destination = join(outDir, file);
138
+ if (existsSync(file)) {
139
+ cpSync(file, destination);
140
+ console.log(`[copy-files plugin] Copied '${file}' to '${destination}'.`);
141
+ } else {
142
+ console.warn(`[copy-files plugin] File '${file}' does not exist. Skipping...`);
143
+ }
144
+ }
145
+ });
146
+ }
147
+ }
125
148
  const importMap: EsbuildPlugin = {
126
149
  name: 'import-map',
127
150
  setup(build: PluginBuild) {
@@ -152,13 +175,12 @@ const buildOptions: BuildOptions = {
152
175
  entryPoints: entrypoints,
153
176
  outdir: 'dist/',
154
177
  entryNames: '[dir]/[name].bundle',
155
- platform: 'browser',
178
+ platform: 'node',
156
179
  format: 'esm',
157
180
  bundle: true,
158
181
  minify: true,
159
182
  sourcemap: 'external',
160
- plugins: [esbuildLog, importMap],
161
-
183
+ plugins: [esbuildLog, copyFiles, importMap],
162
184
  };
163
185
 
164
186
  try {
@@ -176,10 +198,11 @@ if (!omitIife) {
176
198
  try {
177
199
  await build({
178
200
  ...buildOptions,
179
- entryNames: '[dir]/[name].iife.bundle',
201
+ entryNames: '[dir]/[name].bundle.iife',
180
202
  format: 'iife',
181
203
  banner: { js: 'var __importMetaUrl = document.currentScript && document.currentScript.src || \'\';' },
182
204
  define: { 'import.meta.url': '__importMetaUrl' },
205
+ plugins: [esbuildLog, importMap],
183
206
  });
184
207
  } catch (error) {
185
208
  console.error('[scripts/build-bundle.ts] Build failed:');
@@ -1,25 +1,25 @@
1
- import { execSync } from 'node:child_process';
1
+ import { spawnSync } from 'node:child_process';
2
2
  import { readFileSync, writeFileSync } from 'node:fs';
3
3
 
4
4
 
5
- const BUILD_INFO_FILE = 'buildinfo.txt';
6
- const GIT_COMMAND = 'git rev-parse --short HEAD';
7
-
8
- const version: string = JSON.parse(readFileSync('package.json', 'utf-8')).version;
9
-
10
5
  let gitHash = '';
11
6
  try {
12
- gitHash = execSync(GIT_COMMAND, { stdio: ['ignore', 'pipe', 'ignore'] })
13
- .toString()
14
- .trim();
7
+ const gitProc = spawnSync('git', ['rev-parse', '--short', 'HEAD']);
8
+ if (gitProc.status === 0) {
9
+ gitHash = gitProc.stdout.toString().trim();
10
+ }
11
+ else {
12
+ console.warn(`[scripts/buildinfo.ts] Warning: Failed to get git hash. Prceding without...`);
13
+ }
15
14
  } catch { }
16
15
 
17
- const buildinfo = gitHash
18
- ? version.includes('+')
19
- ? `${version}.${gitHash}`
20
- : `${version}+${gitHash}`
21
- : version;
16
+ const packageJson: { version: string } = JSON.parse(readFileSync('package.json', 'utf-8'));
17
+ const packageVersion = packageJson.version;
18
+
19
+ const separator = packageVersion.includes('+') ? '.' : '+';
20
+ const buildinfo = gitHash ? `${packageVersion}${separator}${gitHash}` : packageVersion;
22
21
 
23
- writeFileSync(BUILD_INFO_FILE, buildinfo.trim(), 'utf-8');
22
+ const buildinfoFilePath = 'buildinfo.txt';
23
+ writeFileSync(buildinfoFilePath, buildinfo.trim(), 'utf-8');
24
24
 
25
- console.log(`'${BUILD_INFO_FILE}' has been updated with build info: ${buildinfo}`);
25
+ console.log(`[scripts/buildinfo.ts] Build info '${buildinfo}' written to '${buildinfoFilePath}'.`);
@@ -7,7 +7,7 @@ import {
7
7
  changelogUrl,
8
8
  buildinfoUrl,
9
9
  readmeUrl
10
- } from './constants.js';
10
+ } from './package-urls.js';
11
11
 
12
12
 
13
13
  try {
@@ -1,8 +1,8 @@
1
1
  export const packageUrl: URL = new URL('../', import.meta.url);
2
2
 
3
- export const readmeUrl: URL = new URL('README.md', packageUrl);
4
- export const changelogUrl: URL = new URL('CHANGELOG.md', packageUrl);
5
- export const buildinfoUrl: URL = new URL('buildinfo.txt', packageUrl);
6
3
  export const distUrl: URL = new URL('dist/', packageUrl);
4
+ export const buildinfoUrl: URL = new URL('buildinfo.txt', distUrl);
5
+ export const changelogUrl: URL = new URL('CHANGELOG.md', distUrl);
6
+ export const readmeUrl: URL = new URL('README.md', packageUrl);
7
7
 
8
8
  export const templateUrl: URL = new URL('template/', packageUrl);
@@ -1,7 +1,7 @@
1
1
  import { describe, it } from 'node:test';
2
2
  import assert from 'node:assert';
3
3
  import { existsSync, readFileSync } from 'node:fs';
4
- import { buildinfoUrl, packageUrl } from '#src/constants.js';
4
+ import { buildinfoUrl, packageUrl } from '#src/package-urls.js';
5
5
 
6
6
 
7
7
  // https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
package/buildinfo.txt DELETED
@@ -1 +0,0 @@
1
- 0.4.2+3253038
@@ -1,191 +0,0 @@
1
- import { readFileSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import {
4
- build,
5
- type BuildFailure,
6
- type OnResolveArgs,
7
- type OnResolveResult,
8
- type Plugin as EsbuildPlugin,
9
- type PluginBuild,
10
- type BuildOptions,
11
- type BuildResult
12
- } from 'esbuild';
13
-
14
- import IMPORT_MAP from './import-map.json';
15
-
16
-
17
- interface ExportConditions {
18
- [key: string]: string | undefined;
19
- entrypoint?: string;
20
- types?: string;
21
- browser?: string;
22
- import?: string;
23
- }
24
- interface Dependency {
25
- [key: string]: string;
26
- }
27
- interface PackageManifest {
28
- version: string;
29
- exports?: Record<string, ExportConditions>;
30
- dependencies?: Dependency;
31
- devDependencies?: Dependency;
32
- peerDependencies?: Dependency;
33
- }
34
-
35
- function getManifest(packageIdentifier?: string): PackageManifest {
36
-
37
- const manifestPath = packageIdentifier
38
- ? join('node_modules', packageIdentifier, 'package.json')
39
- : 'package.json'
40
- ;
41
-
42
- let manifest: PackageManifest;
43
-
44
- try {
45
- manifest = JSON.parse(readFileSync(manifestPath, 'utf-8'));
46
- } catch {
47
- throw new Error(`[scripts/build-bundle.ts] Failed to read package manifest at '${manifestPath}'.`);
48
- }
49
-
50
- return manifest;
51
-
52
- }
53
- function getManifestEntrypoints(packageManifest: PackageManifest): string[] {
54
-
55
- const exports = packageManifest.exports;
56
- if (!exports)
57
- throw new Error(`[scripts/build-bundle.ts] Failed to read entrypoints from package manifest: 'exports' field is missing.`);
58
-
59
- const entrypoints = Object.entries(exports)
60
- .map(([key, conditions]) => {
61
- if (!conditions.entrypoint)
62
- throw new Error(`[scripts/build-bundle.ts] Failed to read entrypoints from package manifest: 'entrypoint' condition is missing for export '${key}'.`);
63
- return conditions.entrypoint;
64
- });
65
-
66
- return entrypoints;
67
-
68
- }
69
- function getPackageVersion(manifest: PackageManifest, packageIdentifier?: string): string {
70
-
71
- let version: string | undefined;
72
- if (packageIdentifier) {
73
-
74
- const dependencies = {
75
- ...manifest.dependencies,
76
- ...manifest.devDependencies,
77
- ...manifest.peerDependencies,
78
- };
79
-
80
- version = dependencies[packageIdentifier];
81
- if (!version)
82
- throw new Error(`[scripts/build-bundle.ts] Failed to read version for package '${packageIdentifier}': package is not listed in dependencies.`);
83
-
84
- }
85
- else {
86
- if (!manifest.version)
87
- throw new Error('[scripts/build-bundle.ts] Failed to read package version from manifest: version field is missing.');
88
- version = manifest.version;
89
- }
90
-
91
- return version;
92
-
93
- }
94
-
95
- function resolveVersionInCdnUrl(importSpecifier: string, cdnUrl: string): string {
96
- if (cdnUrl.includes('<VERSION>')) {
97
- const manifest = getManifest();
98
- const version = getPackageVersion(manifest, importSpecifier);
99
- let resolvedVersion = version;
100
- if (resolvedVersion.startsWith('workspace:')) resolvedVersion = resolvedVersion.replace(/^workspace:/, '');
101
- if (resolvedVersion.startsWith('^') || resolvedVersion.startsWith('~')) resolvedVersion = resolvedVersion.substring(1);
102
- if (resolvedVersion.length === 0)
103
- throw new Error(`[scripts/build-bundle.ts] Failed to resolve version for package '${importSpecifier}': resolved version is empty.`);
104
- return cdnUrl.replace('<VERSION>', resolvedVersion);
105
- }
106
- return cdnUrl;
107
- }
108
-
109
- const esbuildLog: EsbuildPlugin = {
110
- name: 'esbuild-log',
111
- setup(build: PluginBuild) {
112
- const format = build.initialOptions.format || 'unknown';
113
- build.onStart(() => {
114
- console.log(`[esbuild-log plugin] ${format} build started...`);
115
- });
116
- build.onEnd((result: BuildResult<BuildOptions>) => {
117
- if (result.errors.length > 0) {
118
- console.error(`[esbuild-log plugin] ${format} build failed.`);
119
- } else {
120
- console.log(`[esbuild-log plugin] ${format} build finished.`);
121
- }
122
- });
123
- }
124
- }
125
- const importMap: EsbuildPlugin = {
126
- name: 'import-map',
127
- setup(build: PluginBuild) {
128
-
129
- for (const [importSpecifier, urlTemplate] of Object.entries(IMPORT_MAP) as [string, string | null][]) {
130
-
131
- const url = urlTemplate ? resolveVersionInCdnUrl(importSpecifier, urlTemplate) : null;
132
- console.log(`[import-map plugin] '${importSpecifier}' → ${url ? `'${url}'` : 'external (no rewrite)'}`);
133
-
134
- const escapedSpecifier = importSpecifier.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
135
- build.onResolve(
136
- { filter: new RegExp(`^${escapedSpecifier}$`) },
137
- (args: OnResolveArgs): OnResolveResult | undefined => {
138
- return { path: url ?? args.path, external: true };
139
- }
140
- );
141
-
142
- }
143
-
144
- },
145
- };
146
-
147
-
148
- const entrypoints = getManifestEntrypoints(getManifest());
149
- console.log('[scripts/build-bundle.ts] Entrypoints:', entrypoints);
150
-
151
- const buildOptions: BuildOptions = {
152
- entryPoints: entrypoints,
153
- outdir: 'dist/',
154
- entryNames: '[dir]/[name].bundle',
155
- platform: 'browser',
156
- format: 'esm',
157
- bundle: true,
158
- minify: true,
159
- sourcemap: 'external',
160
- plugins: [esbuildLog, importMap],
161
-
162
- };
163
-
164
- try {
165
- await build(buildOptions);
166
- } catch (error) {
167
- console.error('[scripts/build-bundle.ts] Build failed:');
168
- for (const message of (error as BuildFailure).errors) {
169
- console.error(message);
170
- }
171
- process.exit(1);
172
- }
173
-
174
- const omitIife = process.argv.includes('--omit-iife');
175
- if (!omitIife) {
176
- try {
177
- await build({
178
- ...buildOptions,
179
- entryNames: '[dir]/[name].iife.bundle',
180
- format: 'iife',
181
- banner: { js: 'var __importMetaUrl = document.currentScript && document.currentScript.src || \'\';' },
182
- define: { 'import.meta.url': '__importMetaUrl' },
183
- });
184
- } catch (error) {
185
- console.error('[scripts/build-bundle.ts] Build failed:');
186
- for (const message of (error as BuildFailure).errors) {
187
- console.error(message);
188
- }
189
- process.exit(1);
190
- }
191
- }
@@ -1,25 +0,0 @@
1
- import { execSync } from 'node:child_process';
2
- import { readFileSync, writeFileSync } from 'node:fs';
3
-
4
-
5
- const BUILD_INFO_FILE = 'buildinfo.txt';
6
- const GIT_COMMAND = 'git rev-parse --short HEAD';
7
-
8
- const version: string = JSON.parse(readFileSync('package.json', 'utf-8')).version;
9
-
10
- let gitHash = '';
11
- try {
12
- gitHash = execSync(GIT_COMMAND, { stdio: ['ignore', 'pipe', 'ignore'] })
13
- .toString()
14
- .trim();
15
- } catch { }
16
-
17
- const buildinfo = gitHash
18
- ? version.includes('+')
19
- ? `${version}.${gitHash}`
20
- : `${version}+${gitHash}`
21
- : version;
22
-
23
- writeFileSync(BUILD_INFO_FILE, buildinfo.trim(), 'utf-8');
24
-
25
- console.log(`'${BUILD_INFO_FILE}' has been updated with build info: ${buildinfo}`);
@@ -1 +0,0 @@
1
- {}
@@ -1,26 +0,0 @@
1
- import { describe, it } from 'node:test';
2
- import assert from 'node:assert';
3
- import { existsSync, readFileSync } from 'node:fs';
4
- import { buildinfoUrl, packageUrl } from '#src/constants.js';
5
-
6
-
7
- // https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
8
- // Captures: [1]=major, [2]=minor, [3]=patch, [4]=pre-release, [5]=build-metadata
9
- const SEMVER_REGEX =
10
- /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
11
-
12
-
13
- describe('buildinfo.txt', () => {
14
-
15
- it('MUST exist at the specified location', async () => {
16
- assert.ok(existsSync(buildinfoUrl));
17
- assert.ok(!existsSync(new URL('wrong.txt', packageUrl)));
18
- });
19
-
20
- it('MUST contain a valid semver string', async () => {
21
- const buildinfo = readFileSync(buildinfoUrl, 'utf-8');
22
- assert.match(buildinfo, SEMVER_REGEX);
23
- assert.doesNotMatch('version zwölf', SEMVER_REGEX);
24
- });
25
-
26
- });