-
Notifications
You must be signed in to change notification settings - Fork 2
/
standardizeProj.js
96 lines (84 loc) · 2.79 KB
/
standardizeProj.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
// @ts-check
const { readFileSync, writeFileSync, existsSync } = require("fs");
// We always use this GUID to represent the apps project guid
const standardAppProjectGuid = "{UNIQUE00-APP0-GUID-GOES-HERE00000000}";
// We always use this GUID to represent the apps appx guid
const appxApplicationGuid = "{UNIQUE00-APPX-GUID-GOES-HERE00000000}";
const appName = "RnDiffApp";
let projectGuid = "";
function standardizeSolutionFile() {
const slnFilePath = `./${appName}/windows/${appName}.sln`;
const sln = readFileSync(slnFilePath);
const reg = new RegExp(
`Project.*"${appName}", "${appName}\\\\${appName}.(vcxproj|csproj)", "(.*)"`,
"mi"
);
const matches = reg.exec(sln.toString());
projectGuid = matches[2];
if (!projectGuid) {
throw new Error("Failed to find app projects guid");
}
// Replace all the guids with the standard one
writeFileSync(
slnFilePath,
sln.toString().replace(new RegExp(projectGuid, "g"), standardAppProjectGuid)
);
}
function standardizeAppsCppProjectFile() {
let appProjPath = `./${appName}/windows/${appName}/${appName}.vcxproj`;
if (!existsSync(appProjPath)) {
// Try csproj instead
appProjPath = `./${appName}/windows/${appName}/${appName}.csproj`;
if (!existsSync(appProjPath)) {
return;
}
}
const appProj = readFileSync(appProjPath);
writeFileSync(
appProjPath,
appProj
.toString()
.replace(
new RegExp(`<ProjectGuid>.*</ProjectGuid>`),
`<ProjectGuid>${standardAppProjectGuid}</ProjectGuid>`
)
.replace(
new RegExp(
`<PackageCertificateThumbprint>.*</PackageCertificateThumbprint>`
),
"<PackageCertificateThumbprint>UniqueThumbPrintHere</PackageCertificateThumbprint>"
)
);
}
function standardizeAppxManifest() {
const appxManPath = `./${appName}/windows/${appName}/Package.appxmanifest`;
const appxMan = readFileSync(appxManPath);
console.log(appxMan.toString());
writeFileSync(
appxManPath,
appxMan
.toString()
.replace(
new RegExp(
`<mp:PhoneIdentity[\r\n\t ]+PhoneProductId="[^"]*"[\r\n\t ]+PhonePublisherId="[^"]*"`,
"gms"
),
`<mp:PhoneIdentity PhoneProductId="${appxApplicationGuid}" PhonePublisherId="AppSpecificPublisherGuidHere"`
).replace(
new RegExp(
`<Identity[\r\n\t ]+Name="[^"]*"[\r\n\t ]+Publisher="[^"]*"`,
"gms"
),
`<Identity Name="${appxApplicationGuid}" Publisher="AppSpecificPublisherHere"`
).replace(
new RegExp(
`<PublisherDisplayName>.*</PublisherDisplayName>`,
"gms"
),
'<PublisherDisplayName>AppSpecificPublisherNameHere</PublisherDisplayName>'
)
);
}
standardizeSolutionFile();
standardizeAppsCppProjectFile();
standardizeAppxManifest();