-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathcli.js
executable file
·118 lines (101 loc) · 3.41 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env node
const chalk = require('chalk');
const commander = require('commander');
// const fs = require('fs-extra');
// const path = require('path');
const execSync = require('child_process').execSync;
const packageJson = require('./package.json');
// const copyFiles = require('./copyFiles');
const nodeVersion = process.versions.node;
const nodeVersionSplitted = nodeVersion.split('.');
const nodeMajorVersion = nodeVersionSplitted[0];
if (nodeMajorVersion < 8) {
console.error(
chalk.red(`
You are running Node ${nodeVersion}
Create React Native Web App requires Node 8 or higher.
Please update your version of Node.
`),
);
process.exit(1);
}
const printCyan = (text) => console.log(` ${chalk.cyan(text)}`);
// const printGreen = (text) => console.log(` ${chalk.green(text)}`);
let appName;
const program = new commander.Command(packageJson.name)
.version(packageJson.version)
.arguments('<project-directory>')
.option('-r, --router')
.usage(`${chalk.green('<project-directory>')}`)
.action((name) => {
appName = name;
})
.on('--help', () => {
console.log(` ${chalk.green('<project-directory>')} is required.`);
console.log();
console.log(
` If you have any problems, do not hesitate to file an issue:`,
);
printCyan(
'https://github.com/orYoffe/create-react-native-web-app/issues/new',
);
console.log();
})
.parse(process.argv);
async function run() {
if (appName) {
printCyan(`⏳ Creating React Native Web App by the name of ${appName}`);
console.log();
execSync(
`npx react-native init ${appName} --template react-native-template-react-native-web`,
{stdio: [0, 1, 2]},
);
let isYarnAvailable;
try {
execSync('yarnpkg --version', {stdio: 'ignore'});
isYarnAvailable = true;
} catch (e) {
isYarnAvailable = false;
}
try {
execSync(`cd ${appName} && git init`);
} catch (error) {}
const packageManagerRunCommand = isYarnAvailable ? 'yarn' : 'npm run';
console.log(`
${chalk.magenta('*')} ${chalk.magenta(
'change directory to your new project',
)}
$ ${chalk.cyan(`cd ${appName}`)}
$ ${chalk.cyan('Then run the these commands to get started:')}
${chalk.magenta('*')} ${chalk.magenta('To run development Web server')}
$ ${chalk.cyan(packageManagerRunCommand + ' web')}
${chalk.magenta('*')} ${chalk.magenta(
'To run Android on connected device (after installing Android Debug Bridge "adb" - https://developer.android.com/studio/releases/platform-tools)',
)}
$ ${chalk.cyan(packageManagerRunCommand + ' android')}
${chalk.magenta('*')} ${chalk.magenta(
'To run ios simulator (after installing Xcode - only on Apple devices)',
)}
$ ${chalk.cyan(packageManagerRunCommand + ' ios')}
${chalk.magenta('*')} ${chalk.magenta(
'To run tests for Native and Web',
)}
$ ${chalk.cyan(packageManagerRunCommand + ' test')}
${chalk.magenta('*')} ${chalk.magenta('To run build for Web')}
$ ${chalk.cyan(packageManagerRunCommand + ' build')}
`);
} else {
console.error(
chalk.red(
'In order to create a new project you must give a name as an argument. ',
),
chalk.cyan('Example: create-react-native-web-app AppName'),
);
process.exit(1);
}
}
try {
run();
} catch (error) {
console.error(error);
}