@pplancq/create-react-app 1.0.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 ADDED
@@ -0,0 +1,6 @@
1
+ ## @pplancq/create-react-app 1.0.0 (2024-02-05)
2
+
3
+
4
+ ### Features
5
+
6
+ * **create-react-app:** add create-react-app script ([6ac21f7](https://github.com/pplancq/dev-tools/commit/6ac21f7e8148822a31b61fb618a5dfccedf20a3c))
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present pplancq
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # @pplancq/create-react-app
2
+
3
+ This package includes a script that allows you to generate a new React project using the `@pplancq/react-template`.
4
+
5
+ ## Usage
6
+
7
+ To create a new React project with this package, use the following command:
8
+
9
+ ```shell
10
+ npm create @pplancq/react-app@latest <project_name>
11
+ ```
12
+
13
+ Replace <project_name> with the name of your new project.
14
+
15
+ ## Template
16
+
17
+ This package uses the `@pplancq/react-template` to generate a new React project.
18
+ For more information about this template, please consult its documentation.
19
+
20
+ ## License
21
+
22
+ This project is under the MIT license.
package/index.js ADDED
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env node
2
+ const { execSync } = require('child_process');
3
+ const { Command } = require('commander');
4
+ const { cpSync, existsSync, readFileSync, renameSync, rmSync, writeFileSync, mkdirSync } = require('fs');
5
+ const { resolve } = require('path');
6
+
7
+ const runCommand = (command, options = { stdio: 'inherit' }) => {
8
+ try {
9
+ execSync(command, options);
10
+ } catch (e) {
11
+ console.error(`Failed to execute ${command}`, e);
12
+ process.exit(-1);
13
+ }
14
+ };
15
+
16
+ const main = async () => {
17
+ const chalk = await import('chalk').then(m => m.default);
18
+
19
+ let projectName = '';
20
+ const packageJson = JSON.parse(readFileSync(resolve(__dirname, './package.json'), { encoding: 'utf-8' }));
21
+
22
+ const cli = new Command(packageJson.name);
23
+ cli
24
+ .version(packageJson.version)
25
+ .argument('<project-name>')
26
+ .usage(chalk.green('<project-name>'))
27
+ .action(name => {
28
+ projectName = name;
29
+ })
30
+ .parse(process.argv);
31
+
32
+ const reactTemplate = '@pplancq/react-template';
33
+
34
+ const repoDir = resolve(process.cwd(), `./${projectName}`);
35
+ const templateDir = resolve(repoDir, `./node_modules/${reactTemplate}`);
36
+
37
+ if (existsSync(repoDir)) {
38
+ console.error(`\nThe directory ${chalk.green(projectName)} is already exist.`);
39
+ console.error('Either try using a new directory name, or remove the files listed above.');
40
+ process.exit(-1);
41
+ }
42
+
43
+ console.info(`\nCreating a new App React in ${chalk.green(repoDir)}.`);
44
+
45
+ console.info(`\nInstall react template from ${chalk.green(reactTemplate)}`);
46
+ mkdirSync(repoDir);
47
+ runCommand(`cd ${repoDir} && npm install ${reactTemplate}`);
48
+ cpSync(templateDir, repoDir, { recursive: true });
49
+ renameSync(`${repoDir}/_gitignore`, `${repoDir}/.gitignore`);
50
+ const repoPackageJson = JSON.parse(readFileSync(resolve(repoDir, 'package.json'), { encoding: 'utf-8' }));
51
+ repoPackageJson.name = projectName;
52
+ repoPackageJson.description = projectName;
53
+ const { _prepare, ...scripts } = repoPackageJson.scripts;
54
+ repoPackageJson.scripts = { ...scripts, prepare: _prepare };
55
+
56
+ delete repoPackageJson.author;
57
+ delete repoPackageJson.repository;
58
+ delete repoPackageJson.bugs;
59
+ delete repoPackageJson.keywords;
60
+
61
+ writeFileSync(resolve(repoDir, 'package.json'), JSON.stringify(repoPackageJson, null, 2), { encoding: 'utf-8' });
62
+ rmSync(`${repoDir}/node_modules`, { recursive: true });
63
+ rmSync(`${repoDir}/package-lock.json`);
64
+ rmSync(`${repoDir}/LICENSE`);
65
+
66
+ console.info('\nInitialized a git repository.');
67
+ runCommand(`cd ${repoDir} && git init --initial-branch=main`, { stdio: 'ignore' });
68
+
69
+ console.info('\nInstalling packages. This might take a couple of minutes.');
70
+ runCommand(`cd ${repoDir} && npm install`);
71
+
72
+ console.info('\nCreated git commit.');
73
+ runCommand(`cd ${repoDir} && git add . && git commit --no-verify --message "Initial commit"`, {
74
+ stdio: 'ignore',
75
+ });
76
+
77
+ console.info(`\n${chalk.yellow('Success \\o/')} Created ${chalk.green(projectName)} at ${chalk.green(repoDir)}`);
78
+ console.info('Inside that directory, you can run several commands:');
79
+ console.info(`\n ${chalk.cyan('npm start')}`);
80
+ console.info(' Starts the development server.');
81
+ console.info(`\n ${chalk.cyan('npm run build')}`);
82
+ console.info(' Bundles the app into static files for production.');
83
+ console.info(`\n ${chalk.cyan('npm test')}`);
84
+ console.info(' Starts the test runner.');
85
+ console.info('\nWe suggest that you begin by typing:');
86
+ console.info(`\n ${chalk.cyan('cd')} ${projectName}`);
87
+ console.info(` ${chalk.cyan('npm start')}`);
88
+ console.info('\nHappy hacking!');
89
+ };
90
+
91
+ main();
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@pplancq/create-react-app",
3
+ "version": "1.0.0",
4
+ "license": "MIT",
5
+ "description": "pplancq create-react-app",
6
+ "author": "pplancq <paul.plancq@outlook.fr>",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/pplancq/dev-tools",
10
+ "directory": "packages/create-react-app"
11
+ },
12
+ "bin": "./index.js",
13
+ "bugs": {
14
+ "url": "https://github.com/pplancq/dev-tools/issues"
15
+ },
16
+ "main": "index.js",
17
+ "keywords": [
18
+ "create",
19
+ "react"
20
+ ],
21
+ "dependencies": {
22
+ "chalk": "^5.3.0",
23
+ "commander": "^11.1.0"
24
+ },
25
+ "volta": {
26
+ "node": "20.10.0",
27
+ "npm": "10.2.5"
28
+ }
29
+ }