-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGulpfile.js
More file actions
137 lines (105 loc) · 3.64 KB
/
Copy pathGulpfile.js
File metadata and controls
137 lines (105 loc) · 3.64 KB
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
131
132
133
134
135
136
137
/* eslint-disable */
const fs = require('fs-extra');
const {
parallel, series, src, dest,
} = require('gulp');
const { argv } = require('yargs');
const { exec } = require('child_process');
require('dotenv').config({ path: 'config/.env' });
console.log('APP_PIN : ', process.env.APP_PIN);
const tenant = argv.tenant || 'main';
const platform = argv.platform || 'ios';
const sourceIosIcons = `./tenant_config/${tenant}/ios/AppIcon.appiconset/**/*`;
const destinationIosIcons = './ios/RNWhiteLabel/Images.xcassets/AppIcon.appiconset';
const sourceIosSplash = `./tenant_config/${tenant}/ios/LaunchImage.launchimage/*`;
const destinationIosSplash = './ios/RNWhiteLabel/Images.xcassets/LaunchImage.launchimage';
const sourceAndroid = `./tenant_config/${tenant}/android/res/**/*`;
const destinationAndroid = './android/app/src/main/res/';
const sourceAndroidManifest = `./tenant_config/${tenant}/android/src/main/AndroidManifest.xml`;
const destinationAndroidManifest = './android/app/src/main/';
const sourceEnvFiles = `./tenant_config/${tenant}/config/*`;
const destinationEnvFiles = './config';
/**
* *************************************
* IOS
**************************************
*/
const cleanIosFiles = () => {
fs.removeSync(destinationIosIcons);
fs.removeSync(destinationIosSplash);
return Promise.resolve('Clean ok');
};
const copyIosIcons = () => {
fs.ensureDirSync(destinationIosIcons);
return src(sourceIosIcons)
.pipe(dest(destinationIosIcons));
};
const copyIosSplashscreen = () => {
fs.ensureDirSync(destinationIosSplash);
return src(sourceIosSplash)
.pipe(dest(destinationIosSplash));
};
const copyIosFiles = series(copyIosIcons, copyIosSplashscreen);
const switchIosFiles = series(cleanIosFiles, copyIosFiles);
/**
* *************************************
* ANDROID
**************************************
*/
const cleanAndroidFiles = () => {
fs.removeSync(destinationAndroid);
return Promise.resolve('Clean ok');
};
const copyAndroidFiles = () => {
fs.ensureDirSync(destinationAndroid);
if (fs.existsSync(sourceAndroidManifest)) {
src(sourceAndroidManifest)
.pipe(dest(destinationAndroidManifest, { overwrite: true }));
}
return src(sourceAndroid)
.pipe(dest(destinationAndroid));
};
const switchAndroidFiles = series(cleanAndroidFiles, copyAndroidFiles);
/**
* *************************************
* CONFIG (ENV files)
**************************************
*/
const cleanEnvFiles = () => {
console.log('Switching ', platform, 'to ', tenant);
fs.removeSync(destinationEnvFiles);
return Promise.resolve('Clean ok');
};
const copyEnvFiles = () => {
fs.ensureDirSync(destinationEnvFiles);
return src(sourceEnvFiles, { dot: true })
.pipe(dest(destinationEnvFiles));
};
const switchEnvFiles = series(cleanEnvFiles, copyEnvFiles);
/**
* *************************************
* Scripts
**************************************
*/
exports.startApp = () => {
console.log('RUN ', `RN_SRC_EXT=${process.env.APP_PIN}.js node node_modules/react-native/local-cli/cli.js start --reset-cache`);
const startCmd = exec(`RN_SRC_EXT=${process.env.APP_PIN}.js node node_modules/react-native/local-cli/cli.js start --reset-cache`);
return startCmd.stdout.pipe(process.stdout);
};
/**
* *************************************
* EXPORTS
**************************************
*/
if (platform === 'android') {
exports.switchTenant = series(switchAndroidFiles, switchEnvFiles);
exports.cleanFiles = cleanAndroidFiles;
} else {
exports.switchTenant = series(switchIosFiles, switchEnvFiles);
exports.cleanFiles = cleanIosFiles;
}
exports.default = series(
switchEnvFiles,
switchAndroidFiles,
switchIosFiles,
);