forked from invertase/react-native-firebase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-firebase-module.js
More file actions
123 lines (115 loc) · 4.52 KB
/
create-firebase-module.js
File metadata and controls
123 lines (115 loc) · 4.52 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
/*
* Copyright (c) 2016-present Invertase Limited & Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this library except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
const { join, resolve } = require('path');
const { readdirSync, renameSync, statSync } = require('fs');
const shelljs = require('shelljs');
const inquirer = require('inquirer');
const { version } = require('./../lerna');
function walkDir(dir) {
let results = [];
const list = readdirSync(dir);
list.forEach(function (file) {
file = dir + '/' + file;
const stat = statSync(file);
if (stat && stat.isDirectory()) {
results = results.concat(walkDir(file));
} else {
results.push(file);
}
});
return results;
}
inquirer
.prompt([
{
type: 'input',
name: 'name',
message: 'What is the name of this module, e.g. analytics:',
default: 'iid',
},
])
.then(answers => {
const { name } = answers;
const packageDir = `packages/${name}`;
const nameUpper = name.charAt(0).toUpperCase() + name.slice(1);
shelljs.cp('-R', 'scripts/_TEMPLATE_', packageDir);
shelljs.exec(
`find ./${packageDir}/ -type f -exec sed -i '' -e "s/_template_/${name}/g" {} \\;`,
);
shelljs.exec(
`find ./${packageDir}/ -type f -exec sed -i '' -e "s/_Template_/${nameUpper}/g" {} \\;`,
);
shelljs.exec(
`find ./${packageDir}/package.json -type f -exec sed -i '' -e "s/_VERSION_/${version}/g" {} \\;`,
);
return Promise.resolve({ name, nameUpper });
})
.then(({ name, nameUpper }) => {
const dir = resolve(`./packages/${name}/`);
const templateFiles = walkDir(dir).filter(file => {
return file.includes('_template_') || file.includes('_Template_');
});
shelljs.mv(`${dir}/ios/RNFB_Template_`, `${dir}/ios/RNFB${nameUpper}`);
shelljs.mv(`${dir}/ios/RNFB_Template_.xcodeproj`, `${dir}/ios/RNFB${nameUpper}.xcodeproj`);
shelljs.mv(
`${dir}/android/src/main/java/io/invertase/firebase/_template_`,
`${dir}/android/src/main/java/io/invertase/firebase/${name}`,
);
for (let i = 0; i < templateFiles.length; i++) {
const templateFile = templateFiles[i]
.replace(
`${dir}/android/src/main/java/io/invertase/firebase/_template_`,
`${dir}/android/src/main/java/io/invertase/firebase/${name}`,
)
.replace(`${dir}/ios/RNFB_Template_/`, `${dir}/ios/RNFB${nameUpper}/`)
.replace(`${dir}/ios/RNFB_Template_.x`, `${dir}/ios/RNFB${nameUpper}.x`);
const newTemplateFilePath = templateFile
.replace(/_template_/g, name)
.replace(/_Template_/g, nameUpper);
renameSync(templateFile, newTemplateFilePath);
}
return Promise.resolve({ name, nameUpper });
})
.then(({ name, nameUpper }) => {
shelljs.exec(`lerna add @react-native-firebase/${name} tests && yarn`);
console.log('');
console.log(`The module '${name}' (${nameUpper}) has been created!`);
console.log('');
console.log('');
console.log('1) ADD IT TO `KNOWN_NAMESPACES` in packages/app/lib/internal/constants.js');
console.log('');
console.log('2) ADD IT TO THE docs:');
console.log(' - in docs/<modulename>/index.md and usage/index.md');
console.log(
' - in docs/<modules>/... find the prev next links where you slice in and fix them',
);
console.log(' - in docs/app/usage.md list of apps that are multi-app, if it is multi-app');
console.log(' - in docs/sidebar.yaml');
console.log(' - in website/scripts/source-reference.js');
console.log(' - in website/src/templates/utils.ts');
console.log('');
console.log('3) If the name has hyphens, carefully check:');
console.log(' - package namespaces in java and package.json and index.d.ts');
console.log(' - the @firebase tag in index.d.ts (creates docs site reference API links)');
console.log('');
console.log('4) Add the e2e tests:');
console.log(' - tests/e2e/.mocharc.js');
console.log(' - tests/package.json (and run yarn + yarn tests:pod:install)');
console.log(' - tests/app.js');
console.log('');
})
.catch(console.error);