hoosat-create 1.1.0 → 1.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 +10 -0
- package/Testi/README.md +0 -0
- package/Testi/babel.config.js +7 -0
- package/Testi/jest.config.js +7 -0
- package/Testi/package.json +38 -0
- package/Testi/src/__tests__/example.test.ts +5 -0
- package/Testi/src/client/App.tsx +17 -0
- package/Testi/src/client/index.tsx +5 -0
- package/Testi/src/server/index.ts +34 -0
- package/Testi/tsconfig.json +18 -0
- package/Testi/webpack.config.js +55 -0
- package/index.js +46 -14
- package/package.json +1 -1
package/README.md
ADDED
package/Testi/README.md
ADDED
|
File without changes
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Testi",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Tonton proggis",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "jest",
|
|
8
|
+
"start": "nodemon --watch 'src/**/*.ts*' --exec 'ts-node' src/server/index.ts",
|
|
9
|
+
"build": "webpack --config webpack.config.js",
|
|
10
|
+
"dev": "npm run build && NODE_ENV=development nodemon --watch 'dist/client.js' --exec 'node dist/server.js'"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [],
|
|
13
|
+
"author": "Toni Lukkaroinen",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@babel/core": "^7.21.8",
|
|
17
|
+
"@babel/preset-env": "^7.21.5",
|
|
18
|
+
"@babel/preset-react": "^7.18.6",
|
|
19
|
+
"@babel/preset-typescript": "^7.21.5",
|
|
20
|
+
"@types/jest": "^29.5.1",
|
|
21
|
+
"@types/react": "^18.2.6",
|
|
22
|
+
"@types/react-dom": "^18.2.4",
|
|
23
|
+
"@types/react-helmet": "^6.1.6",
|
|
24
|
+
"babel-loader": "^9.1.2",
|
|
25
|
+
"express": "^4.18.2",
|
|
26
|
+
"jest": "^29.5.0",
|
|
27
|
+
"nodemon": "^2.0.22",
|
|
28
|
+
"react": "^18.2.0",
|
|
29
|
+
"react-dom": "^18.2.0",
|
|
30
|
+
"react-helmet": "^6.1.0",
|
|
31
|
+
"ts-jest": "^29.1.0",
|
|
32
|
+
"ts-node": "^10.9.1",
|
|
33
|
+
"typescript": "^5.0.4",
|
|
34
|
+
"webpack": "^5.82.1",
|
|
35
|
+
"webpack-cli": "^5.1.1",
|
|
36
|
+
"webpack-node-externals": "^3.0.0"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Helmet } from 'react-helmet';
|
|
3
|
+
|
|
4
|
+
const App = () => {
|
|
5
|
+
|
|
6
|
+
return (
|
|
7
|
+
<div>
|
|
8
|
+
<Helmet>
|
|
9
|
+
<title>Changes?</title>
|
|
10
|
+
<meta name="description" content="My page description" />
|
|
11
|
+
</Helmet>
|
|
12
|
+
Hoosat React + Express Typescript SSR!
|
|
13
|
+
</div>
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default App;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { renderToString } from 'react-dom/server';
|
|
5
|
+
import { Helmet } from 'react-helmet';
|
|
6
|
+
import App from '../client/App';
|
|
7
|
+
|
|
8
|
+
const app = express();
|
|
9
|
+
|
|
10
|
+
app.use(express.static(path.join(__dirname, '../../dist')));
|
|
11
|
+
|
|
12
|
+
app.get('/', (req, res) => {
|
|
13
|
+
const message = 'Hello from server!';
|
|
14
|
+
const html = renderToString(React.createElement(App));
|
|
15
|
+
const helmet = Helmet.renderStatic();
|
|
16
|
+
|
|
17
|
+
res.send(`
|
|
18
|
+
<!DOCTYPE html>
|
|
19
|
+
<html>
|
|
20
|
+
<head>
|
|
21
|
+
${helmet.title.toString()}
|
|
22
|
+
${helmet.meta.toString()}
|
|
23
|
+
</head>
|
|
24
|
+
<body>
|
|
25
|
+
<div id="root">${html}</div>
|
|
26
|
+
<script src="/server.js"></script>
|
|
27
|
+
</body>
|
|
28
|
+
</html>
|
|
29
|
+
`);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
app.listen(3000, () => {
|
|
33
|
+
console.log('Server started on http://localhost:3000');
|
|
34
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"esModuleInterop": true,
|
|
5
|
+
"target": "es6",
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"jsx": "react",
|
|
8
|
+
"moduleResolution": "node",
|
|
9
|
+
"noImplicitAny": false,
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"baseUrl": "./src",
|
|
12
|
+
"paths": {
|
|
13
|
+
"*": ["node_modules/*", "src/types/*"]
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"include": ["src/**/*"],
|
|
17
|
+
"exclude": ["node_modules"]
|
|
18
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const webpack = require('webpack');
|
|
3
|
+
const nodeExternals = require('webpack-node-externals');
|
|
4
|
+
|
|
5
|
+
module.exports = [
|
|
6
|
+
{
|
|
7
|
+
name: 'client',
|
|
8
|
+
entry: './src/client/index.tsx',
|
|
9
|
+
mode: 'development',
|
|
10
|
+
output: {
|
|
11
|
+
path: path.resolve(__dirname, 'dist'),
|
|
12
|
+
filename: 'client.js',
|
|
13
|
+
},
|
|
14
|
+
resolve: {
|
|
15
|
+
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
|
16
|
+
},
|
|
17
|
+
module: {
|
|
18
|
+
rules: [
|
|
19
|
+
{
|
|
20
|
+
test: /\.tsx?$/,
|
|
21
|
+
use: 'ts-loader',
|
|
22
|
+
exclude: /node_modules/,
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
plugins: [
|
|
27
|
+
new webpack.DefinePlugin({
|
|
28
|
+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development')
|
|
29
|
+
})
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: 'server',
|
|
34
|
+
entry: './src/server/index.ts',
|
|
35
|
+
mode: 'development',
|
|
36
|
+
target: 'node',
|
|
37
|
+
externals: [nodeExternals()],
|
|
38
|
+
output: {
|
|
39
|
+
path: path.resolve(__dirname, 'dist'),
|
|
40
|
+
filename: 'server.js',
|
|
41
|
+
},
|
|
42
|
+
resolve: {
|
|
43
|
+
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
|
44
|
+
},
|
|
45
|
+
module: {
|
|
46
|
+
rules: [
|
|
47
|
+
{
|
|
48
|
+
test: /\.tsx?$/,
|
|
49
|
+
use: 'ts-loader',
|
|
50
|
+
exclude: /node_modules/,
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
];
|
package/index.js
CHANGED
|
@@ -4,23 +4,55 @@ const { promisify } = require('util');
|
|
|
4
4
|
const promisifiedDownload = promisify(download);
|
|
5
5
|
const readline = require('readline');
|
|
6
6
|
const { spawn } = require('child_process');
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const path = require('path');
|
|
7
9
|
|
|
8
|
-
const repository = 'github:Hoosat-Oy/
|
|
10
|
+
const repository = 'github:Hoosat-Oy/hoosat-template';
|
|
9
11
|
const rl = readline.createInterface({
|
|
10
12
|
input: process.stdin,
|
|
11
13
|
output: process.stdout
|
|
12
14
|
});
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
.
|
|
26
|
-
});
|
|
16
|
+
async function run() {
|
|
17
|
+
const destination = await askQuestion('Enter destination project name: ');
|
|
18
|
+
const description = await askQuestion('Enter project description: ');
|
|
19
|
+
const author = await askQuestion('Enter project author: ');
|
|
20
|
+
const license = await askQuestion('Enter project license: ');
|
|
21
|
+
const keywords = await askQuestion('Enter project keywords (comma-separated): ');
|
|
22
|
+
const keywordList = keywords.split(',').map(k => k.trim()).filter(k => k !== '');
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
await promisifiedDownload(repository, destination);
|
|
26
|
+
console.log('Project downloaded successfully');
|
|
27
|
+
console.log('Running npm install...');
|
|
28
|
+
const install = spawn('npm', ['install'], { cwd: destination, stdio: 'inherit' });
|
|
29
|
+
await new Promise(resolve => install.on('close', resolve));
|
|
30
|
+
console.log('npm install completed');
|
|
31
|
+
const destinationPath = path.resolve("./" + destination);
|
|
32
|
+
const packageJsonPath = path.join(destinationPath, 'package.json');
|
|
33
|
+
const packageJson = require(packageJsonPath);
|
|
34
|
+
packageJson.name = destination;
|
|
35
|
+
packageJson.description = description;
|
|
36
|
+
packageJson.author = author;
|
|
37
|
+
packageJson.license = license;
|
|
38
|
+
packageJson.keywords = keywordList;
|
|
39
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
40
|
+
console.log(`Project's package name updated to ${destination}`);
|
|
41
|
+
console.log(`Project's description updated to ${description}`);
|
|
42
|
+
console.log(`Project's author updated to ${author}`);
|
|
43
|
+
console.log(`Project's license updated to ${license}`);
|
|
44
|
+
console.log(`Project's keywords updated to ${keywordList.join(', ')}`);
|
|
45
|
+
} catch (err) {
|
|
46
|
+
console.error(`Failed to download project: ${err}`);
|
|
47
|
+
} finally {
|
|
48
|
+
rl.close();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function askQuestion(question) {
|
|
53
|
+
return new Promise(resolve => {
|
|
54
|
+
rl.question(question, resolve);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
run();
|