hoosat-create 1.4.3 → 1.4.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 +36 -3
- package/index.js +173 -108
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -8,6 +8,31 @@ Hoosat create is a `npx` script that creates React 18.2 full-stack server side r
|
|
|
8
8
|
npx hoosat-create@latest
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
### Commandline arguments
|
|
12
|
+
- `submodule`
|
|
13
|
+
- `--destination`
|
|
14
|
+
- `--author`
|
|
15
|
+
- `--license`
|
|
16
|
+
- `--keywords`
|
|
17
|
+
- `--keywoordsList`
|
|
18
|
+
- `--gitInit`
|
|
19
|
+
- `--hoosatui`
|
|
20
|
+
|
|
21
|
+
For example:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
npx hoosat-create@latest --destination "new_project" --author "Toni Lukkaroinen" --gitInit Y --hoosatui Y
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Now it will ask the rest like `license` in the process. Which you can default just by pressing enter.
|
|
28
|
+
|
|
29
|
+
### Submodule creation
|
|
30
|
+
|
|
31
|
+
The following command creates an empty git submodule for you to start working on code that will be shared with another project later.
|
|
32
|
+
```
|
|
33
|
+
npx hoosat-create@latest submodule --destination "src/client/submodule"
|
|
34
|
+
```
|
|
35
|
+
|
|
11
36
|
## Technologies Used
|
|
12
37
|
|
|
13
38
|
- React-helmet-async 1.3
|
|
@@ -71,9 +96,8 @@ router.Middleware(assets("./public"));
|
|
|
71
96
|
|
|
72
97
|
// Creating a ping route
|
|
73
98
|
// For request and response we dont use wrappers for node http types and methods.
|
|
74
|
-
router.Get("/ping", (req:
|
|
75
|
-
res.
|
|
76
|
-
res.end("pong!");
|
|
99
|
+
router.Get("/ping", (req: HoosatRequest, res: HoosatResponse) => {
|
|
100
|
+
res.status(200).json("pong!");
|
|
77
101
|
});
|
|
78
102
|
|
|
79
103
|
// Now that the middleware and routes have been set the server must be created that handles the routes.
|
|
@@ -96,6 +120,15 @@ I just dropped some dependancies from the repository and this will keep happenin
|
|
|
96
120
|
Though for now the only goal seems to be to drop `react-helmet-async`.
|
|
97
121
|
|
|
98
122
|
## Release changes
|
|
123
|
+
|
|
124
|
+
### 1.4.4 -> 1.4.5
|
|
125
|
+
- One small document change in server code example, to make your life easier.
|
|
126
|
+
- Add support for command line arguments.
|
|
127
|
+
- Add support for npx hoosat-create submodule
|
|
128
|
+
|
|
129
|
+
### 1.4.3 -> 1.4.4
|
|
130
|
+
- Why the heck I removed that #!/usr/bin/env node.. Now it's back.
|
|
131
|
+
|
|
99
132
|
### 1.4.2 -> 1.4.3
|
|
100
133
|
- Update package.json to contain metadata
|
|
101
134
|
|
package/index.js
CHANGED
|
@@ -1,125 +1,190 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { spawn } from 'child_process';
|
|
4
|
+
import { createInterface } from 'readline';
|
|
5
|
+
import { readFileSync, writeFileSync } from 'fs';
|
|
6
|
+
import { join } from 'path';
|
|
5
7
|
|
|
6
8
|
const repository = 'https://github.com/Hoosat-Oy/hoosat-template.git';
|
|
7
|
-
const rl =
|
|
9
|
+
const rl = createInterface({
|
|
8
10
|
input: process.stdin,
|
|
9
11
|
output: process.stdout
|
|
10
12
|
});
|
|
11
13
|
|
|
12
14
|
async function run() {
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// Change directory to the project directory
|
|
15
|
+
const command = process.argv[2];
|
|
16
|
+
|
|
17
|
+
if (command === 'submodule') {
|
|
18
|
+
console.log('Creating a submodule for project.');
|
|
19
|
+
const rootDirectory = process.cwd();
|
|
20
|
+
//const name = getValueFromArgument('name') || (await askQuestion('Enter name for new submodule: '));
|
|
21
|
+
const destination = getValueFromArgument('destination') || (await askQuestion('Enter relative destination for new submodule: '));
|
|
22
|
+
try {
|
|
23
|
+
await runCommand(`git rev-parse --is-inside-work-tree`, "Current working directory is not git repository.");
|
|
24
|
+
} catch (error) {
|
|
25
|
+
console.error(error.message);
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
// mkdir submodule-destination
|
|
29
|
+
try {
|
|
30
|
+
await fs.promises.mkdir(destination, { recursive: true });
|
|
31
|
+
console.log("Created submodule folder.");
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.error(error.message);
|
|
34
|
+
}
|
|
35
|
+
// cd submodule-destination
|
|
36
|
+
// git init
|
|
37
|
+
// cd back to root of project
|
|
38
|
+
// git commit -m 'Added empty submodule'
|
|
38
39
|
process.chdir(destination);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
})
|
|
61
|
-
|
|
40
|
+
try {
|
|
41
|
+
await runCommand(`git init`, 'Failed to initialize git for submodule.');
|
|
42
|
+
console.log("Initialized git repository.");
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.error(error, error.message);
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
await runCommand(`touch ./README.md`, 'Failed to create README.md file');
|
|
48
|
+
console.log("CreatedREADME.md file for commit.");
|
|
49
|
+
} catch (error) {
|
|
50
|
+
console.error(error.message);
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
await runCommand(`git add ./README.md`, 'Failed to stage README.md.');
|
|
54
|
+
console.log("Staged README.md");
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.error(error.message);
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
await runCommand(`git commit -m 'Add readme.'`, 'Failed to commit.');
|
|
60
|
+
console.log("Committed readme.");
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error(error.message);
|
|
63
|
+
}
|
|
64
|
+
// Change back to the root of the project
|
|
65
|
+
process.chdir(rootDirectory);
|
|
66
|
+
// git submodule add ./submodule-destination submodule-name
|
|
67
|
+
try {
|
|
68
|
+
await runCommand(`git submodule add ./${destination}`, 'Failed to add the new local repository as git submodule');
|
|
69
|
+
console.log("Added local repository as git submodule to parent git repository.");
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.error(error, error.message);
|
|
72
|
+
}
|
|
73
|
+
// git commit -m 'Added empty submodule'
|
|
74
|
+
// try {
|
|
75
|
+
// await runCommand(`git commit -m 'Added ${name} submodule into ${destination}'`, 'Failed to commit changes, do it manually');
|
|
76
|
+
// console.log("Committed changes in parent repository.");
|
|
77
|
+
// } catch (error) {
|
|
78
|
+
// console.error(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 = getValueFromArgument('gitInit') || (await askYesNoQuestion('Do you want to initialize a git repository? [Y/n] '));
|
|
91
|
+
let installHoosatUI = undefined;
|
|
62
92
|
if (gitInit) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
93
|
+
installHoosatUI = getValueFromArgument('hoosatui') || await askYesNoQuestion('Do you want to install HoosatUI? [Y/n] ');
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
// Clone git repository.
|
|
97
|
+
try {
|
|
98
|
+
await runCommand(`git clone ${repository} ${destination}`, 'Failed to clone project.', { stdio: 'inherit' });
|
|
99
|
+
console.log('Project cloned successfully.');
|
|
100
|
+
} catch (error) {
|
|
101
|
+
console.error(error.message);
|
|
102
|
+
}
|
|
103
|
+
// Change directory to the project directory
|
|
104
|
+
process.chdir(destination);
|
|
105
|
+
// Modify the package.json
|
|
106
|
+
const packageJsonPath = join(process.cwd(), 'package.json');
|
|
107
|
+
const packageJsonContent = readFileSync(packageJsonPath, 'utf8');
|
|
108
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
109
|
+
packageJson.name = destination;
|
|
110
|
+
packageJson.description = description;
|
|
111
|
+
packageJson.author = author;
|
|
112
|
+
packageJson.license = license;
|
|
113
|
+
packageJson.keywords = keywordList;
|
|
114
|
+
writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
115
|
+
console.log('Project package.json has been modified.');
|
|
116
|
+
// Do NPM install for dependencies.
|
|
117
|
+
try {
|
|
118
|
+
await runCommand('npm install', 'Failed to install project template dependencies.', { stdio: 'inherit' });
|
|
119
|
+
console.log('Project template dependancies installed with npm.');
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.error(error.message);
|
|
122
|
+
}
|
|
123
|
+
if (gitInit) {
|
|
124
|
+
// Initialize git repository
|
|
125
|
+
try {
|
|
126
|
+
await runCommand('git init', 'Failed to initialize git repository.', { stdio: 'inherit' });
|
|
127
|
+
console.log('Git has been initialized.');
|
|
128
|
+
} catch (error) {
|
|
129
|
+
console.error(error.message);
|
|
130
|
+
}
|
|
131
|
+
console.log('Git repository initialized.');
|
|
132
|
+
if (installHoosatUI) {
|
|
133
|
+
// Change directory to the client directory
|
|
134
|
+
process.chdir('src/client');
|
|
135
|
+
// Clone HoosatUI repository
|
|
136
|
+
try {
|
|
137
|
+
await runCommand('git submodule add https://github.com/hoosat-oy/HoosatUI', 'Failed to add submodule HoosatUI.', { stdio: 'inherit' });
|
|
138
|
+
console.log('HoosatUI cloned successfully as submodule in src/client/HoosatUI.');
|
|
139
|
+
} catch (error) {
|
|
140
|
+
console.error(error.message);
|
|
141
|
+
}
|
|
142
|
+
// Install necessary dev-dependencies
|
|
143
|
+
try {
|
|
144
|
+
await runCommand('npm install --save-dev @testing-library/jest-dom @testing-library/react', 'Failed to install HoosatUI devDependancies.', { stdio: 'inherit' });
|
|
145
|
+
console.log('npm HoosatUI devDependencies installed successfully.');
|
|
146
|
+
} catch (error) {
|
|
147
|
+
console.error(error.message);
|
|
71
148
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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.');
|
|
90
|
-
// Install necessary dev-dependencies
|
|
91
|
-
const installHoosatUIDevDeps = spawn('npm', ['install', '--save-dev', '@testing-library/jest-dom', '@testing-library/react'], { stdio: 'inherit' });
|
|
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
|
-
});
|
|
101
|
-
console.log('npm HoosatUI devDependencies installed successfully.');
|
|
102
|
-
// Install necessary dependencies.
|
|
103
|
-
const installHoosatUIDeps = spawn('npm', ['install', 'react-markdown', 'rehype-highlight', 'remark-gfm'], { stdio: 'inherit' });
|
|
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
|
-
});
|
|
113
|
-
console.log('npm HoosatUI dependencies installed successfully.');
|
|
149
|
+
// Install necessary dependencies.
|
|
150
|
+
try {
|
|
151
|
+
await runCommand('npm install react-markdown rehype-highlight remark-gfm', 'Failed to install HoosatUI dependencies.', { stdio: 'inherit' });
|
|
152
|
+
console.log('npm HoosatUI dependencies installed successfully.');
|
|
153
|
+
} catch (error) {
|
|
154
|
+
console.error(error.message);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
114
157
|
}
|
|
158
|
+
} catch (err) {
|
|
159
|
+
console.error(`Failed to clone project: ${err}`);
|
|
160
|
+
} finally {
|
|
161
|
+
rl.close();
|
|
115
162
|
}
|
|
116
|
-
} catch (err) {
|
|
117
|
-
console.error(`Failed to clone project: ${err}`);
|
|
118
|
-
} finally {
|
|
119
|
-
rl.close();
|
|
120
163
|
}
|
|
121
164
|
}
|
|
122
165
|
|
|
166
|
+
async function runCommand(commandString, errorMessage, spawnOptions) {
|
|
167
|
+
return new Promise((resolve, reject) => {
|
|
168
|
+
const commandProcess = spawn(commandString, [], { shell: true, ...spawnOptions });
|
|
169
|
+
commandProcess.on('close', code => {
|
|
170
|
+
if (code === 0) {
|
|
171
|
+
resolve();
|
|
172
|
+
} else {
|
|
173
|
+
reject(new Error(commandString + "\r\n" + errorMessage));
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
function getValueFromArgument(argName) {
|
|
181
|
+
const argIndex = process.argv.findIndex(arg => arg === `--${argName}`);
|
|
182
|
+
if (argIndex !== -1 && argIndex + 1 < process.argv.length) {
|
|
183
|
+
return process.argv[argIndex + 1];
|
|
184
|
+
}
|
|
185
|
+
return undefined;
|
|
186
|
+
}
|
|
187
|
+
|
|
123
188
|
function askQuestion(question) {
|
|
124
189
|
return new Promise((resolve, reject) => {
|
|
125
190
|
rl.question(question, answer => {
|
|
@@ -157,4 +222,4 @@ function containsInvalidCharacters(input) {
|
|
|
157
222
|
run();
|
|
158
223
|
|
|
159
224
|
// Export the askQuestion function for testing purposes
|
|
160
|
-
|
|
225
|
+
export default { askQuestion };
|
package/package.json
CHANGED