@momo-kits/foundation 0.92.2 → 0.92.3-tracking.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/code-scanner.js CHANGED
@@ -1,51 +1,143 @@
1
1
  const scanner = require('react-scanner');
2
+ const fs = require('fs');
2
3
  const path = require('path');
3
4
 
4
- const scan = async config => {
5
- return await scanner.run(config);
5
+ const scan = async (config) => {
6
+ return await scanner.run(config);
6
7
  };
7
8
 
8
- const calcSum = array => {
9
- return array.reduce((a, b) => a + b, 0);
9
+ const calcSum = (array) => {
10
+ return array.reduce((a, b) => a + b, 0);
10
11
  };
11
12
 
12
- const calculateAdoptionRate = (kitJsonPath, miniappJsonPath) => {
13
- const kitJson = require(kitJsonPath);
14
- const miniAppJson = require(miniappJsonPath);
15
- const numOfKitComponents = calcSum(Object.values(kitJson));
16
- const numOfMiniAppComponents = calcSum(Object.values(miniAppJson));
17
- const adoptionRate = (numOfKitComponents / numOfMiniAppComponents) * 100;
18
- console.log("Number of kit's components: ", numOfKitComponents);
19
- console.log("Number of miniapp's components: ", numOfMiniAppComponents);
20
- console.log('Adoption rate: ', adoptionRate);
13
+ const calculateAdoptionRate = async (branchName , kitJsonPath , miniappJsonPath , reactNativeJsonPath , fsJsonPath ) => {
14
+ const kitJson = require(kitJsonPath);
15
+ const miniAppJson = require(miniappJsonPath);
16
+ const reactNativeJson = require(reactNativeJsonPath);
17
+ const fsJson = require(fsJsonPath);
18
+
19
+ const numOfKitComponents = calcSum(Object.values(kitJson));
20
+ const numOfMiniAppComponents = calcSum(Object.values(miniAppJson));
21
+ const numOfReactNativeComponents = calcSum(Object.values(reactNativeJson));
22
+ const numOfFSComponents = calcSum(Object.values(fsJson));
23
+
24
+ const adoptionRate = ((numOfKitComponents + numOfReactNativeComponents + numOfFSComponents) / numOfMiniAppComponents) * 100;
25
+
26
+ return {
27
+ miniAppName: branchName,
28
+ numOfKitComponents: numOfKitComponents,
29
+ numOfMiniAppComponents: numOfMiniAppComponents,
30
+ numOfReactNativeComponents: numOfReactNativeComponents,
31
+ numOfFSComponents: numOfFSComponents,
32
+ adoptionRate: adoptionRate.toFixed(2) + '%'
33
+ }
21
34
  };
22
35
 
36
+ function ensureFileExists(filePath , defaultContent = {}) {
37
+ if (!fs.existsSync(filePath)) {
38
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
39
+ fs.writeFileSync(filePath, JSON.stringify(defaultContent, null, 2));
40
+ }
41
+ }
42
+
43
+ const sendMessage = ({
44
+ numOfKitComponents,
45
+ numOfMiniAppComponents,
46
+ numOfFSComponents,
47
+ numOfReactNativeComponents,
48
+ adoptionRate,
49
+ miniAppName = ''
50
+ }) => {
51
+ const url = 'https://chat.googleapis.com/v1/spaces/AAAAL9P6G8M/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=fnwfYuH_u0KicBnKTSSm9S0qV6azJH5v6URm8HR7V2g';
52
+
53
+ const data = {
54
+ text: `MiniApp: ${miniAppName}\nNumber of kit's components: ${numOfKitComponents}\nNumber of miniapp's components: ${numOfMiniAppComponents}\nNumber of FS's components: ${numOfFSComponents}\nNumber of React Native's components: ${numOfReactNativeComponents}\nAdoption rate: ${adoptionRate}`
55
+ };
56
+
57
+ fetch(url, {
58
+ method: 'POST',
59
+ headers: {
60
+ 'Content-Type': 'application/json'
61
+ },
62
+ body: JSON.stringify(data)
63
+ })
64
+ .then(response => response.json())
65
+ .then(data => {
66
+ console.log('Success:', data);
67
+ })
68
+ .catch((error) => {
69
+ console.error('Error:', error);
70
+ });
71
+ }
72
+
23
73
  const main = async () => {
24
- const [scanPath, kitJsonRelativePath, miniappJsonRelativePath] =
25
- process.argv.slice(2);
26
-
27
- const kitJsonPath = path.resolve(process.cwd(), kitJsonRelativePath);
28
- const miniappJsonPath = path.resolve(process.cwd(), miniappJsonRelativePath);
29
-
30
- const config1 = {
31
- crawlFrom: scanPath,
32
- includeSubComponents: true,
33
- importedFrom: /@momo-kits\/.+/,
34
- processors: [['count-components', {outputTo: kitJsonPath}]],
35
- rootDir: './',
36
- };
37
-
38
- const config2 = {
39
- crawlFrom: scanPath,
40
- includeSubComponents: true,
41
- processors: [['count-components', {outputTo: miniappJsonPath}]],
42
- rootDir: './',
43
- };
44
-
45
- await scan(config1);
46
- await scan(config2);
47
-
48
- calculateAdoptionRate(kitJsonPath, miniappJsonPath);
74
+ const rootPath = `${__dirname}/../../../`
75
+ const app = path.join(`${__dirname}/../../../`, 'app.json');
76
+ const appJson = require(app)
77
+ const branchName = appJson.appId
78
+
79
+ if (!branchName || !branchName.includes("vn.momo")){
80
+ return
81
+ }
82
+
83
+ const scanPath = path.join(rootPath, 'src')
84
+ const kitJsonPath = path.join(rootPath, './scan/kit.json')
85
+ const miniappJsonPath = path.join(rootPath, './scan/miniapp.json')
86
+ const reactNativeJsonPath = path.join(rootPath, './scan/RN.json')
87
+ const fsJsonPath = path.join(rootPath, './scan/verLib.json')
88
+
89
+ const allKitsReg = /@momo-kits/;
90
+ const fsReg = /^(?:@fs-mobile-platform\/(components|investment|screens)|@miniapp-platform\/(components|foundation))$/;
91
+ const RNReg = 'react-native'
92
+
93
+ const config1 = {
94
+ crawlFrom: scanPath,
95
+ includeSubComponents: true,
96
+ importedFrom: allKitsReg,
97
+ processors: [['count-components', { outputTo: kitJsonPath }]],
98
+ rootDir: process.cwd(),
99
+ };
100
+
101
+ const config2 = {
102
+ crawlFrom: scanPath,
103
+ includeSubComponents: true,
104
+ processors: [['count-components', { outputTo: miniappJsonPath }]],
105
+ rootDir: process.cwd(),
106
+ };
107
+
108
+ const config3 = {
109
+ crawlFrom: scanPath,
110
+ includeSubComponents: true,
111
+ importedFrom: RNReg,
112
+ processors: [['count-components', { outputTo: reactNativeJsonPath }]],
113
+ rootDir: process.cwd(),
114
+ };
115
+
116
+ const config4 = {
117
+ crawlFrom: scanPath,
118
+ includeSubComponents: true,
119
+ importedFrom: fsReg,
120
+ processors: [['count-components', { outputTo: fsJsonPath }]],
121
+ rootDir: process.cwd(),
122
+ };
123
+
124
+ try {
125
+ ensureFileExists(kitJsonPath, {});
126
+ ensureFileExists(miniappJsonPath, {});
127
+ ensureFileExists(reactNativeJsonPath, {});
128
+ ensureFileExists(fsJsonPath, {});
129
+
130
+ await scan(config1);
131
+ await scan(config2);
132
+ await scan(config3);
133
+ await scan(config4);
134
+
135
+ const result = await calculateAdoptionRate(branchName,kitJsonPath, miniappJsonPath, reactNativeJsonPath, fsJsonPath);
136
+ sendMessage(result)
137
+ console.log(result)
138
+ } catch (error) {
139
+ console.error("Error during scan or calculation:", error);
140
+ }
49
141
  };
50
142
 
51
- main().catch(console.error);
143
+ main();
@@ -0,0 +1,56 @@
1
+ const {readFileSync, writeFileSync, readdirSync, statSync} = require('fs');
2
+ const path = require('path');
3
+ let rootPath = process.argv[2];
4
+
5
+ const migrateText = [
6
+ {typo1: 'headline_s', typo2: 'headline_default_bold'},
7
+ {typo1: 'header_s', typo2: 'header_s_semibold'},
8
+ {typo1: 'header_xs', typo2: 'header_xs_semibold'},
9
+ {typo1: 'description_default', typo2: 'body_default_regular'},
10
+ {typo1: 'description_s', typo2: 'description_default_regular'},
11
+ {typo1: 'description_xs', typo2: 'description_xs_regular'},
12
+ {typo1: 'label_default', typo2: 'label_default_medium'},
13
+ {typo1: 'label_s', typo2: 'label_s_medium'},
14
+ {typo1: 'label_xs', typo2: 'label_xs_medium'},
15
+ {typo1: 'action_default', typo2: 'action_default_bold'},
16
+ {typo1: 'action_xs', typo2: 'action_xs_bold'},
17
+ {typo1: 'action_xxs', typo2: 'action_xxs_bold'},
18
+ ];
19
+
20
+ function replaceTextInFile(oldText, newText, filePath) {
21
+ try {
22
+ let content = readFileSync(filePath, {encoding: 'utf-8'});
23
+ const regex = new RegExp(`\\b${oldText}\\b`, 'g');
24
+ content = content.replace(regex, newText);
25
+ writeFileSync(filePath, content, 'utf8');
26
+ console.log(`Replaced text in: ${filePath}`);
27
+ } catch (error) {
28
+ console.error(`Error processing file ${filePath}:`, error);
29
+ }
30
+ }
31
+
32
+ function scanDirectory(directory, oldText, newText) {
33
+ const files = readdirSync(directory);
34
+
35
+ files.forEach(file => {
36
+ const filePath = path.join(directory, file);
37
+ const stat = statSync(filePath);
38
+
39
+ if (stat.isDirectory()) {
40
+ scanDirectory(filePath, oldText, newText);
41
+ } else if (
42
+ stat.isFile() &&
43
+ (filePath.endsWith('.tsx') || filePath.endsWith('.ts'))
44
+ ) {
45
+ replaceTextInFile(oldText, newText, filePath);
46
+ }
47
+ });
48
+ }
49
+
50
+ function main() {
51
+ migrateText.forEach(({typo1, typo2}) => {
52
+ scanDirectory(rootPath, typo1, typo2);
53
+ });
54
+ }
55
+
56
+ main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.92.2",
3
+ "version": "0.92.3-tracking.10",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {