@pplancq/create-react-app 1.0.0 → 1.2.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
1
+ ## @pplancq/create-react-app [1.2.0](https://github.com/pplancq/dev-tools/compare/@pplancq/create-react-app@1.1.0...@pplancq/create-react-app@1.2.0) (2024-03-18)
2
+
3
+
4
+ ### Features
5
+
6
+ * **create-react-app:** update documentation for create new project ([3af363f](https://github.com/pplancq/dev-tools/commit/3af363f5c3e436fdbf346af3f19a33d4f17cecac))
7
+
8
+
9
+ ### Reverts
10
+
11
+ * **dev-tool:** add package-lock when execute npm postversion ([1e83fe7](https://github.com/pplancq/dev-tools/commit/1e83fe7ee8d2529ce3b85e1abb56968171ee01ff))
12
+
13
+ ## @pplancq/create-react-app [1.1.0](https://github.com/pplancq/dev-tools/compare/@pplancq/create-react-app@1.0.0...@pplancq/create-react-app@1.1.0) (2024-03-12)
14
+
15
+
16
+ ### Features
17
+
18
+ * **create-react-app:** add check to prevent command injection ([65de337](https://github.com/pplancq/dev-tools/commit/65de33787a4a6eed7588234be6bae1ace5503fb4))
19
+ * **create-react-app:** add option to use vite on new project ([337a6f1](https://github.com/pplancq/dev-tools/commit/337a6f191db3c6aa474e6f9904d22b53ccb58577))
20
+ * **create-react-app:** add remove CHANGELOG.md during create new project ([27d8e7b](https://github.com/pplancq/dev-tools/commit/27d8e7bd246664ec372dd34cedebff274031341b))
21
+ * **create-react-app:** add support for yarn and pnpm ([eafc39d](https://github.com/pplancq/dev-tools/commit/eafc39d972b178ca21ed307166a9ba394161803f))
22
+ * **react-template:** update readme ([3aa2543](https://github.com/pplancq/dev-tools/commit/3aa2543948a697f6604f4984884184d3f285d297))
23
+
1
24
  ## @pplancq/create-react-app 1.0.0 (2024-02-05)
2
25
 
3
26
 
package/README.md CHANGED
@@ -10,8 +10,52 @@ To create a new React project with this package, use the following command:
10
10
  npm create @pplancq/react-app@latest <project_name>
11
11
  ```
12
12
 
13
+ or
14
+
15
+ ```shell
16
+ npx @pplancq/create-react-app@latest <project_name>
17
+ ```
18
+
19
+ or
20
+
21
+ ```shell
22
+ yarn create @pplancq/react-app@latest <project_name>
23
+ ```
24
+
25
+ or
26
+
27
+ ```shell
28
+ pnpm create @pplancq/react-app@latest <project_name>
29
+ ```
30
+
13
31
  Replace <project_name> with the name of your new project.
14
32
 
33
+ ### Using Vite
34
+
35
+ This package also supports creating a new React project with Vite. If you prefer to use Vite instead of webpack, you can use the `--use-vite` option
36
+
37
+ ```shell
38
+ npm create @pplancq/react-app@latest <project_name> -- --use-vite
39
+ ```
40
+
41
+ or
42
+
43
+ ```shell
44
+ npx @pplancq/create-react-app@latest <project_name> --use-vite
45
+ ```
46
+
47
+ or
48
+
49
+ ```shell
50
+ yarn create @pplancq/react-app@latest <project_name> --use-vite
51
+ ```
52
+
53
+ or
54
+
55
+ ```shell
56
+ pnpm create @pplancq/react-app@latest <project_name> --use-vite
57
+ ```
58
+
15
59
  ## Template
16
60
 
17
61
  This package uses the `@pplancq/react-template` to generate a new React project.
package/index.js CHANGED
@@ -4,6 +4,10 @@ const { Command } = require('commander');
4
4
  const { cpSync, existsSync, readFileSync, renameSync, rmSync, writeFileSync, mkdirSync } = require('fs');
5
5
  const { resolve } = require('path');
6
6
 
7
+ const NPM = 'npm';
8
+ const YARN = 'yarn';
9
+ const PNPM = 'pnpm';
10
+
7
11
  const runCommand = (command, options = { stdio: 'inherit' }) => {
8
12
  try {
9
13
  execSync(command, options);
@@ -13,22 +17,49 @@ const runCommand = (command, options = { stdio: 'inherit' }) => {
13
17
  }
14
18
  };
15
19
 
20
+ const getPackageManager = () => {
21
+ switch (true) {
22
+ case process.env.npm_config_user_agent.includes(YARN):
23
+ return YARN;
24
+ case process.env.npm_config_user_agent.includes(PNPM):
25
+ return PNPM;
26
+ default:
27
+ return NPM;
28
+ }
29
+ };
30
+
16
31
  const main = async () => {
17
32
  const chalk = await import('chalk').then(m => m.default);
18
33
 
19
34
  let projectName = '';
35
+ let useVite = false;
20
36
  const packageJson = JSON.parse(readFileSync(resolve(__dirname, './package.json'), { encoding: 'utf-8' }));
21
37
 
22
38
  const cli = new Command(packageJson.name);
23
39
  cli
24
40
  .version(packageJson.version)
25
41
  .argument('<project-name>')
42
+ .option('--use-vite', 'use vite on your application')
26
43
  .usage(chalk.green('<project-name>'))
27
- .action(name => {
44
+ .action((name, options) => {
28
45
  projectName = name;
46
+ useVite = options.useVite ?? false;
29
47
  })
30
48
  .parse(process.argv);
31
49
 
50
+ const packageManager = getPackageManager();
51
+
52
+ if (!/^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(projectName)) {
53
+ console.error(`The project name '${projectName}' is not valid.`);
54
+ console.error(
55
+ 'A valid npm project name must start with a lowercase letter, a number, a hyphen, or a tilde, and can include dots, hyphens, tildes, or underscores.',
56
+ );
57
+ console.error(
58
+ "If the project name starts with '@', it must be followed by a valid scope name and a '/'. Please check and try again.",
59
+ );
60
+ process.exit(-1);
61
+ }
62
+
32
63
  const reactTemplate = '@pplancq/react-template';
33
64
 
34
65
  const repoDir = resolve(process.cwd(), `./${projectName}`);
@@ -44,8 +75,12 @@ const main = async () => {
44
75
 
45
76
  console.info(`\nInstall react template from ${chalk.green(reactTemplate)}`);
46
77
  mkdirSync(repoDir);
47
- runCommand(`cd ${repoDir} && npm install ${reactTemplate}`);
48
- cpSync(templateDir, repoDir, { recursive: true });
78
+ runCommand(`cd ${repoDir} && npm init -y`, { stdio: 'ignore' });
79
+ if (packageManager === YARN) {
80
+ runCommand(`cd ${repoDir} && yarn config set nodeLinker node-modules`, { stdio: 'ignore' });
81
+ }
82
+ runCommand(`cd ${repoDir} && ${packageManager} ${packageManager === YARN ? 'add' : 'install'} ${reactTemplate}`);
83
+ cpSync(templateDir, repoDir, { recursive: true, dereference: true });
49
84
  renameSync(`${repoDir}/_gitignore`, `${repoDir}/.gitignore`);
50
85
  const repoPackageJson = JSON.parse(readFileSync(resolve(repoDir, 'package.json'), { encoding: 'utf-8' }));
51
86
  repoPackageJson.name = projectName;
@@ -60,14 +95,40 @@ const main = async () => {
60
95
 
61
96
  writeFileSync(resolve(repoDir, 'package.json'), JSON.stringify(repoPackageJson, null, 2), { encoding: 'utf-8' });
62
97
  rmSync(`${repoDir}/node_modules`, { recursive: true });
63
- rmSync(`${repoDir}/package-lock.json`);
64
98
  rmSync(`${repoDir}/LICENSE`);
99
+ rmSync(`${repoDir}/CHANGELOG.md`);
100
+ rmSync(`${repoDir}/README.md`);
101
+ renameSync(`${repoDir}/_README.md`, `${repoDir}/README.md`);
102
+
103
+ let readme = readFileSync(resolve(repoDir, 'README.md'), { encoding: 'utf-8' });
104
+ switch (packageManager) {
105
+ case YARN:
106
+ rmSync(`${repoDir}/yarn.lock`);
107
+ readme = readme.replaceAll('npm install', 'yarn');
108
+ readme = readme.replaceAll('npm', 'yarn');
109
+ break;
110
+ case PNPM:
111
+ rmSync(`${repoDir}/pnpm-lock.yaml`);
112
+ readme = readme.replaceAll('npm', 'pnpm');
113
+ break;
114
+ default:
115
+ rmSync(`${repoDir}/package-lock.json`);
116
+ }
117
+ writeFileSync(resolve(repoDir, 'README.md'), readme, { encoding: 'utf-8' });
65
118
 
66
119
  console.info('\nInitialized a git repository.');
67
120
  runCommand(`cd ${repoDir} && git init --initial-branch=main`, { stdio: 'ignore' });
68
121
 
69
122
  console.info('\nInstalling packages. This might take a couple of minutes.');
70
- runCommand(`cd ${repoDir} && npm install`);
123
+ runCommand(`cd ${repoDir} && ${packageManager} install`);
124
+
125
+ if (packageManager === PNPM) {
126
+ runCommand(`cd ${repoDir} && ${packageManager} install -D vite`);
127
+ }
128
+
129
+ if (useVite) {
130
+ runCommand(`cd ${repoDir} && ${packageManager} run migrate:vite`);
131
+ }
71
132
 
72
133
  console.info('\nCreated git commit.');
73
134
  runCommand(`cd ${repoDir} && git add . && git commit --no-verify --message "Initial commit"`, {
@@ -76,15 +137,24 @@ const main = async () => {
76
137
 
77
138
  console.info(`\n${chalk.yellow('Success \\o/')} Created ${chalk.green(projectName)} at ${chalk.green(repoDir)}`);
78
139
  console.info('Inside that directory, you can run several commands:');
79
- console.info(`\n ${chalk.cyan('npm start')}`);
140
+ const logCommand = command => {
141
+ console.info(`\n ${chalk.cyan(command)}`);
142
+ };
143
+ logCommand(`${packageManager} start`);
80
144
  console.info(' Starts the development server.');
81
- console.info(`\n ${chalk.cyan('npm run build')}`);
145
+ logCommand(`${packageManager} run build`);
82
146
  console.info(' Bundles the app into static files for production.');
83
- console.info(`\n ${chalk.cyan('npm test')}`);
147
+ logCommand(`${packageManager} test`);
84
148
  console.info(' Starts the test runner.');
149
+ logCommand(`${packageManager} run remove:demo`);
150
+ console.info(' Remove the demo application.');
151
+ if (!useVite) {
152
+ logCommand(`${packageManager} run migrate:vite`);
153
+ console.info(' Migrate from webpack to vite.');
154
+ }
85
155
  console.info('\nWe suggest that you begin by typing:');
86
156
  console.info(`\n ${chalk.cyan('cd')} ${projectName}`);
87
- console.info(` ${chalk.cyan('npm start')}`);
157
+ logCommand(`${packageManager} start`);
88
158
  console.info('\nHappy hacking!');
89
159
  };
90
160
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pplancq/create-react-app",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "license": "MIT",
5
5
  "description": "pplancq create-react-app",
6
6
  "author": "pplancq <paul.plancq@outlook.fr>",
@@ -20,7 +20,7 @@
20
20
  ],
21
21
  "dependencies": {
22
22
  "chalk": "^5.3.0",
23
- "commander": "^11.1.0"
23
+ "commander": "^12.0.0"
24
24
  },
25
25
  "volta": {
26
26
  "node": "20.10.0",