hoosat-create 1.4.7 → 1.5.0
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/LICENSE.txt +16 -16
- package/README.md +167 -152
- package/index.js +256 -226
- package/package.json +31 -23
package/LICENSE.txt
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
ISC License
|
|
2
|
-
|
|
3
|
-
Copyright 2023 Hoosat Oy
|
|
4
|
-
|
|
5
|
-
Permission to use, copy, modify, and/or distribute this software
|
|
6
|
-
for any purpose with or without fee is hereby granted, provided
|
|
7
|
-
that the above copyright notice and this permission notice appear
|
|
8
|
-
in all copies.
|
|
9
|
-
|
|
10
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
|
11
|
-
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
|
12
|
-
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
|
13
|
-
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
|
|
14
|
-
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
15
|
-
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
|
16
|
-
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright 2023 Hoosat Oy
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software
|
|
6
|
+
for any purpose with or without fee is hereby granted, provided
|
|
7
|
+
that the above copyright notice and this permission notice appear
|
|
8
|
+
in all copies.
|
|
9
|
+
|
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
|
|
11
|
+
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
|
12
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
|
13
|
+
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
|
|
14
|
+
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
15
|
+
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
|
16
|
+
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
17
17
|
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,152 +1,167 @@
|
|
|
1
|
-
# Hoosat Create
|
|
2
|
-
|
|
3
|
-
Hoosat create is a `npx` script that creates React
|
|
4
|
-
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
-
|
|
17
|
-
- `--
|
|
18
|
-
- `--
|
|
19
|
-
- `--
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
-
|
|
47
|
-
-
|
|
48
|
-
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
- `npm run
|
|
63
|
-
- This script
|
|
64
|
-
- `npm run build:client`: Builds the client in
|
|
65
|
-
- `npm run build:server`: Builds the server in
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
- `npm run
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
- `
|
|
77
|
-
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
`src/
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
// Creating
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
//
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
-
|
|
145
|
-
-
|
|
146
|
-
|
|
147
|
-
### 1.3
|
|
148
|
-
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
1
|
+
# Hoosat Create
|
|
2
|
+
|
|
3
|
+
Hoosat create is a `npx` script that creates React 19 full-stack server side rendering ESM project for you, where you can use Typescript to build web applications. It uses [@Hoosat-Oy/hoosat-template](https://github.com/Hoosat-Oy/hoosat-template) to build React project with SSR and Typescript.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
Node.js 22, 24 or 26 (any supported LTS line). Node.js 20 and older are end-of-life and not supported. Git is needed for cloning the template.
|
|
8
|
+
|
|
9
|
+
## Command to run
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
npx hoosat-create@latest
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Commandline arguments
|
|
16
|
+
- `submodule`
|
|
17
|
+
- `--destination`
|
|
18
|
+
- `--author`
|
|
19
|
+
- `--license`
|
|
20
|
+
- `--keywords`
|
|
21
|
+
- `--keywoordsList`
|
|
22
|
+
- `--gitInit`
|
|
23
|
+
- `--hoosatui`
|
|
24
|
+
|
|
25
|
+
For example:
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
npx hoosat-create@latest --destination "new_project" --author "Toni Lukkaroinen" --gitInit Y --hoosatui Y
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Now it will ask the rest like `license` in the process. Which you can default just by pressing enter.
|
|
32
|
+
|
|
33
|
+
### Submodule creation
|
|
34
|
+
|
|
35
|
+
The following command creates an empty git submodule for you to start working on code that will be shared with another project later.
|
|
36
|
+
```
|
|
37
|
+
npx hoosat-create@latest submodule --destination "src/client/submodule"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Technologies Used
|
|
41
|
+
|
|
42
|
+
- React 19
|
|
43
|
+
- React Router 8
|
|
44
|
+
- React-helmet-async 3
|
|
45
|
+
- i18next 27 / react-i18next 18
|
|
46
|
+
- TypeScript 6
|
|
47
|
+
- Webpack 5
|
|
48
|
+
- Jest 30
|
|
49
|
+
|
|
50
|
+
## Features
|
|
51
|
+
|
|
52
|
+
- Full-stack TypeScript application using React and Node HTTP/HTTPS.
|
|
53
|
+
- Includes working server side SEO with `react-helmet-async`
|
|
54
|
+
- Supports ES modules for server-side and client-side ```.
|
|
55
|
+
- Configured with Webpack for production builds.
|
|
56
|
+
- Includes Jest for unit testing.
|
|
57
|
+
- Includes example components and routes for getting started.
|
|
58
|
+
- Includes HoosatUI as optional dependancy as git submodule.
|
|
59
|
+
|
|
60
|
+
## Scripts
|
|
61
|
+
|
|
62
|
+
- `npm run dev`: Builds and runs the development version.
|
|
63
|
+
- This script concurrently executes the following commands:
|
|
64
|
+
- `npm run dev:build:client`: Builds the client in development mode and watches for file changes.
|
|
65
|
+
- `npm run dev:build:server`: Builds the server in development mode and watches for file changes.
|
|
66
|
+
- `npm run dev:run`: Starts the server with Nodemon to automatically restart it on file changes.
|
|
67
|
+
|
|
68
|
+
- `npm run build`: Builds the production version.
|
|
69
|
+
- This script sequentially executes the following commands:
|
|
70
|
+
- `npm run build:client`: Builds the client in production mode.
|
|
71
|
+
- `npm run build:server`: Builds the server in production mode.
|
|
72
|
+
|
|
73
|
+
- `npm run start`: Runs the production version.
|
|
74
|
+
- This script starts the server using the compiled production files.
|
|
75
|
+
|
|
76
|
+
- `npm run test`: Runs test units with Jest.
|
|
77
|
+
- This script executes the test units using Jest.
|
|
78
|
+
|
|
79
|
+
## File structure
|
|
80
|
+
|
|
81
|
+
- `src/client`: Contains client-side ``` (React components, styles, etc.).
|
|
82
|
+
- `src/server`: Contains server-side ``` (Node HTTP/HTTPS routes, API routes, etc.).
|
|
83
|
+
- `src/common`: Contains common ```.
|
|
84
|
+
- `public`: Contains the bundle.js client ``` and public files for the project.
|
|
85
|
+
- `dist`: Contains production build output of server.
|
|
86
|
+
|
|
87
|
+
## Node HTTP/HTTP server with server side router.
|
|
88
|
+
|
|
89
|
+
`src/server/core/server.ts` contains the source ```, it supports middlewares, wildcard routes and specific routes. There are middlewares currently for setting cors and static files.
|
|
90
|
+
|
|
91
|
+
### Basic example
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
import { createRouter, createServer, listen } from './core/server';
|
|
95
|
+
import { cors } from './core/cors';
|
|
96
|
+
import { assets } from './core/assets';
|
|
97
|
+
// Creating the router
|
|
98
|
+
const router = createRouter();
|
|
99
|
+
|
|
100
|
+
// Adding static file middleware
|
|
101
|
+
router.Middleware(assets("./public"));
|
|
102
|
+
|
|
103
|
+
// Creating a ping route
|
|
104
|
+
// For request and response we dont use wrappers for node http types and methods.
|
|
105
|
+
router.Get("/ping", (req: HoosatRequest, res: HoosatResponse) => {
|
|
106
|
+
res.status(200).json("pong!");
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// Now that the middleware and routes have been set the server must be created that handles the routes.
|
|
110
|
+
const server = createServer(router);
|
|
111
|
+
|
|
112
|
+
// Start listening on port 3000
|
|
113
|
+
const port = parseInt(process.env.PORT || "8080");
|
|
114
|
+
listen(server, port, () => {
|
|
115
|
+
console.log(`Server is running on port ${port.toString()}`);
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
## License
|
|
121
|
+
This template is licensed under the ISC License. Feel free to use it for your own projects or as a starting point for your own templates.
|
|
122
|
+
|
|
123
|
+
## Message
|
|
124
|
+
|
|
125
|
+
I just dropped some dependancies from the repository and this will keep happening. With our own ``` we can keep it up to date with React and Node versions more easily.
|
|
126
|
+
Though for now the only goal seems to be to drop `react-helmet-async`.
|
|
127
|
+
|
|
128
|
+
## Release changes
|
|
129
|
+
|
|
130
|
+
### 1.4.7 -> 1.5.0
|
|
131
|
+
- Requires Node.js 22 or newer (Node.js 20 is end-of-life), template is tested on Node.js 22, 24 and 26.
|
|
132
|
+
- Clone the template and its submodule over HTTPS, so no GitHub SSH key is needed.
|
|
133
|
+
- Run git and npm without a shell and with argument lists, so project names can not be interpreted as shell commands.
|
|
134
|
+
- Fix `--gitInit n` and `--hoosatui n` being treated as yes.
|
|
135
|
+
- Stop when cloning the template fails instead of continuing in the wrong directory.
|
|
136
|
+
- Fix `submodule` command on Windows and with git 2.38.1+.
|
|
137
|
+
- Template: React 19, React Router 8, TypeScript 6, Jest 30, i18next 27, security fixes in server core and all dependency vulnerabilities resolved.
|
|
138
|
+
|
|
139
|
+
### 1.4.5 -> 1.4.6
|
|
140
|
+
- Use submodule for server, make cloning of template recursive.
|
|
141
|
+
|
|
142
|
+
### 1.4.4 -> 1.4.5
|
|
143
|
+
- One small document change in server code example, to make your life easier.
|
|
144
|
+
- Add support for command line arguments.
|
|
145
|
+
- Add support for npx hoosat-create submodule
|
|
146
|
+
|
|
147
|
+
### 1.4.3 -> 1.4.4
|
|
148
|
+
- Why the heck I removed that #!/usr/bin/env node.. Now it's back.
|
|
149
|
+
|
|
150
|
+
### 1.4.2 -> 1.4.3
|
|
151
|
+
- Update package.json to contain metadata
|
|
152
|
+
|
|
153
|
+
### 1.4.1 -> 1.4.2
|
|
154
|
+
- Remove download-git-repo dependancy from hoosat-create
|
|
155
|
+
- Do input validation in hoosat-create. Which means following characters do not work in project name.
|
|
156
|
+
- ';', '|', '&&', '>', '<', '`', '$(', '$()'
|
|
157
|
+
|
|
158
|
+
### 1.4.0 -> 1.4.1
|
|
159
|
+
- Changed createServer to include options argument for changing server protocol and to include SSL certificate information.
|
|
160
|
+
- JSDoc has been added and more documentation work.
|
|
161
|
+
|
|
162
|
+
### 1.3.5 -> 1.4.0
|
|
163
|
+
- Dropped Express.js and Babel from dependancies.
|
|
164
|
+
- Updated package.json scripts to use concurrently and nodemon.
|
|
165
|
+
|
|
166
|
+
## Join us
|
|
167
|
+
[https://discord.gg/UXPFcPaPBg](Discord)
|
package/index.js
CHANGED
|
@@ -1,226 +1,256 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import { spawn } from 'child_process';
|
|
4
|
-
import { createInterface } from 'readline';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
console.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
// git
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
console.log("Now commit your changes to git.");
|
|
81
|
-
rl.close();
|
|
82
|
-
} else {
|
|
83
|
-
console.log('Creating a new project from Hoosat React SSR Template.');
|
|
84
|
-
const destination = getValueFromArgument('destination') || (await askQuestion('Enter destination project name: '));
|
|
85
|
-
const description = getValueFromArgument('description') || (await askQuestion('Enter project description: '));
|
|
86
|
-
const author = getValueFromArgument('author') || (await askQuestion('Enter project author: '));
|
|
87
|
-
const license = getValueFromArgument('license') || (await askQuestion('Enter project license: '));
|
|
88
|
-
const keywords = getValueFromArgument('keywords') || (await askQuestion('Enter project keywords (comma-separated): '));
|
|
89
|
-
const keywordList = keywords.split(',').map(k => k.trim()).filter(k => k !== '');
|
|
90
|
-
const gitInit =
|
|
91
|
-
let installHoosatUI =
|
|
92
|
-
if (gitInit) {
|
|
93
|
-
installHoosatUI =
|
|
94
|
-
}
|
|
95
|
-
try {
|
|
96
|
-
// Clone git repository.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
packageJson.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
import { createInterface } from 'node:readline/promises';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
|
|
7
|
+
const repository = 'https://github.com/TMKCodes/hoosat-template.git';
|
|
8
|
+
const hoosatUIRepository = 'https://github.com/hoosat-oy/HoosatUI';
|
|
9
|
+
const minimumNodeMajor = 22;
|
|
10
|
+
|
|
11
|
+
const rl = createInterface({
|
|
12
|
+
input: process.stdin,
|
|
13
|
+
output: process.stdout
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
async function run() {
|
|
17
|
+
const nodeMajor = Number(process.versions.node.split('.')[0]);
|
|
18
|
+
if (nodeMajor < minimumNodeMajor) {
|
|
19
|
+
console.warn(`Warning: Node.js ${process.versions.node} is not supported anymore. Please use Node.js ${minimumNodeMajor} or newer (https://nodejs.org).`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const command = process.argv[2];
|
|
23
|
+
|
|
24
|
+
if (command === 'submodule') {
|
|
25
|
+
console.log('Creating a submodule for project.');
|
|
26
|
+
const rootDirectory = process.cwd();
|
|
27
|
+
const destination = getValueFromArgument('destination') || (await askQuestion('Enter relative destination for new submodule: '));
|
|
28
|
+
try {
|
|
29
|
+
await runCommand('git', ['rev-parse', '--is-inside-work-tree'], 'Current working directory is not git repository.');
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.error(error.message);
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
// mkdir submodule-destination
|
|
35
|
+
try {
|
|
36
|
+
await fs.promises.mkdir(destination, { recursive: true });
|
|
37
|
+
console.log("Created submodule folder.");
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error(error.message);
|
|
40
|
+
}
|
|
41
|
+
// cd submodule-destination, git init, commit a README and cd back to root of project
|
|
42
|
+
process.chdir(destination);
|
|
43
|
+
try {
|
|
44
|
+
await runCommand('git', ['init'], 'Failed to initialize git for submodule.');
|
|
45
|
+
console.log("Initialized git repository.");
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error(error.message);
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
if (!fs.existsSync('./README.md')) {
|
|
51
|
+
fs.writeFileSync('./README.md', '');
|
|
52
|
+
}
|
|
53
|
+
console.log("Created README.md file for commit.");
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error('Failed to create README.md file', error.message);
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
await runCommand('git', ['add', './README.md'], 'Failed to stage README.md.');
|
|
59
|
+
console.log("Staged README.md");
|
|
60
|
+
} catch (error) {
|
|
61
|
+
console.error(error.message);
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
await runCommand('git', ['commit', '-m', 'Add readme.'], 'Failed to commit.');
|
|
65
|
+
console.log("Committed readme.");
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error(error.message);
|
|
68
|
+
}
|
|
69
|
+
// Change back to the root of the project
|
|
70
|
+
process.chdir(rootDirectory);
|
|
71
|
+
// git submodule add ./submodule-destination submodule-destination
|
|
72
|
+
// Giving the path registers the existing repository in place. Without it git tries to clone it
|
|
73
|
+
// over the "file" transport, which git 2.38.1+ blocks by default (CVE-2022-39253).
|
|
74
|
+
try {
|
|
75
|
+
await runCommand('git', ['submodule', 'add', `./${destination}`, destination], 'Failed to add the new local repository as git submodule');
|
|
76
|
+
console.log("Added local repository as git submodule to parent git repository.");
|
|
77
|
+
} catch (error) {
|
|
78
|
+
console.error(error.message);
|
|
79
|
+
}
|
|
80
|
+
console.log("Now commit your changes to git.");
|
|
81
|
+
rl.close();
|
|
82
|
+
} else {
|
|
83
|
+
console.log('Creating a new project from Hoosat React SSR Template.');
|
|
84
|
+
const destination = getValueFromArgument('destination') || (await askQuestion('Enter destination project name: '));
|
|
85
|
+
const description = getValueFromArgument('description') || (await askQuestion('Enter project description: '));
|
|
86
|
+
const author = getValueFromArgument('author') || (await askQuestion('Enter project author: '));
|
|
87
|
+
const license = getValueFromArgument('license') || (await askQuestion('Enter project license: '));
|
|
88
|
+
const keywords = getValueFromArgument('keywords') || (await askQuestion('Enter project keywords (comma-separated): '));
|
|
89
|
+
const keywordList = keywords.split(',').map(k => k.trim()).filter(k => k !== '');
|
|
90
|
+
const gitInit = getYesNoFromArgument('gitInit') ?? (await askYesNoQuestion('Do you want to initialize a git repository? [Y/n] '));
|
|
91
|
+
let installHoosatUI = false;
|
|
92
|
+
if (gitInit) {
|
|
93
|
+
installHoosatUI = getYesNoFromArgument('hoosatui') ?? (await askYesNoQuestion('Do you want to install HoosatUI? [Y/n] '));
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
// Clone git repository.
|
|
97
|
+
await runCommand('git', ['clone', '--recursive', repository, destination], 'Failed to clone project.', { stdio: 'inherit' });
|
|
98
|
+
console.log('Project cloned successfully.');
|
|
99
|
+
// Change directory to the project directory
|
|
100
|
+
process.chdir(destination);
|
|
101
|
+
// Modify the package.json
|
|
102
|
+
const packageJsonPath = join(process.cwd(), 'package.json');
|
|
103
|
+
const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf8');
|
|
104
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
105
|
+
packageJson.name = destination;
|
|
106
|
+
packageJson.description = description;
|
|
107
|
+
packageJson.author = author;
|
|
108
|
+
packageJson.license = license;
|
|
109
|
+
packageJson.keywords = keywordList;
|
|
110
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n');
|
|
111
|
+
console.log('Project package.json has been modified.');
|
|
112
|
+
// Do NPM install for dependencies.
|
|
113
|
+
try {
|
|
114
|
+
await runCommand('npm', ['install'], 'Failed to install project template dependencies.', { stdio: 'inherit' });
|
|
115
|
+
console.log('Project template dependencies installed with npm.');
|
|
116
|
+
} catch (error) {
|
|
117
|
+
console.error(error.message);
|
|
118
|
+
}
|
|
119
|
+
if (gitInit) {
|
|
120
|
+
// Initialize git repository
|
|
121
|
+
try {
|
|
122
|
+
await runCommand('git', ['init'], 'Failed to initialize git repository.', { stdio: 'inherit' });
|
|
123
|
+
await runCommand('git', ['remote', 'rm', 'origin'], 'Failed to remove origin remote from git repository.', { stdio: 'inherit' });
|
|
124
|
+
console.log('Git has been initialized.');
|
|
125
|
+
} catch (error) {
|
|
126
|
+
console.error(error.message);
|
|
127
|
+
}
|
|
128
|
+
console.log('Git repository initialized.');
|
|
129
|
+
if (installHoosatUI) {
|
|
130
|
+
// Change directory to the client directory
|
|
131
|
+
process.chdir('src/client');
|
|
132
|
+
// Clone HoosatUI repository
|
|
133
|
+
try {
|
|
134
|
+
await runCommand('git', ['submodule', 'add', hoosatUIRepository], 'Failed to add submodule HoosatUI.', { stdio: 'inherit' });
|
|
135
|
+
console.log('HoosatUI cloned successfully as submodule in src/client/HoosatUI.');
|
|
136
|
+
} catch (error) {
|
|
137
|
+
console.error(error.message);
|
|
138
|
+
}
|
|
139
|
+
// Install necessary dev-dependencies
|
|
140
|
+
try {
|
|
141
|
+
await runCommand('npm', ['install', '--save-dev', '@testing-library/jest-dom', '@testing-library/react', '@testing-library/dom'], 'Failed to install HoosatUI devDependencies.', { stdio: 'inherit' });
|
|
142
|
+
console.log('npm HoosatUI devDependencies installed successfully.');
|
|
143
|
+
} catch (error) {
|
|
144
|
+
console.error(error.message);
|
|
145
|
+
}
|
|
146
|
+
// Install necessary dependencies.
|
|
147
|
+
try {
|
|
148
|
+
await runCommand('npm', ['install', 'react-markdown', 'rehype-highlight', 'remark-gfm'], 'Failed to install HoosatUI dependencies.', { stdio: 'inherit' });
|
|
149
|
+
console.log('npm HoosatUI dependencies installed successfully.');
|
|
150
|
+
} catch (error) {
|
|
151
|
+
console.error(error.message);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
} catch (err) {
|
|
156
|
+
console.error(`Failed to create project: ${err.message}`);
|
|
157
|
+
process.exitCode = 1;
|
|
158
|
+
} finally {
|
|
159
|
+
rl.close();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Runs a command without a shell, so arguments (like the project name) can never be
|
|
166
|
+
* interpreted as shell syntax. Only npm on Windows needs a shell, because it is a .cmd file
|
|
167
|
+
* and Node.js refuses to spawn those without one; its arguments are always static strings here.
|
|
168
|
+
*/
|
|
169
|
+
function runCommand(command, args, errorMessage, spawnOptions = {}) {
|
|
170
|
+
const needsShell = process.platform === 'win32' && command === 'npm';
|
|
171
|
+
return new Promise((resolve, reject) => {
|
|
172
|
+
const commandProcess = needsShell
|
|
173
|
+
? spawn([command, ...args].join(' '), { ...spawnOptions, shell: true })
|
|
174
|
+
: spawn(command, args, { ...spawnOptions, shell: false });
|
|
175
|
+
const fail = (reason) => reject(new Error(`${command} ${args.join(' ')}\r\n${errorMessage}${reason ? ` (${reason})` : ''}`));
|
|
176
|
+
commandProcess.on('error', (error) => fail(error.message));
|
|
177
|
+
commandProcess.on('close', code => {
|
|
178
|
+
if (code === 0) {
|
|
179
|
+
resolve();
|
|
180
|
+
} else {
|
|
181
|
+
fail(`exit code ${code}`);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function getValueFromArgument(argName) {
|
|
188
|
+
const argIndex = process.argv.findIndex(arg => arg === `--${argName}`);
|
|
189
|
+
if (argIndex !== -1 && argIndex + 1 < process.argv.length) {
|
|
190
|
+
const value = process.argv[argIndex + 1];
|
|
191
|
+
if (containsInvalidCharacters(value)) {
|
|
192
|
+
throw new Error(`Invalid value for --${argName}. The value contains invalid characters.`);
|
|
193
|
+
}
|
|
194
|
+
return value;
|
|
195
|
+
}
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Reads a yes/no command line argument, for example `--gitInit Y` or `--gitInit n`.
|
|
201
|
+
* @returns {boolean | undefined} undefined when the argument was not given.
|
|
202
|
+
*/
|
|
203
|
+
function getYesNoFromArgument(argName) {
|
|
204
|
+
const value = getValueFromArgument(argName);
|
|
205
|
+
if (value === undefined) {
|
|
206
|
+
return undefined;
|
|
207
|
+
}
|
|
208
|
+
const answer = parseYesNo(value);
|
|
209
|
+
if (answer === undefined) {
|
|
210
|
+
throw new Error(`Invalid value for --${argName}. Please provide a valid yes/no answer (Y/n).`);
|
|
211
|
+
}
|
|
212
|
+
return answer;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function parseYesNo(value) {
|
|
216
|
+
const normalized = value.trim().toLowerCase();
|
|
217
|
+
if (normalized === '' || normalized === 'y' || normalized === 'yes' || normalized === 'true') {
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
if (normalized === 'n' || normalized === 'no' || normalized === 'false') {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
return undefined;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
async function askQuestion(question) {
|
|
227
|
+
const answer = await rl.question(question);
|
|
228
|
+
if (containsInvalidCharacters(answer)) {
|
|
229
|
+
throw new Error('Invalid input. The answer contains invalid characters.');
|
|
230
|
+
}
|
|
231
|
+
return answer;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async function askYesNoQuestion(question) {
|
|
235
|
+
const answer = parseYesNo(await rl.question(question));
|
|
236
|
+
if (answer === undefined) {
|
|
237
|
+
throw new Error('Invalid input. Please provide a valid yes/no answer (Y/n).');
|
|
238
|
+
}
|
|
239
|
+
return answer;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function containsInvalidCharacters(input) {
|
|
243
|
+
// Define the list of invalid characters or commands
|
|
244
|
+
const invalidCharacters = [';', '|', '&&', '>', '<', '`', '$(', '$()'];
|
|
245
|
+
// Check if the input contains any invalid characters or commands
|
|
246
|
+
return invalidCharacters.some(character => input.includes(character));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
run().catch((error) => {
|
|
250
|
+
console.error(error.message);
|
|
251
|
+
rl.close();
|
|
252
|
+
process.exitCode = 1;
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
// Export the askQuestion function for testing purposes
|
|
256
|
+
export default { askQuestion };
|
package/package.json
CHANGED
|
@@ -1,23 +1,31 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "hoosat-create",
|
|
3
|
-
"type": "module",
|
|
4
|
-
"version": "1.
|
|
5
|
-
"description": "Hoosat - React & Typescript SSR project template.",
|
|
6
|
-
"homepage": "https://example.com",
|
|
7
|
-
"author": "Toni Lukkaroinen @ Hoosat Oy",
|
|
8
|
-
"license": "ISC",
|
|
9
|
-
"bugs": {
|
|
10
|
-
"url": "https://github.com/Hoosat-Oy/hoosat-create/issues"
|
|
11
|
-
},
|
|
12
|
-
"repository": {
|
|
13
|
-
"type": "git",
|
|
14
|
-
"url": "https://github.com/Hoosat-Oy/hoosat-create"
|
|
15
|
-
},
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
}
|
|
23
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "hoosat-create",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.5.0",
|
|
5
|
+
"description": "Hoosat - React & Typescript SSR project template.",
|
|
6
|
+
"homepage": "https://example.com",
|
|
7
|
+
"author": "Toni Lukkaroinen @ Hoosat Oy",
|
|
8
|
+
"license": "ISC",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/Hoosat-Oy/hoosat-create/issues"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/Hoosat-Oy/hoosat-create.git"
|
|
15
|
+
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=22"
|
|
18
|
+
},
|
|
19
|
+
"main": "index.js",
|
|
20
|
+
"bin": {
|
|
21
|
+
"hoosat-create": "index.js"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"index.js",
|
|
25
|
+
"README.md",
|
|
26
|
+
"LICENSE.txt"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"test": "node index.js"
|
|
30
|
+
}
|
|
31
|
+
}
|