@reflex-stack/tsp 0.1.11 → 0.2.1
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 +40 -45
- package/package.json +5 -5
- package/src/cli.js +55 -58
- package/src/commands/init.js +65 -28
- package/src/commands/size-report.js +29 -34
- package/src/config.js +0 -2
- package/src/tests.js +1 -4
- package/src/utils.js +5 -3
- package/tests/example-package/LICENCE +0 -21
- package/tests/example-package/README.md +0 -31
- package/tests/example-package/dist/common-dep.d.ts +0 -1
- package/tests/example-package/dist/common-dep.js +0 -1
- package/tests/example-package/dist/index.d.ts +0 -2
- package/tests/example-package/dist/index.js +0 -2
- package/tests/example-package/dist/root-dep.d.ts +0 -1
- package/tests/example-package/dist/root-dep.js +0 -1
- package/tests/example-package/dist/stuff.d.ts +0 -1
- package/tests/example-package/dist/stuff.js +0 -5
- package/tests/example-package/dist/submodule/index.d.ts +0 -1
- package/tests/example-package/dist/submodule/index.js +0 -5
- package/tests/example-package/dist/submodule/submodule-dep.d.ts +0 -1
- package/tests/example-package/dist/submodule/submodule-dep.js +0 -1
- package/tests/example-package/package-lock.json +0 -1061
- package/tests/example-package/package.json +0 -47
- package/tests/example-package/reports/main-dark.svg +0 -1
- package/tests/example-package/reports/main-light.svg +0 -1
- package/tests/example-package/reports/submodule-dark.svg +0 -1
- package/tests/example-package/reports/submodule-light.svg +0 -1
- package/tests/example-package/reports/total-dark.svg +0 -1
- package/tests/example-package/reports/total-light.svg +0 -1
- package/tests/example-package/tests/test.js +0 -25
- package/tests/example-package/tests/tsconfig.json +0 -5
- package/tests/example-package/tsconfig.json +0 -36
package/README.md
CHANGED
|
@@ -6,23 +6,29 @@
|
|
|
6
6
|
- It uses `tsc` to compile from ts to js and check errors
|
|
7
7
|
- Generates `.d.ts` to keep types when used
|
|
8
8
|
- Scaffold new packages in 1 minute
|
|
9
|
-
- Testing lib pre-installed, can also use your own or skip tests
|
|
10
|
-
- Generating size report
|
|
9
|
+
- Testing lib pre-installed, can also use your own or skip tests (will use `bun:test` if the runtime is Bun)
|
|
10
|
+
- Generating size report and replace them with tags in `README.md` for Npm and GitHub
|
|
11
11
|
- Compatible with latest **Node** / **Bun** / **Deno** and all bundlers with ecma specification
|
|
12
|
-
- Publishing under `.js` and `.d.ts` [helps having better performances](https://x.com/mattpocockuk/status/1872945584761651432) in your projects
|
|
12
|
+
- Publishing under `.js` and `.d.ts` [helps having better performances](https://x.com/mattpocockuk/status/1872945584761651432) in your projects.
|
|
13
13
|
|
|
14
|
-
Check example on [NPM](https://www.npmjs.com/package/@reflex-stack/tsp-example) and [GitHub](https://github.com/reflex-stack/tsp/tree/main/tests/example
|
|
14
|
+
Check example on [NPM](https://www.npmjs.com/package/@reflex-stack/tsp-bun-example) and [GitHub](https://github.com/reflex-stack/tsp/tree/main/tests/tsp-bun-example)
|
|
15
15
|
|
|
16
16
|
## Init a new TypeScript Package
|
|
17
17
|
|
|
18
|
-
First, create the associated **git repository** for your package and clone it (
|
|
18
|
+
First, create the associated **git repository** for your package and clone it (optional).
|
|
19
19
|
|
|
20
20
|
Then, run this command in the cloned directory. :
|
|
21
|
+
|
|
22
|
+
#### To create a package managed with Bun
|
|
21
23
|
```bash
|
|
22
|
-
|
|
24
|
+
bunx @reflex-stack/tsp init
|
|
23
25
|
```
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
#### To create a package managed with Node
|
|
28
|
+
```bash
|
|
29
|
+
npx @reflex-stack/tsp init
|
|
30
|
+
```
|
|
31
|
+
> If you create this package in a mono-repo, `cd` in the correct repository before running this command. The subdirectory is important for package.json to be in the right place.
|
|
26
32
|
|
|
27
33
|
#### Created files
|
|
28
34
|
|
|
@@ -35,11 +41,11 @@ This will ask some questions and create those files. It contains 1 **submodule**
|
|
|
35
41
|
│ │ └─ index.ts
|
|
36
42
|
│ └─ index.ts
|
|
37
43
|
├─ tests/
|
|
38
|
-
│ └─ test.js
|
|
39
|
-
│ └─ tsconfig.json ( to have correct typings in test.js
|
|
44
|
+
│ └─ test.(js|ts)
|
|
45
|
+
│ └─ tsconfig.json (if Node runtime, to have correct typings in test.js)
|
|
40
46
|
├─ .gitignore
|
|
41
47
|
├─ .npmignore
|
|
42
|
-
├─ LICENSE (
|
|
48
|
+
├─ LICENSE (if MIT)
|
|
43
49
|
├─ package.json
|
|
44
50
|
├─ package-lock.json
|
|
45
51
|
├─ README.md
|
|
@@ -50,56 +56,46 @@ This will ask some questions and create those files. It contains 1 **submodule**
|
|
|
50
56
|
|
|
51
57
|
#### Build sources
|
|
52
58
|
```shell
|
|
59
|
+
bun run build
|
|
60
|
+
# or
|
|
53
61
|
npm run build
|
|
54
62
|
```
|
|
55
63
|
- Will clear `./dist`, build sources from `.ts` files to `.js` and `.d.ts` files.
|
|
56
|
-
- Will generate size report and generate `./reports` directory with JSON and SVG files.
|
|
57
64
|
|
|
58
65
|
> Run `npm run build --noSizeReport` to skip size report entirely.
|
|
59
66
|
|
|
60
67
|
#### Test
|
|
61
68
|
```bash
|
|
69
|
+
bun run test
|
|
70
|
+
# or
|
|
62
71
|
npm run test
|
|
63
72
|
```
|
|
64
73
|
> Will clear `./dist`, build sources and run tests. No size report.
|
|
65
74
|
|
|
66
|
-
####
|
|
75
|
+
#### Bump version
|
|
67
76
|
```bash
|
|
68
|
-
|
|
77
|
+
bun run bump
|
|
78
|
+
# or
|
|
79
|
+
npm run bump
|
|
69
80
|
```
|
|
70
|
-
> Will clear `./dist`, build sources, run tests, and start publish process.
|
|
71
|
-
> This will ask you how to upgrade package.json version, push to git and npm.
|
|
72
81
|
|
|
82
|
+
> Will clear `./dist`, build sources, run tests, and create a new package version.
|
|
83
|
+
> You will be able to run `npm publish --access public` or `bun publish --access public` safely after that.
|
|
73
84
|
|
|
74
|
-
## Size report
|
|
75
85
|
|
|
76
|
-
|
|
77
|
-
- 2 svgs for root module
|
|
78
|
-
- 2 svgs by submodule
|
|
79
|
-
- 2 svgs for total if you have submodules
|
|
80
|
-
|
|
81
|
-
There are 2 svgs generated, for dark and light mode, to be included in the README.md, on **GitHub** and **NPM**.
|
|
82
|
-
|
|
83
|
-
> When scaffolded, an example of SVG inclusion is generated in README.md
|
|
84
|
-
|
|
85
|
-
How to include the size report in `README.md` ?
|
|
86
|
+
## Size report
|
|
86
87
|
|
|
87
|
-
|
|
88
|
-
Main bundle is <picture style="display: inline-block"><source media="(prefers-color-scheme: dark)" srcset="./reports/main-dark.svg"><img src="./reports/main-light.svg"></picture>,
|
|
89
|
-
submodule is <picture style="display: inline-block"><source media="(prefers-color-scheme: dark)" srcset="./reports/submodule-dark.svg"><img src="./reports/submodule-light.svg"></picture>,
|
|
90
|
-
total is <picture style="display: inline-block"><source media="(prefers-color-scheme: dark)" srcset="./reports/total-dark.svg"><img src="./reports/total-light.svg"></picture>
|
|
91
|
-
```
|
|
88
|
+
**TSP** can generate size reports with brotli compression.
|
|
92
89
|
|
|
93
|
-
|
|
90
|
+
Use `<bundle-size id="{bundleID}">0b</bundle-size>` tags in your `README.md` to include size reports.
|
|
91
|
+
Replace `{bundleID}` with the name of the bundle you want to include.
|
|
92
|
+
Those tags will be replaced each time you run `npm run build`.
|
|
94
93
|
|
|
95
|
-
|
|
96
|
-
submodule is <picture style="display: inline-block"><source media="(prefers-color-scheme: dark)" srcset="./tests/example-package/reports/submodule-dark.svg"><img src="./tests/example-package/reports/submodule-light.svg"></picture>,
|
|
97
|
-
total is <picture style="display: inline-block"><source media="(prefers-color-scheme: dark)" srcset="./tests/example-package/reports/total-dark.svg"><img src="./tests/example-package/reports/total-light.svg"></picture>
|
|
94
|
+
For the total bundle size, use `<bundle-size id="total">0b</bundle-size>`
|
|
98
95
|
|
|
99
|
-
>
|
|
100
|
-
> This can be disabled in package.json at `tsp.generate-svg-report`
|
|
96
|
+
> Works in GitHub and NPM.
|
|
101
97
|
|
|
102
|
-
**TSP** can also generate a json size report if needed (
|
|
98
|
+
**TSP** can also generate a json size report as `bundle-sizes.json` if needed (default is set to false)
|
|
103
99
|
|
|
104
100
|
## TSP config
|
|
105
101
|
TSP config is in the generated `package.json` under the `"tsp"` node
|
|
@@ -107,22 +103,21 @@ TSP config is in the generated `package.json` under the `"tsp"` node
|
|
|
107
103
|
```json5
|
|
108
104
|
{
|
|
109
105
|
"tsp": {
|
|
110
|
-
// Can set to "
|
|
111
|
-
"runtime": "
|
|
106
|
+
// Can set to "node" or "deno"
|
|
107
|
+
"runtime": "bun",
|
|
112
108
|
// If you change them, you should update tsconfig.json file
|
|
113
109
|
"src": './src',
|
|
114
110
|
"dist": './dist',
|
|
115
111
|
"tests": './tests',
|
|
116
112
|
"tmp": './tmp',
|
|
117
113
|
// Add your test files here
|
|
118
|
-
"test-files": ['test.
|
|
114
|
+
"test-files": ['test.ts'],
|
|
119
115
|
// Where size reports are generated
|
|
120
|
-
"
|
|
121
|
-
"generate-json-report": false,
|
|
122
|
-
"generate-svg-report": true
|
|
116
|
+
"generate-json-report": false
|
|
123
117
|
},
|
|
124
118
|
}
|
|
125
119
|
```
|
|
126
120
|
|
|
127
121
|
## Next features
|
|
128
|
-
- [ ]
|
|
122
|
+
- [ ] Set other files than `README.md` in config for size report tags
|
|
123
|
+
- [ ] Docisfy integration
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reflex-stack/tsp",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"tsp": "./src/cli.js"
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"./tests": "./src/tests.js"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
|
-
"
|
|
16
|
+
"bump": "node ./src/cli.js bump"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"description": "TSP scaffolds and build Typescript sources to EcmaScript modules and publish them as modular packages to NPM",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@types/node": "^
|
|
26
|
+
"@types/node": "^25.5.0",
|
|
27
27
|
"@zouloux/cli": "^0.2.8",
|
|
28
28
|
"@zouloux/files": "^3.0.4",
|
|
29
29
|
"brotli-size": "^4.0.0",
|
|
30
30
|
"stach": "^2.0.1",
|
|
31
|
-
"terser": "^5.
|
|
32
|
-
"typescript": "^
|
|
31
|
+
"terser": "^5.46.1",
|
|
32
|
+
"typescript": "^6.0.2"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/cli.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { askInput, CLICommands, execAsync, nicePrint, oraTask, execSync, table, askList, newLine } from "@zouloux/cli";
|
|
5
5
|
import { build, clearOutput } from "./commands/build.js";
|
|
6
6
|
import { getUserPackageJson, naiveHumanFileSize, showIntroMessage } from "./utils.js";
|
|
7
|
-
import {
|
|
7
|
+
import { generateJSON, replaceBundleSizes, sizeReport } from "./commands/size-report.js";
|
|
8
8
|
import { init } from "./commands/init.js";
|
|
9
9
|
import { getConfig } from "./config.js";
|
|
10
10
|
|
|
@@ -17,7 +17,7 @@ const commands = new CLICommands({
|
|
|
17
17
|
|
|
18
18
|
// Executed for all commands
|
|
19
19
|
commands.before((args, flags, commandName) => {
|
|
20
|
-
if ( commandName !== "
|
|
20
|
+
if ( commandName !== "bump" && !flags.noIntro )
|
|
21
21
|
showIntroMessage(!commandName || commandName === "init")
|
|
22
22
|
})
|
|
23
23
|
|
|
@@ -50,10 +50,11 @@ commands.add("build", async (args, flags) => {
|
|
|
50
50
|
task.error()
|
|
51
51
|
console.log(error.stdout ?? '')
|
|
52
52
|
console.log(error.stderr ?? '')
|
|
53
|
+
process.exit(1)
|
|
53
54
|
})
|
|
54
55
|
|
|
55
56
|
// CLI Flag to disable reports and only build
|
|
56
|
-
if ( flags.noSizeReport )
|
|
57
|
+
if ( flags && flags.noSizeReport )
|
|
57
58
|
return
|
|
58
59
|
|
|
59
60
|
// Generate size report
|
|
@@ -68,20 +69,18 @@ commands.add("build", async (args, flags) => {
|
|
|
68
69
|
return report
|
|
69
70
|
})
|
|
70
71
|
|
|
71
|
-
// Generate
|
|
72
|
-
if ( config["generate-
|
|
73
|
-
await oraTask('Generating report
|
|
74
|
-
|
|
75
|
-
await cleanSizeReports( config )
|
|
76
|
-
// Generate JSON
|
|
77
|
-
if ( config["generate-json-report"] )
|
|
78
|
-
generateJSON( report, config )
|
|
79
|
-
// Generate SVG files
|
|
80
|
-
if ( config["generate-svg-report"] )
|
|
81
|
-
await generateSVGs( report, config )
|
|
72
|
+
// Generate JSON report
|
|
73
|
+
if ( config["generate-json-report"] ) {
|
|
74
|
+
await oraTask('Generating json report', async ( task ) => {
|
|
75
|
+
generateJSON( report, config )
|
|
82
76
|
})
|
|
83
77
|
}
|
|
84
78
|
|
|
79
|
+
// Replace bundle sizes
|
|
80
|
+
await oraTask('Replacing bundle sizes', async ( task ) => {
|
|
81
|
+
await replaceBundleSizes( report, config )
|
|
82
|
+
})
|
|
83
|
+
|
|
85
84
|
// Print report table in CLI
|
|
86
85
|
const tableData = [
|
|
87
86
|
// Table header
|
|
@@ -142,7 +141,11 @@ commands.add("test", async (args, flags, commandName) => {
|
|
|
142
141
|
nicePrint(`Starting test sequence`)
|
|
143
142
|
newLine()
|
|
144
143
|
for ( const testFile of config["test-files"] ) {
|
|
145
|
-
const command =
|
|
144
|
+
const command = (
|
|
145
|
+
config.runtime === "node"
|
|
146
|
+
? `node ${config.tests}/${testFile}`
|
|
147
|
+
: `bun test ${config.tests}/${testFile}`
|
|
148
|
+
)
|
|
146
149
|
nicePrint(`{d}$ ${command}`)
|
|
147
150
|
try {
|
|
148
151
|
await execAsync(command, 3)
|
|
@@ -156,25 +159,26 @@ commands.add("test", async (args, flags, commandName) => {
|
|
|
156
159
|
})
|
|
157
160
|
|
|
158
161
|
/**
|
|
159
|
-
*
|
|
162
|
+
* BUMP VERSION COMMAND
|
|
160
163
|
*/
|
|
161
|
-
commands.add("
|
|
164
|
+
commands.add("bump", async (args, flags, commandName) => {
|
|
162
165
|
// Check NPM connected user
|
|
163
|
-
await oraTask({text: `Connecting to npm`}, async task => {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
})
|
|
166
|
+
// await oraTask({text: `Connecting to npm`}, async task => {
|
|
167
|
+
// try {
|
|
168
|
+
// const whoami = await execAsync(`npm whoami`, 0)
|
|
169
|
+
// task.success(nicePrint(`Hello {b/c}@${whoami}`, {output: 'return'}).trim())
|
|
170
|
+
// return whoami
|
|
171
|
+
// }
|
|
172
|
+
// catch (e) {
|
|
173
|
+
// task.error(`Please connect to npm with ${chalk.bold('npm login')}`)
|
|
174
|
+
// }
|
|
175
|
+
// })
|
|
173
176
|
// TODO : When test will build only needed files, move build after tests
|
|
174
177
|
// (to build all files after test has succeed)
|
|
175
178
|
// Compile
|
|
176
|
-
//await
|
|
177
|
-
//await
|
|
179
|
+
// await commands.run("build")
|
|
180
|
+
// await commands.run("test")
|
|
181
|
+
|
|
178
182
|
|
|
179
183
|
// todo : Internal build
|
|
180
184
|
// todo : Run test command
|
|
@@ -190,42 +194,33 @@ commands.add("publish", async (args, flags, commandName) => {
|
|
|
190
194
|
newLine()
|
|
191
195
|
nicePrint(`📦 Current version of {b/c}${name}{/} is {b/c}${version}`)
|
|
192
196
|
// Ask how to increment version
|
|
193
|
-
const increment = await askList(`How to
|
|
197
|
+
const increment = await askList(`How to bump version ?`, {
|
|
194
198
|
patch: 'patch (0.0.X) - No new features, patch bugs or optimize code',
|
|
195
199
|
minor: 'minor (0.X.0) - No breaking change, have new or improved features',
|
|
196
200
|
major: 'major (X.0.0) - Breaking change',
|
|
197
|
-
// Keep but publish on NPM (if already increment in package.json)
|
|
198
|
-
keep: `keep (${ version }) - Publish current package.json version`,
|
|
199
|
-
// Push on git but no lib publish
|
|
200
|
-
push: `push - Push on git only, no npm publish`,
|
|
201
|
-
// Skip this lib (no publish at all, go to next library)
|
|
202
|
-
skip: `skip - Do not publish ${ name }`,
|
|
203
201
|
}, { returnType: 'key' });
|
|
204
|
-
//
|
|
205
|
-
|
|
206
|
-
return
|
|
207
|
-
// execSync(`git status -s`, stdioLevel, libraryExecOptions)
|
|
208
|
-
// Ask for commit message
|
|
209
|
-
let message = await askInput(`Commit message ?`);
|
|
202
|
+
// Ask for tag message
|
|
203
|
+
let message = await askInput(`Tag message`);
|
|
210
204
|
message = message.replace(/["']/g, "'");
|
|
211
|
-
// If we increment, use npm version
|
|
205
|
+
// // If we increment, use npm version
|
|
212
206
|
if ( increment !== 'keep' && increment !== 'push' ) {
|
|
213
207
|
version = execSync(`npm version ${increment} --no-git-tag-version -m"${name} - %s - ${message}"`, stdioLevel, libraryExecOptions).toString().trim();
|
|
214
208
|
}
|
|
215
209
|
// Add to git and push
|
|
216
|
-
execSync(`git add .`, stdioLevel, libraryExecOptions);
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
//
|
|
220
|
-
//
|
|
221
|
-
//
|
|
222
|
-
if ( increment
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
210
|
+
// execSync(`git add .`, stdioLevel, libraryExecOptions);
|
|
211
|
+
// let prefix = ""
|
|
212
|
+
// if ( increment === 'patch' )
|
|
213
|
+
// prefix = "fix:"
|
|
214
|
+
// else if ( increment === 'minor' )
|
|
215
|
+
// prefix = "feat:"
|
|
216
|
+
// else if ( increment === 'major' )
|
|
217
|
+
// prefix = "major:"
|
|
218
|
+
// execSync(`git commit -m"${prefix}:${name} - ${version} : ${message}"`, stdioLevel, libraryExecOptions);
|
|
219
|
+
// execSync(`git push`, stdioLevel, libraryExecOptions);
|
|
220
|
+
// Ask to publish
|
|
221
|
+
// fixme : should have public or private setting in config
|
|
222
|
+
const packageManager = typeof Bun === "undefined" ? "npm" : "bun"
|
|
223
|
+
nicePrint(`Please run {b/c}${packageManager} publish --access public{/} to publish this library on NPM as a public package.`)
|
|
229
224
|
})
|
|
230
225
|
|
|
231
226
|
|
|
@@ -235,8 +230,10 @@ commands.add("publish", async (args, flags, commandName) => {
|
|
|
235
230
|
commands.start(function (commandName) {
|
|
236
231
|
if ( commandName )
|
|
237
232
|
return
|
|
238
|
-
|
|
239
|
-
|
|
233
|
+
if ( commandName !== undefined ) {
|
|
234
|
+
nicePrint(`{b/r}Command '${commandName}' not found`)
|
|
235
|
+
newLine()
|
|
236
|
+
}
|
|
240
237
|
nicePrint(`Available commands :`)
|
|
241
238
|
commands.list().forEach( command => nicePrint(`- ${command}`) )
|
|
242
239
|
})
|
package/src/commands/init.js
CHANGED
|
@@ -6,6 +6,9 @@ import { Stach } from "stach";
|
|
|
6
6
|
import { mkdirSync } from "fs";
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
|
|
9
|
+
const runtime = typeof Bun === "undefined" ? "node" : "bun"
|
|
10
|
+
const packageManager = runtime === "node" ? "npm" : "bun"
|
|
11
|
+
|
|
9
12
|
const licenseTemplate = `MIT License
|
|
10
13
|
|
|
11
14
|
Copyright (c) {{ year }} {{ authorName }}
|
|
@@ -29,12 +32,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
29
32
|
SOFTWARE.`
|
|
30
33
|
|
|
31
34
|
const readmeTemplate = `# {{ packageTextName }}
|
|
32
|
-
Main bundle is <
|
|
33
|
-
and optional submodule is only <
|
|
35
|
+
Main bundle is <bundle-size id="main">0b</bundle-size>
|
|
36
|
+
and optional submodule is only <bundle-size id="submodule">0b</bundle-size>.
|
|
37
|
+
For a total of <bundle-size id="total">0b</bundle-size>
|
|
34
38
|
|
|
35
39
|
## Install
|
|
36
40
|
|
|
37
|
-
|
|
41
|
+
\`${packageManager} i {{ packageNPMName }}\`
|
|
38
42
|
|
|
39
43
|
## Usage
|
|
40
44
|
|
|
@@ -47,11 +51,11 @@ and optional submodule is only <picture style="display: inline-block"><source me
|
|
|
47
51
|
## Build commands
|
|
48
52
|
|
|
49
53
|
##### Build
|
|
50
|
-
-
|
|
54
|
+
- \`${runtime} run build\`
|
|
51
55
|
##### Test
|
|
52
|
-
-
|
|
53
|
-
#####
|
|
54
|
-
-
|
|
56
|
+
- \`${runtime} run test\`
|
|
57
|
+
##### Bump version
|
|
58
|
+
- \`${runtime} run bump\`
|
|
55
59
|
|
|
56
60
|
---
|
|
57
61
|
## TSP
|
|
@@ -104,13 +108,16 @@ const tsconfigTestTemplate = `{
|
|
|
104
108
|
|
|
105
109
|
const gitIgnoreTemplate = `.DS_Store
|
|
106
110
|
.idea
|
|
111
|
+
.vscode
|
|
107
112
|
tmp
|
|
108
113
|
node_modules
|
|
109
114
|
dist
|
|
110
115
|
`
|
|
111
116
|
|
|
112
117
|
const npmIgnoreTemplate = `.DS_Store
|
|
118
|
+
.DS_Store
|
|
113
119
|
.idea
|
|
120
|
+
.vscode
|
|
114
121
|
LICENSE
|
|
115
122
|
tmp/
|
|
116
123
|
src/
|
|
@@ -135,7 +142,7 @@ export function subRandomFunction () {
|
|
|
135
142
|
}
|
|
136
143
|
`
|
|
137
144
|
|
|
138
|
-
const
|
|
145
|
+
const testFileNode = `// If you have no tests, uncomment this
|
|
139
146
|
// console.log("No test implemented.")
|
|
140
147
|
// process.exit(0)
|
|
141
148
|
|
|
@@ -143,24 +150,24 @@ const testFile = `// If you have no tests, uncomment this
|
|
|
143
150
|
import { randomFunction } from "../dist/index.js"
|
|
144
151
|
import { subRandomFunction } from "../dist/submodule/index.js"
|
|
145
152
|
// Import small testing lib from tsp
|
|
146
|
-
import { describe,
|
|
153
|
+
import { describe, test, expect, startTest } from "@reflex-stack/tsp/tests"
|
|
147
154
|
|
|
148
155
|
const endTest = startTest()
|
|
149
156
|
|
|
150
157
|
describe("Main module", () => {
|
|
151
|
-
|
|
158
|
+
test("Should call random", () => {
|
|
152
159
|
const rootResult = randomFunction()
|
|
153
160
|
expect(rootResult).toBe(5)
|
|
154
161
|
})
|
|
155
162
|
})
|
|
156
163
|
|
|
157
164
|
describe("Sub module", () => {
|
|
158
|
-
|
|
165
|
+
test("Should call sub random", () => {
|
|
159
166
|
const subResult = subRandomFunction()
|
|
160
167
|
expect(subResult).toBe(60)
|
|
161
168
|
})
|
|
162
169
|
// Test error example
|
|
163
|
-
//
|
|
170
|
+
// test("Should fail", () => {
|
|
164
171
|
// expect(5).toBe(12)
|
|
165
172
|
// })
|
|
166
173
|
})
|
|
@@ -168,6 +175,35 @@ describe("Sub module", () => {
|
|
|
168
175
|
endTest()
|
|
169
176
|
`
|
|
170
177
|
|
|
178
|
+
const testFileBun = `// If you have no tests, uncomment this
|
|
179
|
+
// console.log("No test implemented.")
|
|
180
|
+
// process.exit(0)
|
|
181
|
+
|
|
182
|
+
// Import your code directly from src directory thanks to bun
|
|
183
|
+
import { randomFunction } from "../src/index.js"
|
|
184
|
+
import { subRandomFunction } from "../src/submodule/index.js"
|
|
185
|
+
// Import Bun testing lib
|
|
186
|
+
import { describe, test, expect } from "bun:test"
|
|
187
|
+
|
|
188
|
+
describe("Main module", () => {
|
|
189
|
+
test("Should call random", () => {
|
|
190
|
+
const rootResult = randomFunction()
|
|
191
|
+
expect(rootResult).toBe(5)
|
|
192
|
+
})
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
describe("Sub module", () => {
|
|
196
|
+
test("Should call sub random", () => {
|
|
197
|
+
const subResult = subRandomFunction()
|
|
198
|
+
expect(subResult).toBe(60)
|
|
199
|
+
})
|
|
200
|
+
// Test error example
|
|
201
|
+
// test("Should fail", () => {
|
|
202
|
+
// expect(5).toBe(12)
|
|
203
|
+
// })
|
|
204
|
+
})
|
|
205
|
+
`
|
|
206
|
+
|
|
171
207
|
export async function init () {
|
|
172
208
|
// Check if some critical file already exists and warn before overriding
|
|
173
209
|
if ( existsSync("package.json") ) {
|
|
@@ -189,20 +225,19 @@ export async function init () {
|
|
|
189
225
|
nicePrint(`{d}Git sub directory is {/}${relativeGitSubDirectory}. This will be saved to package.json.`)
|
|
190
226
|
}
|
|
191
227
|
}
|
|
228
|
+
nicePrint(`{d}Using {b}${runtime}{/}{d} runtime. Your package will be configured to work with {b}${runtime}{/}{d}.`)
|
|
192
229
|
newLine()
|
|
193
230
|
const options = { remoteURL, relativeGitSubDirectory }
|
|
194
231
|
options.packageTextName = await askInput(`Package name, in plain text {d}ex : My Package`, { notEmpty: true })
|
|
195
232
|
options.packageNPMName = await askInput(`Package name, for NPM, with namespace {d}ex : @mynamespace/mypackage`, { notEmpty: true })
|
|
196
233
|
options.authorName = await askInput(`Author name`, { notEmpty: true })
|
|
197
234
|
options.licenseName = await askInput(`License name`, { defaultValue: "MIT" })
|
|
198
|
-
options.esLevel = await askInput(`ES Level for tsconfig`, { defaultValue: "
|
|
235
|
+
options.esLevel = await askInput(`ES Level for tsconfig`, { defaultValue: "es2024" })
|
|
199
236
|
options.tsStrict = await askList(`Use strict Typescript?`, ["Yes", "No"], { defaultIndex: 0, returnType: "index" })
|
|
200
237
|
options.domAccess = await askList(`Will it have access to DOM?`, ["Yes", "No"], { defaultIndex: 0, returnType: "index" })
|
|
201
|
-
options.svgReport = await askList(`Export SVG size report on build for README.md?`, ["Yes", "No"], { defaultIndex: 0, returnType: "index" })
|
|
202
238
|
options.jsonReport = await askList(`Export JSON size report on build?`, ["Yes", "No"], { defaultIndex: 1, returnType: "index" })
|
|
203
239
|
options.domAccess = options.domAccess === 0
|
|
204
240
|
options.tsStrict = options.tsStrict === 0
|
|
205
|
-
options.svgReport = options.svgReport === 0
|
|
206
241
|
options.jsonReport = options.jsonReport === 0
|
|
207
242
|
options.libs = [options.domAccess ? "DOM" : "", options.esLevel]
|
|
208
243
|
.filter( Boolean )
|
|
@@ -228,20 +263,18 @@ export async function init () {
|
|
|
228
263
|
}
|
|
229
264
|
},
|
|
230
265
|
tsp: {
|
|
231
|
-
runtime
|
|
266
|
+
runtime,
|
|
232
267
|
src: './src',
|
|
233
268
|
dist: './dist',
|
|
234
269
|
tests: './tests',
|
|
235
|
-
"test-files": ['test.js'],
|
|
270
|
+
"test-files": [runtime === "node" ? 'test.js' : 'test.ts'],
|
|
236
271
|
tmp: './tmp',
|
|
237
|
-
|
|
238
|
-
"generate-json-report": options.jsonReport,
|
|
239
|
-
"generate-svg-report": options.svgReport
|
|
272
|
+
"generate-json-report": options.jsonReport
|
|
240
273
|
},
|
|
241
274
|
scripts: {
|
|
242
275
|
build: "tsp build",
|
|
243
276
|
test: "tsp build --noSizeReport && tsp test --noIntro",
|
|
244
|
-
|
|
277
|
+
bump: "tsp build && tsp test && tsp bump"
|
|
245
278
|
},
|
|
246
279
|
dependencies: {
|
|
247
280
|
"@reflex-stack/tsp": options.tspVersion
|
|
@@ -253,7 +286,7 @@ export async function init () {
|
|
|
253
286
|
type: "git",
|
|
254
287
|
url: options.remoteURL
|
|
255
288
|
}
|
|
256
|
-
// Add subdirectory for package.json and
|
|
289
|
+
// Add subdirectory for package.json and in README.md on NPMJs
|
|
257
290
|
if ( options.relativeGitSubDirectory ) {
|
|
258
291
|
packageJson.repository.directory = options.relativeGitSubDirectory
|
|
259
292
|
}
|
|
@@ -276,19 +309,23 @@ export async function init () {
|
|
|
276
309
|
writeFileSync(join(config.src, "index.ts"), Stach(rootIndexTs, options))
|
|
277
310
|
writeFileSync(join(config.src, "submodule", "index.ts"), Stach(subModuleIndexTs, options))
|
|
278
311
|
// Generate tests file
|
|
279
|
-
|
|
280
|
-
|
|
312
|
+
if ( runtime === "node" ) {
|
|
313
|
+
writeFileSync(join(config.tests, "test.js"), Stach(testFileNode, options))
|
|
314
|
+
writeFileSync(join(config.tests, "tsconfig.json"), Stach(tsconfigTestTemplate, options))
|
|
315
|
+
} else if ( runtime === "bun" ) {
|
|
316
|
+
writeFileSync(join(config.tests, "test.ts"), Stach(testFileBun, options))
|
|
317
|
+
}
|
|
281
318
|
// Install dependencies
|
|
282
319
|
await oraTask("Installing dependencies", async () => {
|
|
283
|
-
await execAsync(
|
|
320
|
+
await execAsync(`${packageManager} i typescript terser`, false, { cwd: config.cwd })
|
|
284
321
|
})
|
|
285
322
|
// Show commands
|
|
286
323
|
newLine()
|
|
287
324
|
nicePrint(`{b/g}Package ${options.packageNPMName} created ✨`)
|
|
288
325
|
newLine()
|
|
289
326
|
nicePrint(`Available commands :`)
|
|
290
|
-
nicePrint(`-
|
|
291
|
-
nicePrint(`-
|
|
292
|
-
nicePrint(`-
|
|
327
|
+
nicePrint(`- ${packageManager} run build`)
|
|
328
|
+
nicePrint(`- ${packageManager} run test`)
|
|
329
|
+
nicePrint(`- ${packageManager} run publish`)
|
|
293
330
|
newLine()
|
|
294
331
|
}
|