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 ADDED
@@ -0,0 +1,10 @@
1
+ # Hoosat Create
2
+
3
+ Hoosat create is a `npx` script that creates React + Express project for you, where you can use Typescript to build web applications.
4
+
5
+ Give it a test:
6
+ ```
7
+ npx hoosat-create
8
+ ```
9
+
10
+
File without changes
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ presets: [
3
+ '@babel/preset-env',
4
+ '@babel/preset-react',
5
+ '@babel/preset-typescript',
6
+ ],
7
+ };
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ preset: 'ts-jest',
3
+ testEnvironment: 'node',
4
+ roots: ['<rootDir>/src'],
5
+ testMatch: ['**/__tests__/**/*.test.(ts|tsx)'],
6
+ moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
7
+ };
@@ -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,5 @@
1
+ describe('Example Test', () => {
2
+ it('should pass', () => {
3
+ expect(1 + 1).toBe(2);
4
+ });
5
+ });
@@ -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,5 @@
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom';
3
+ import App from './App';
4
+
5
+ ReactDOM.hydrate(<App />, document.getElementById('root'));
@@ -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/react-express-typescript-ssr';
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
- rl.question('Enter destination project name: ', (destination) => {
15
- promisifiedDownload(repository, destination)
16
- .then(() => {
17
- console.log('Project downloaded successfully');
18
- console.log('Running npm install...');
19
- const install = spawn('npm', ['install'], { cwd: destination, stdio: 'inherit' });
20
- install.on('close', () => {
21
- console.log('npm install completed');
22
- });
23
- })
24
- .catch(err => console.error(`Failed to download project: ${err}`))
25
- .finally(() => rl.close());
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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hoosat-create",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Hoosat Oy React + Express.js Typescript SSR project template.",
5
5
  "main": "index.js",
6
6
  "bin": {