-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.js
130 lines (105 loc) · 4.47 KB
/
init.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
119
120
121
122
123
124
125
126
127
128
129
130
const prompts = require('prompts');
const { execSync } = require("child_process");
const { replaceContents } = require('./utils');
const fs = require('fs');
module.exports = async (path) => {
const { default: ora } = await import('ora');
if (path == '.') {
const currentDirectory = await prompts({
type: 'confirm',
name: 'continue',
message: 'Are you sure you want to initialize a new project in the current directory?',
initial: false
})
if (!currentDirectory.continue) {
return;
}
}
try {
const proc = await execSync('yarn -v')
} catch (error) {
console.log('Kindly install yarn using "npm i -g yarn"');
process.exit(1)
}
path = path == "." || "./" ? path : `./${path}`;
const useExpo = await prompts({
type: 'confirm',
name: 'continue',
message: 'Do you want to use Expo?',
initial: true
})
const installRouter = await prompts({
type: 'confirm',
name: 'continue',
message: 'Do you want to install the Vue Native Router?',
initial: true
})
if (useExpo.continue) {
const installingExpoOra = ora('Initializing Expo Project...').start();
const expoInit = execSync(`expo init ${path}`, {
stdio: 'inherit'
})
installingExpoOra.succeed('Expo Project Initialized');
// expoInit.on('close', code => {
// if (code !== 0) {
// console.log('expo-cli not installed globally. Please install it globally with `npm install -g expo-cli');
// }
// })
} else {
const initializingRN = ora('Initializing React Native Project...').start();
const reactNativeInit = execSync("npx react-native init --version [email protected]", {
stdio: 'ignore'
})
initializingRN.succeed('React Native Project Initialized');
// reactNativeInit.on('close', code => {
// if (code !== 0) {
// console.log('Unexpected error. Please try again.');
// }
// })
}
const initalizingVueNative = ora('Initializing Vue Native in Project...').start();
execSync(`cd ${path} && yarn add vue-native-core vue-native-scripts vue-native-helper`, {
stdio: 'ignore'
})
initalizingVueNative.succeed('Vue Native Initialized');
fs.copyFileSync(`${__dirname}/assets/vueTransformerPlugin.js`, `${path}/vueTransformerPlugin.js`)
if (useExpo.continue) {
fs.copyFileSync(`${__dirname}/assets/metro.config.expo.js`, `${path}/metro.config.js`)
} else {
fs.copyFileSync(`${__dirname}/assets/metro.config.rncli.js`, `${path}/metro.config.js`)
}
if (installRouter.continue) {
const installingVueRouter = ora('Installing Vue Native Router...').start();
const vueRouter = execSync(`cd ${path} && yarn add vue-native-router`, {
stdio: 'ignore'
})
installingVueRouter.succeed('Vue Native Router Installed');
// vueRouter.on('close', code => {
// if (code !== 0) {
// console.log('Unexpected error. Please try again.');
// }
// })
const installingVRDependencies = ora('Installing Vue Native Rotuer Dependencies...').start();
const vueRouterDeps = execSync(`cd ${path} && yarn add react-native-screens react-native-reanimated react-native-paper react-native-gesture-handler`, )
installingVRDependencies.succeed('Vue Native Router Dependencies Installed');
// vueRouterDeps.on('close', code => {
// if (code !== 0) {
// console.log('Unexpected error. Please try again.');
// }
// })
fs.unlinkSync(`${path}/babel.config.js`)
fs.copyFileSync(`${__dirname}/assets/babel.config.js`, `${path}/babel.config.js`)
fs.unlinkSync(`${path}/App.js`)
fs.copyFileSync(`${__dirname}/assets/RouterApp.vue`, `${path}/App.vue`)
var dir = `${path}/screens`;
if (!fs.existsSync(dir)){
fs.mkdirSync(dir);
}
fs.copyFileSync(`${__dirname}/assets/HomeScreen.vue`, `${path}/screens/HomeScreen.vue`)
fs.copyFileSync(`${__dirname}/assets/DetailsScreen.vue`, `${path}/screens/DetailsScreen.vue`)
} else {
fs.unlinkSync(`${path}/App.js`)
fs.copyFileSync(`${__dirname}/assets/App.vue`, `${path}/App.vue`)
}
console.log("Vue Native Project Successfully Initialized!")
}