-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
change-main-to-class-name-14-0-2.ts
45 lines (42 loc) · 1.12 KB
/
change-main-to-class-name-14-0-2.ts
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
import {
formatFiles,
getProjects,
logger,
names,
stripIndents,
Tree,
} from '@nrwl/devkit';
import { join } from 'path';
/**
* This function changes "main" tag to project's className
*/
export default async function update(tree: Tree) {
const projects = getProjects(tree);
for (const [name, config] of projects.entries()) {
if (config.targets?.start?.executor !== '@nrwl/react-native:start')
continue;
let mailFilePath;
if (tree.exists(join(config.root, 'src/main.tsx'))) {
mailFilePath = join(config.root, 'src/main.tsx');
}
if (tree.exists(join(config.root, 'src/main.js'))) {
mailFilePath = join(config.root, 'src/main.js');
}
if (!mailFilePath) {
continue;
}
try {
const { className } = names(name);
const content = tree.read(mailFilePath, 'utf-8');
if (!content.includes(`'main'`)) {
return;
}
tree.write(mailFilePath, content.replace(`'main'`, `'${className}'`));
} catch {
logger.error(
stripIndents`Unable to update ${mailFilePath} for project ${name}.`
);
}
}
await formatFiles(tree);
}