hoosat-create 1.4.0 → 1.4.2
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 +50 -10
- package/index.js +92 -27
- package/package.json +3 -6
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ npx hoosat-create@latest
|
|
|
20
20
|
|
|
21
21
|
- Full-stack TypeScript application using React and Node HTTP/HTTPS.
|
|
22
22
|
- Includes working server side SEO with `react-helmet-async`
|
|
23
|
-
- Supports ES modules for server-side and client-side
|
|
23
|
+
- Supports ES modules for server-side and client-side ```.
|
|
24
24
|
- Configured with Webpack for production builds.
|
|
25
25
|
- Includes Jest for unit testing.
|
|
26
26
|
- Includes example components and routes for getting started.
|
|
@@ -47,29 +47,69 @@ npx hoosat-create@latest
|
|
|
47
47
|
|
|
48
48
|
## File structure
|
|
49
49
|
|
|
50
|
-
- `src/client`: Contains client-side
|
|
51
|
-
- `src/server`: Contains server-side
|
|
52
|
-
- `src/common`: Contains common
|
|
53
|
-
- `public`: Contains the bundle.js client
|
|
50
|
+
- `src/client`: Contains client-side ``` (React components, styles, etc.).
|
|
51
|
+
- `src/server`: Contains server-side ``` (Node HTTP/HTTPS routes, API routes, etc.).
|
|
52
|
+
- `src/common`: Contains common ```.
|
|
53
|
+
- `public`: Contains the bundle.js client ``` and public files for the project.
|
|
54
54
|
- `dist`: Contains production build output of server.
|
|
55
55
|
|
|
56
|
+
## Node HTTP/HTTP server with server side router.
|
|
57
|
+
|
|
58
|
+
`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.
|
|
59
|
+
|
|
60
|
+
### Basic example
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
import { createRouter, createServer, listen } from './core/server';
|
|
64
|
+
import { cors } from './core/cors';
|
|
65
|
+
import { assets } from './core/assets';
|
|
66
|
+
// Creating the router
|
|
67
|
+
const router = createRouter();
|
|
68
|
+
|
|
69
|
+
// Adding static file middleware
|
|
70
|
+
router.Middleware(assets("./public"));
|
|
71
|
+
|
|
72
|
+
// Creating a ping route
|
|
73
|
+
// For request and response we dont use wrappers for node http types and methods.
|
|
74
|
+
router.Get("/ping", (req: IncomingMessage, res: ServerResponse) => {
|
|
75
|
+
res.writeHead(20, { 'Content-Type': "text/plain" });
|
|
76
|
+
res.end("pong!");
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// Now that the middleware and routes have been set the server must be created that handles the routes.
|
|
80
|
+
const server = createServer(router);
|
|
81
|
+
|
|
82
|
+
// Start listening on port 3000
|
|
83
|
+
const port = parseInt(process.env.PORT || "8080");
|
|
84
|
+
listen(server, port, () => {
|
|
85
|
+
console.log(`Server is running on port ${port.toString()}`);
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
|
|
56
90
|
## License
|
|
57
91
|
This template is licensed under the MIT License. Feel free to use it for your own projects or as a starting point for your own templates.
|
|
58
92
|
|
|
59
93
|
## Message
|
|
60
94
|
|
|
61
|
-
I just dropped some dependancies from the repository and this will keep happening. With our own
|
|
95
|
+
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.
|
|
62
96
|
Though for now the only goal seems to be to drop `react-helmet-async`.
|
|
63
97
|
|
|
64
98
|
## Release changes
|
|
65
99
|
|
|
100
|
+
|
|
101
|
+
### 1.4.1 -> 1.4.2
|
|
102
|
+
- Remove download-git-repo dependancy from hoosat-create
|
|
103
|
+
- Do input validation in hoosat-create. Which means following characters do not work in project name.
|
|
104
|
+
- ';', '|', '&&', '>', '<', '`', '$(', '$()'
|
|
105
|
+
|
|
106
|
+
### 1.4.0 -> 1.4.1
|
|
107
|
+
- Changed createServer to include options argument for changing server protocol and to include SSL certificate information.
|
|
108
|
+
- JSDoc has been added and more documentation work.
|
|
109
|
+
|
|
66
110
|
### 1.3.5 -> 1.4.0
|
|
67
111
|
- Dropped Express.js and Babel from dependancies.
|
|
68
112
|
- Updated package.json scripts to use concurrently and nodemon.
|
|
69
113
|
|
|
70
114
|
## Join us
|
|
71
115
|
[https://discord.gg/UXPFcPaPBg](Discord)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
package/index.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const download = require('download-git-repo');
|
|
3
|
-
const { promisify } = require('util');
|
|
4
|
-
const promisifiedDownload = promisify(download);
|
|
5
|
-
const readline = require('readline');
|
|
6
1
|
const { spawn } = require('child_process');
|
|
2
|
+
const readline = require('readline');
|
|
7
3
|
const fs = require('fs');
|
|
8
4
|
const path = require('path');
|
|
9
5
|
|
|
10
|
-
const repository = 'github
|
|
6
|
+
const repository = 'https://github.com/Hoosat-Oy/hoosat-template.git';
|
|
11
7
|
const rl = readline.createInterface({
|
|
12
8
|
input: process.stdin,
|
|
13
9
|
output: process.stdout
|
|
@@ -20,20 +16,30 @@ async function run() {
|
|
|
20
16
|
const license = await askQuestion('Enter project license: ');
|
|
21
17
|
const keywords = await askQuestion('Enter project keywords (comma-separated): ');
|
|
22
18
|
const keywordList = keywords.split(',').map(k => k.trim()).filter(k => k !== '');
|
|
23
|
-
const gitInit = await askYesNoQuestion('Do you want to
|
|
19
|
+
const gitInit = await askYesNoQuestion('Do you want to initialize a git repository? [Y/n] ');
|
|
24
20
|
let installHoosatUI = undefined;
|
|
25
|
-
if(gitInit) {
|
|
21
|
+
if (gitInit) {
|
|
26
22
|
installHoosatUI = await askYesNoQuestion('Do you want to install HoosatUI? [Y/n] ');
|
|
27
23
|
}
|
|
28
24
|
try {
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
// Clone git repository.
|
|
26
|
+
const clone = spawn('git', ['clone', repository, destination]);
|
|
27
|
+
await new Promise((resolve, reject) => {
|
|
28
|
+
clone.on('close', code => {
|
|
29
|
+
if (code === 0) {
|
|
30
|
+
resolve();
|
|
31
|
+
} else {
|
|
32
|
+
reject(new Error('Failed to clone project.'));
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
console.log('Project cloned successfully');
|
|
32
37
|
// Change directory to the project directory
|
|
33
38
|
process.chdir(destination);
|
|
34
39
|
// Modify the package.json
|
|
35
40
|
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
36
|
-
const
|
|
41
|
+
const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf8');
|
|
42
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
37
43
|
packageJson.name = destination;
|
|
38
44
|
packageJson.description = description;
|
|
39
45
|
packageJson.author = author;
|
|
@@ -41,54 +47,113 @@ async function run() {
|
|
|
41
47
|
packageJson.keywords = keywordList;
|
|
42
48
|
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
43
49
|
console.log('Project package.json has been modified.');
|
|
44
|
-
// Do NPM install for
|
|
50
|
+
// Do NPM install for dependencies.
|
|
45
51
|
const install = spawn('npm', ['install'], { stdio: 'inherit' });
|
|
46
|
-
await new Promise(resolve =>
|
|
52
|
+
await new Promise((resolve, reject) => {
|
|
53
|
+
install.on('close', code => {
|
|
54
|
+
if (code === 0) {
|
|
55
|
+
resolve();
|
|
56
|
+
} else {
|
|
57
|
+
reject(new Error('Failed to install project dependencies.'));
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
47
61
|
console.log('npm install completed');
|
|
48
62
|
if (gitInit) {
|
|
49
63
|
// Initialize git repository
|
|
50
64
|
const gitInit = spawn('git', ['init']);
|
|
51
|
-
await new Promise(resolve =>
|
|
65
|
+
await new Promise((resolve, reject) => {
|
|
66
|
+
gitInit.on('close', code => {
|
|
67
|
+
if (code === 0) {
|
|
68
|
+
resolve();
|
|
69
|
+
} else {
|
|
70
|
+
reject(new Error('Failed to initialize git repository.'));
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
52
74
|
console.log('Git repository initialized.');
|
|
53
75
|
if (installHoosatUI) {
|
|
54
76
|
// Change directory to the client directory
|
|
55
77
|
process.chdir('src/client');
|
|
56
|
-
//
|
|
57
|
-
const
|
|
58
|
-
await new Promise(resolve =>
|
|
59
|
-
|
|
78
|
+
// Clone HoosatUI repository
|
|
79
|
+
const hoosatUIClone = spawn('git', ['clone', 'https://github.com/hoosat-oy/HoosatUI']);
|
|
80
|
+
await new Promise((resolve, reject) => {
|
|
81
|
+
hoosatUIClone.on('close', code => {
|
|
82
|
+
if (code === 0) {
|
|
83
|
+
resolve();
|
|
84
|
+
} else {
|
|
85
|
+
reject(new Error('Failed to clone HoosatUI.'));
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
console.log('HoosatUI cloned successfully.');
|
|
60
90
|
// Install necessary dev-dependencies
|
|
61
91
|
const installHoosatUIDevDeps = spawn('npm', ['install', '--save-dev', '@testing-library/jest-dom', '@testing-library/react'], { stdio: 'inherit' });
|
|
62
|
-
await new Promise(resolve =>
|
|
92
|
+
await new Promise((resolve, reject) => {
|
|
93
|
+
installHoosatUIDevDeps.on('close', code => {
|
|
94
|
+
if (code === 0) {
|
|
95
|
+
resolve();
|
|
96
|
+
} else {
|
|
97
|
+
reject(new Error('Failed to install HoosatUI devDependencies.'));
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|
|
63
101
|
console.log('npm HoosatUI devDependencies installed successfully.');
|
|
64
|
-
// Install necessary
|
|
102
|
+
// Install necessary dependencies.
|
|
65
103
|
const installHoosatUIDeps = spawn('npm', ['install', 'react-markdown', 'rehype-highlight', 'remark-gfm'], { stdio: 'inherit' });
|
|
66
|
-
await new Promise(resolve =>
|
|
104
|
+
await new Promise((resolve, reject) => {
|
|
105
|
+
installHoosatUIDeps.on('close', code => {
|
|
106
|
+
if (code === 0) {
|
|
107
|
+
resolve();
|
|
108
|
+
} else {
|
|
109
|
+
reject(new Error('Failed to install HoosatUI dependencies.'));
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
});
|
|
67
113
|
console.log('npm HoosatUI dependencies installed successfully.');
|
|
68
114
|
}
|
|
69
115
|
}
|
|
70
116
|
} catch (err) {
|
|
71
|
-
console.error(`Failed to
|
|
117
|
+
console.error(`Failed to clone project: ${err}`);
|
|
72
118
|
} finally {
|
|
73
119
|
rl.close();
|
|
74
120
|
}
|
|
75
121
|
}
|
|
76
122
|
|
|
77
123
|
function askQuestion(question) {
|
|
78
|
-
return new Promise(resolve => {
|
|
79
|
-
rl.question(question,
|
|
124
|
+
return new Promise((resolve, reject) => {
|
|
125
|
+
rl.question(question, answer => {
|
|
126
|
+
if (!containsInvalidCharacters(answer)) {
|
|
127
|
+
resolve(answer);
|
|
128
|
+
} else {
|
|
129
|
+
reject(new Error('Invalid input. The answer contains invalid characters.'));
|
|
130
|
+
}
|
|
131
|
+
});
|
|
80
132
|
});
|
|
81
133
|
}
|
|
82
134
|
|
|
83
135
|
function askYesNoQuestion(question) {
|
|
84
|
-
return new Promise(resolve => {
|
|
136
|
+
return new Promise((resolve, reject) => {
|
|
85
137
|
rl.question(question, answer => {
|
|
86
138
|
const normalizedAnswer = answer.trim().toLowerCase();
|
|
87
|
-
|
|
139
|
+
if (normalizedAnswer === '' || normalizedAnswer === 'y' || normalizedAnswer === 'yes') {
|
|
140
|
+
resolve(true);
|
|
141
|
+
} else if (normalizedAnswer === 'n' || normalizedAnswer === 'no') {
|
|
142
|
+
resolve(false);
|
|
143
|
+
} else {
|
|
144
|
+
reject(new Error('Invalid input. Please provide a valid yes/no answer (Y/n).'));
|
|
145
|
+
}
|
|
88
146
|
});
|
|
89
147
|
});
|
|
90
148
|
}
|
|
91
149
|
|
|
150
|
+
function containsInvalidCharacters(input) {
|
|
151
|
+
// Define the list of invalid characters or commands
|
|
152
|
+
const invalidCharacters = [';', '|', '&&', '>', '<', '`', '$(', '$()'];
|
|
153
|
+
// Check if the input contains any invalid characters or commands
|
|
154
|
+
return invalidCharacters.some(character => input.includes(character));
|
|
155
|
+
}
|
|
156
|
+
|
|
92
157
|
run();
|
|
93
158
|
|
|
94
159
|
// Export the askQuestion function for testing purposes
|
package/package.json
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hoosat-create",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "Hoosat - React & Typescript SSR project template.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"hoosat-create": "index.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
-
"test": "
|
|
10
|
+
"test": "node index.js"
|
|
11
11
|
},
|
|
12
12
|
"author": "",
|
|
13
|
-
"license": "ISC"
|
|
14
|
-
"dependencies": {
|
|
15
|
-
"download-git-repo": "^3.0.2"
|
|
16
|
-
}
|
|
13
|
+
"license": "ISC"
|
|
17
14
|
}
|