nx-react-native-cli 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.
Files changed (3) hide show
  1. package/lib/index.js +75 -0
  2. package/package.json +36 -0
  3. package/src/index.js +103 -0
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "nx-react-native-cli",
3
+ "version": "1.0.0",
4
+ "description": "A react native starter (with NX) cli script",
5
+ "main": "./src/index.js",
6
+ "type": "module",
7
+ "files": [
8
+ "lib",
9
+ "package.json"
10
+ ],
11
+ "bin": {
12
+ "nxrn": "./src/index.js"
13
+ },
14
+ "scripts": {
15
+ "start": "./src/index.js",
16
+ "build": "esbuild src/index.js --platform=node --bundle --outdir=lib --minify --analyze",
17
+ "prepublish": "npm run build",
18
+ "relink": "npm unlink nxrn && npm run prepublish && npm link nxrn",
19
+ "test": "echo \"Error: no test specified\" && exit 1"
20
+ },
21
+ "author": {
22
+ "email": "mercadojee@gmail.com",
23
+ "name": "Jee Lorenz Mercado"
24
+ },
25
+ "license": "MIT",
26
+ "dependencies": {
27
+ "chalk": "^5.3.0",
28
+ "commander": "^12.1.0",
29
+ "inquirer": "^10.0.2",
30
+ "ora": "^8.0.1",
31
+ "prettier": "^3.3.3"
32
+ },
33
+ "devDependencies": {
34
+ "esbuild": "^0.23.0"
35
+ }
36
+ }
package/src/index.js ADDED
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env node
2
+
3
+ import chalk from 'chalk';
4
+ import { execSync } from 'child_process';
5
+ import { program } from 'commander';
6
+ import inquirer from 'inquirer';
7
+ import ora from 'ora';
8
+ import {
9
+ addScriptsInRootPackageJson,
10
+ copyDir,
11
+ copyFile,
12
+ executeCommand,
13
+ removeDir,
14
+ } from './utils/index.js';
15
+
16
+ program
17
+ .name('React Native Starter with NX')
18
+ .description('A starter script to create a new React Native project with NX')
19
+ .version('1.0.0');
20
+
21
+ program
22
+ .command('create')
23
+ .description('create nx workspace with react-native')
24
+ .action((options) => {
25
+ const currentPwd = process.cwd();
26
+
27
+ inquirer
28
+ .prompt([
29
+ {
30
+ type: 'input',
31
+ name: 'directory',
32
+ message: 'Enter the directory name to create the project',
33
+ },
34
+ ])
35
+ .then((answers) => {
36
+ const { directory } = answers;
37
+ const workspaceDirectory = `${currentPwd}/${directory}`;
38
+
39
+ console.log(chalk.green(`Creating Nx workspace in ./${directory}!`));
40
+ const spinner1 = ora().start('Creating Nx workspace');
41
+ execSync(`cd ${currentPwd} && npx create-nx-workspace@latest --name ${directory}`, {
42
+ stdio: 'inherit',
43
+ });
44
+ spinner1.succeed('Nx workspace created');
45
+
46
+ const spinner2 = ora().start('Adding React Native');
47
+ executeCommand(workspaceDirectory, `npx nx reset`, {
48
+ stdio: 'inherit',
49
+ });
50
+ executeCommand(workspaceDirectory, `npm i -D @nx/react-native@17.3.0`, {
51
+ stdio: 'inherit',
52
+ });
53
+ executeCommand(workspaceDirectory, `npx nx g @nx/react-native:app apps/mobile --skip-nx-cache`, {
54
+ stdio: 'inherit',
55
+ });
56
+ executeCommand(
57
+ workspaceDirectory,
58
+ `npm install --save-dev react-native-dotenv husky prettier@3.3.2 @typescript-eslint/parser@6.21.0 eslint-config-airbnb-typescript@17.1.0 eslint-plugin-react eslint-plugin-react-hooks eslint-plugin-react-perf eslint-plugin-sonarjs@0.25.1 @tanstack/eslint-plugin-query eslint-plugin-tailwindcss eslint-config-prettier @typescript-eslint/eslint-plugin@6.13.2 eslint-plugin-import eslint-plugin-sort-destructure-keys eslint-plugin-sort-keys-fix eslint-plugin-prettier prettier-plugin-tailwindcss eslint-import-resolver-typescript @swc-node/register@~1.8.0`,
59
+ { stdio: 'inherit' },
60
+ );
61
+ executeCommand(
62
+ workspaceDirectory,
63
+ `npm install tailwindcss twrnc react-native-keyboard-aware-scroll-view react-native-safe-area-context @react-navigation/core @react-navigation/native @react-navigation/native-stack @react-navigation/routers @react-navigation/stack react-native-gesture-handler react-native-screens react-native-reanimated dayjs zustand jotai @tanstack/query-core @tanstack/query-sync-storage-persister @tanstack/react-query @tanstack/react-query-persist-client axios jotai-optics lodash react-hook-form react-native-fast-image react-native-get-random-values react-native-simple-toast react-native-url-polyfill zod zod-validation-error @react-native-async-storage/async-storage @react-native-community/hooks @gorhom/bottom-sheet @hookform/resolvers @react-native-community/datetimepicker @react-navigation/material-top-tabs @tanstack/query-async-storage-persister babel-plugin-module-resolver react-native-dotenv react-native-mmkv react-native-modal-datetime-picker react-native-pager-view react-native-modal react-native-svg-transformer react-native-url-polyfill uuid`,
64
+ { stdio: 'inherit' },
65
+ );
66
+ spinner2.succeed('React Native added');
67
+
68
+ const spinner3 = ora().start('Adding files');
69
+ copyDir(`${workspaceDirectory}/.vscode`, `.vscode`);
70
+ copyDir(`${workspaceDirectory}/.husky`, `.husky`);
71
+ copyFile(`${workspaceDirectory}/.prettierrc`, '.prettierrc');
72
+ copyFile(`${workspaceDirectory}/.prettierignore`, '.prettierignore');
73
+ copyFile(`${workspaceDirectory}/.eslintrc.json`, '.eslintrc.json');
74
+ copyFile(`${workspaceDirectory}/.eslintrc.json`, '.eslintrc.json');
75
+ copyFile(`${workspaceDirectory}/.gitignore`, '.gitignore');
76
+ copyFile(`${workspaceDirectory}/.ruby-version`, '.ruby-version');
77
+ copyFile(`${workspaceDirectory}/.nvmrc`, '.nvmrc');
78
+ copyFile(`${workspaceDirectory}/check-env.sh`, `check-env.sh`);
79
+ copyFile(`${workspaceDirectory}/clean-generated-outputs.sh`, `clean-generated-outputs.sh`);
80
+ removeDir(`${workspaceDirectory}/apps/mobile/src`);
81
+ copyDir(`${workspaceDirectory}/apps`, `apps`);
82
+ executeCommand(workspaceDirectory, `keytool -genkey -keystore ${workspaceDirectory}/apps/mobile/android/app/dev.keystore -keyalg RSA -keysize 2048 -validity 10000 -alias dev -dname "cn=Unknown, ou=Unknown, o=Unknown, c=Unknown" -storepass development -keypass development`, {
83
+ stdio: 'inherit',
84
+ });
85
+ addScriptsInRootPackageJson(workspaceDirectory);
86
+ spinner3.succeed('Files added');
87
+
88
+ console.log(chalk.green('Project created successfully!'));
89
+ console.log(
90
+ chalk.blue(
91
+ 'Next Steps? Rename your app using https://www.npmjs.com/package/react-native-rename',
92
+ ),
93
+ );
94
+ console.log(
95
+ chalk.blue(
96
+ "Don't forget to wide search for 'AppsMobile' and replace it with your app name",
97
+ ),
98
+ );
99
+ console.log(chalk.blue('Run `npm run serve:mobile` to start the project! Happy coding!'));
100
+ });
101
+ });
102
+
103
+ program.parse(process.argv);