hoosat-create 1.4.1 → 1.4.3

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.
Files changed (3) hide show
  1. package/README.md +8 -1
  2. package/index.js +92 -27
  3. package/package.json +12 -7
package/README.md CHANGED
@@ -88,7 +88,7 @@ listen(server, port, () => {
88
88
 
89
89
 
90
90
  ## License
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.
91
+ 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.
92
92
 
93
93
  ## Message
94
94
 
@@ -96,6 +96,13 @@ I just dropped some dependancies from the repository and this will keep happenin
96
96
  Though for now the only goal seems to be to drop `react-helmet-async`.
97
97
 
98
98
  ## Release changes
99
+ ### 1.4.2 -> 1.4.3
100
+ - Update package.json to contain metadata
101
+
102
+ ### 1.4.1 -> 1.4.2
103
+ - Remove download-git-repo dependancy from hoosat-create
104
+ - Do input validation in hoosat-create. Which means following characters do not work in project name.
105
+ - ';', '|', '&&', '>', '<', '`', '$(', '$()'
99
106
 
100
107
  ### 1.4.0 -> 1.4.1
101
108
  - Changed createServer to include options argument for changing server protocol and to include SSL certificate information.
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:Hoosat-Oy/hoosat-template';
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 install initialize git repository? [Y/n] ');
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
- // Download git repository.
30
- await promisifiedDownload(repository, destination);
31
- console.log('Project downloaded successfully');
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 packageJson = require(packageJsonPath);
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 dependancies.
50
+ // Do NPM install for dependencies.
45
51
  const install = spawn('npm', ['install'], { stdio: 'inherit' });
46
- await new Promise(resolve => install.on('close', 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 => gitInit.on('close', 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
- // Install HoosatUI as a git submodule
57
- const gitSubmodule = spawn('git', ['submodule', 'add', 'https://github.com/hoosat-oy/HoosatUI'], { stdio: 'inherit' });
58
- await new Promise(resolve => gitSubmodule.on('close', resolve));
59
- console.log('HoosatUI installed successfully.');
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 => installHoosatUIDevDeps.on('close', 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 dependancies.
102
+ // Install necessary dependencies.
65
103
  const installHoosatUIDeps = spawn('npm', ['install', 'react-markdown', 'rehype-highlight', 'remark-gfm'], { stdio: 'inherit' });
66
- await new Promise(resolve => installHoosatUIDeps.on('close', 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 download project: ${err}`);
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, resolve);
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
- resolve(normalizedAnswer === '' || normalizedAnswer === 'y' || normalizedAnswer === 'yes');
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,22 @@
1
1
  {
2
2
  "name": "hoosat-create",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
4
4
  "description": "Hoosat - React & Typescript SSR project template.",
5
+ "homepage": "https://example.com",
6
+ "author": "Toni Lukkaroinen @ Hoosat Oy",
7
+ "license": "ISC",
8
+ "bugs": {
9
+ "url": "https://github.com/Hoosat-Oy/hoosat-create/issues"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/Hoosat-Oy/hoosat-create"
14
+ },
5
15
  "main": "index.js",
6
16
  "bin": {
7
17
  "hoosat-create": "index.js"
8
18
  },
9
19
  "scripts": {
10
- "test": "echo \"Error: no test specified\" && exit 1"
11
- },
12
- "author": "",
13
- "license": "ISC",
14
- "dependencies": {
15
- "download-git-repo": "^3.0.2"
20
+ "test": "node index.js"
16
21
  }
17
22
  }