This repository has been archived by the owner on Jan 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Gulpfile.js
202 lines (169 loc) · 6.71 KB
/
Gulpfile.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import cp from 'child_process';
import path from 'path';
import fs from 'fs';
import gulp from 'gulp';
import os from 'os';
import url from 'url';
import plist from 'plist';
import glob from 'glob';
const rootDirPath = path.dirname(url.fileURLToPath(import.meta.url));
/**
* @param {string} cmd
* @param {string?} cwd
*/
function _run(cmd, cwd) {
console.log('ℹ️ ' + cmd);
cp.execSync(cmd, { stdio: 'inherit', cwd: cwd ?? rootDirPath });
}
//~~~
class Version {
#versionNumberKey = 'APP_PROJECT_VERSION';
#buildNumberKey = 'APP_BUNDLE_VERSION';
#filePath;
#lines;
constructor(filePath) {
this.#filePath = filePath;
this.#lines = fs.readFileSync(filePath).toString().trim().split('\n');
}
get version() {
const line = this.#lines.filter((item) => item.startsWith(this.#versionNumberKey))[0];
const value = line.split('=')[1].trim();
return value;
}
get build() {
const line = this.#lines.filter((item) => item.startsWith(this.#buildNumberKey))[0];
const value = line.split('=')[1].trim();
return parseInt(value);
}
bump() {
const latestTag = cp.execSync('git describe --tags --abbrev=0').toString().trim();
const components = latestTag.split('.');
const last = parseInt(components[components.length - 1]);
components[components.length - 1] = last + 1;
const newTag = components.join('.');
if (newTag === this.version) {
console.log('Nothing to do. Skipping.');
return;
}
const newBuild = this.build + 1;
this.#lines = [`${this.#versionNumberKey} = ${newTag}`, `${this.#buildNumberKey} = ${newBuild}`];
const contents = this.#lines.join('\n') + '\n';
fs.writeFileSync(this.#filePath, contents);
}
}
//~~~
const v = new Version(path.join(rootDirPath, 'Configuration/Version.xcconfig'));
const appName = 'VST3NetSend';
const xcArchiveFileName = `${appName}-${v.version}x${v.build}.xcarchive`;
const xcArchiveFilePath = path.join(process.env.MCA_XC_ARCHIVES, xcArchiveFileName);
const zipArchiveFileName = `${appName}_v${v.version}.zip`;
const appFileName = `${appName}.vst3`;
const installedAppFilePath = path.join(process.env.HOME, 'Library/Audio/Plug-Ins/VST3/Development/VST3NetSend.vst3');
const notarizationFilePath = path.join(rootDirPath, 'build', zipArchiveFileName);
function archive() {
const buildDirPath = fs.mkdtempSync(path.join(os.tmpdir(), `${appName}-archive-`));
const archiveFilePath = path.join(buildDirPath, 'Build', xcArchiveFileName);
if (fs.existsSync(xcArchiveFilePath)) {
throw `Archive already exists at path "${xcArchiveFilePath}".`;
}
const args = `-arch x86_64 -arch arm64 ONLY_ACTIVE_ARCH=NO DEVELOPMENT_TEAM=H3M62US4J7 CODE_SIGN_IDENTITY="Developer ID Application"`;
_run(`xcodebuild -project VST3NetSend.xcodeproj -scheme VST3NetSend -archivePath ${archiveFilePath} ${args} archive`);
const productPath = 'Products/Library/Audio/Plug-Ins/VST3/Development';
_run(`zip -9 -q --symlinks -r ${zipArchiveFileName} ${appFileName}`, path.join(archiveFilePath, productPath));
const newFilePath = path.join(archiveFilePath, productPath, appFileName);
const exportedFilePath = path.join(archiveFilePath, productPath, zipArchiveFileName);
_run(`ditto ${exportedFilePath} ${notarizationFilePath}`);
_run(`ditto ${newFilePath} ${installedAppFilePath}`);
_run(`ditto ${archiveFilePath} ${xcArchiveFilePath}`);
fs.rmdirSync(buildDirPath, { recursive: true, force: true });
}
function cleanArchive() {
const filesToRemove = [xcArchiveFilePath, installedAppFilePath, notarizationFilePath];
for (const file of filesToRemove) {
console.log(`Will remove file: ${file}`);
fs.rmdirSync(file, { recursive: true, force: true });
}
}
function notarizationSubmit() {
// See: https://developer.apple.com/documentation/security/notarizing_macos_software_before_distribution/customizing_the_notarization_workflow/notarizing_apps_when_developing_with_xcode_12_and_earlier
const cmd = `xcrun altool --notarize-app --primary-bundle-id "com.microcodingapps.oss.VST3NetSend" -u ${process.env.MCA_XC_DEV_ID_OSS} -p "@keychain:mca-notarization" --file ${notarizationFilePath}`;
_run(cmd);
}
function notarizationHistory() {
const cmd = `xcrun altool --notarization-history 0 -u ${process.env.MCA_XC_DEV_ID_OSS} -p "@keychain:mca-notarization"`;
_run(cmd);
}
function makeStandalone() {
const projectPath = `${rootDirPath}/Shared.xcodeproj/project.pbxproj`;
const vendorDirPath = `${rootDirPath}/Vendor`;
const vendorPath = `${vendorDirPath}/mc`;
const regex = /mc-shared\/\w+\/Sources/g;
const contents = fs.readFileSync(projectPath).toString();
const matches = contents.match(regex);
if (matches == undefined) {
console.log('➔ Nothing to do!');
return;
}
if (fs.existsSync(vendorPath)) {
fs.rmdirSync(vendorPath, { recursive: true, force: true });
}
fs.mkdirSync(vendorPath, { recursive: true });
for (const match of matches) {
const from = `${vendorDirPath}/${match}`;
const to = vendorPath + match.replace('mc-shared', '');
const swiftFiles = glob.sync(`${from}/**/*.swift`);
for (const file of swiftFiles) {
const contents = fs.readFileSync(file).toString();
if (contents.includes('MCA-OSS-VSTNS')) {
const dstName = path.join(to, file.replace(from, ''));
const dstDir = path.dirname(dstName);
fs.mkdirSync(dstDir, { recursive: true });
// console.log(`➔ Copying '${file}' to '${dstName}'`);
fs.copyFileSync(file, dstName);
}
}
const fromSpec = from.replace('/Sources', '/project.yml');
const toSpec = to.replace('/Sources', '/project.yml');
fs.copyFileSync(fromSpec, toSpec);
}
fs.copyFileSync(`${vendorDirPath}/mc-shared/templates.yml`, `${vendorPath}/templates.yml`);
}
//~~~
gulp.task('default', (cb) => {
console.log('✅ Available tasks:');
cp.execSync('gulp -T', { stdio: 'inherit' });
cb();
});
gulp.task('note-subm', (cb) => {
notarizationSubmit();
cb();
});
gulp.task('note-hist', (cb) => {
notarizationHistory();
cb();
});
gulp.task('st', (cb) => {
_run(`xcodegen --spec project-shared.yml`);
makeStandalone();
_run(`xcodegen --spec project.yml`);
cb();
});
gulp.task('gen', (cb) => {
_run(`xcodegen --spec project-shared.yml`);
cb();
});
gulp.task('arch-build', (cb) => {
archive(false);
cb();
});
gulp.task('arch-clean', (cb) => {
cleanArchive(false);
cb();
});
gulp.task('finish', (cb) => {
const buildNum = v.version;
console.log(`Creating tag: "${buildNum}"`);
cp.execSync(`git tag "${buildNum}"`, { stdio: 'inherit' });
cp.execSync(`git push origin "${buildNum}"`, { stdio: 'inherit' });
cb();
});