forked from GeekyAnts/nativebase-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
133 lines (130 loc) · 5.54 KB
/
utils.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
131
132
133
const { spawn } = require('child_process');
const path = require('path');
const { promises: fs } = require("fs");
const expoTemplatePackageJsonVersion = require('./expo-nativebase/package.json').version;
const expoTypeScriptTemplatePackageJsonVersion = require('./expo-nativebase-typescript/package.json').version;
const craTemplatePackageJsonVersion = require('./cra-template-nativebase/package.json').version;
const craTypeScriptTemplatePackageJsonVersion = require('./cra-template-nativebase-typescript/package.json').version;
const reactNativeTemplatePackageJsonVersion = require('./react-native-template-nativebase/package.json').version;
const reactNativeTypeScriptTemplatePackageJsonVersion = require('./react-native-template-nativebase-typescript/package.json').version;
const nextjsTemplatePackageJsonVersion = require('./nextjs-with-native-base/package.json').version;
const nextjsTypeScriptTemplatePackageJsonVersion = require('./nextjs-with-native-base-typescript/package.json').version;
const universalTemplatePackageJsonVersion = require('./universal-app-template-nativebase/package.json');
const universalTypeScriptTemplatePackageJsonVersion = require('./universal-app-template-nativebase-typescript/package.json');
var self = {
templates: [
{
name: "expo-nativebase",
version: expoTemplatePackageJsonVersion,
paths: [path.resolve("expo-nativebase")],
publishable: true,
nested: false
},
{
name: "expo-nativebase-typescript",
version: expoTypeScriptTemplatePackageJsonVersion,
paths: [path.resolve("expo-nativebase-typescript")],
publishable: true,
nested: false
},
{
name: "nextjs-with-native-base",
version: nextjsTemplatePackageJsonVersion,
paths: [path.resolve("nextjs-with-native-base")],
publishable: false,
nested: false
},
{
name: "nextjs-with-native-base-typescript",
version: nextjsTypeScriptTemplatePackageJsonVersion,
paths: [path.resolve("nextjs-with-native-base-typescript")],
publishable: false,
nested: false
},
{
name: "react-native-template-nativebase",
version: reactNativeTemplatePackageJsonVersion,
paths: [path.resolve("react-native-template-nativebase/template")],
publishable: true,
nested: false
},
{
name: "react-native-template-nativebase-typescript",
version: reactNativeTypeScriptTemplatePackageJsonVersion,
paths: [path.resolve("react-native-template-nativebase-typescript/template")],
publishable: true,
nested: false
},
{
name: "cra-template-nativebase",
version: craTemplatePackageJsonVersion,
paths: [path.resolve("cra-template-nativebase")],
publishable: true,
nested: true
},
{
name: "cra-template-nativebase-typescript",
version: craTypeScriptTemplatePackageJsonVersion,
paths: [path.resolve("cra-template-nativebase-typescript")],
publishable: true,
nested: true
},
{
name: "universal-app-template-nativebase",
version: universalTemplatePackageJsonVersion,
paths: [
path.resolve("universal-app-template-nativebase/apps/components"),
path.resolve("universal-app-template-nativebase/apps/mobile"),
path.resolve("universal-app-template-nativebase/apps/web")
],
publishable: false,
nested: true
},
{
name: "universal-app-template-nativebase-typescript",
version: universalTypeScriptTemplatePackageJsonVersion,
paths: [
path.resolve("universal-app-template-nativebase-typescript/apps/components"),
path.resolve("universal-app-template-nativebase-typescript/apps/mobile"),
path.resolve("universal-app-template-nativebase-typescript/apps/web")
],
publishable: false,
nested: true
}
],
executeShellCommand: function (command, msg) {
const child = spawn(command, {
shell: true
});
child.stdout.on("data", function (data) {
console.log(`${data}`);
});
child.stderr.on("data", data => {
console.log(`stderr: ${data} `);
});
child.on("error", error => {
console.log(`error: ${error.message}`);
});
child.on("close", () => {
console.log('\x1b[32m%s\x1b[0m', msg);
});
},
//update native base version in json file by writing the file
updateNBVersionInJsonFile: async function (filePath, templateName, version) {
try {
const fileData = await fs.readFile(filePath, "utf-8");
const data = await JSON.parse(fileData);
if (!self.isUniversalTemplate(templateName))
data.package.dependencies['native-base'] = version;
else
data.dependencies['native-base'] = version;
await fs.writeFile(filePath, JSON.stringify(data, null, 2));
} catch (err) {
console.log(err);
}
},
isUniversalTemplate: function (name) {
return name === "universal-app-template-nativebase" || name === "universal-app-template-nativebase-typescript";
}
}
module.exports = self;