-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpkg.ts
More file actions
74 lines (61 loc) · 2.46 KB
/
Copy pathpkg.ts
File metadata and controls
74 lines (61 loc) · 2.46 KB
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
import chalk from 'chalk'
import { execSync } from 'node:child_process'
import fs from 'node:fs/promises'
import path from 'node:path';
// Create .build folder if it does not exist
try {
await fs.mkdir('./.build')
} catch (err) {}
console.log(chalk.magenta('Removing everything in ./.build except tmp'))
await fs.readdir('./.build')
.then((files) =>
Promise.all(
files.map(file => file === 'tmp'
? undefined
: fs.rm(`./.build/${file}`, { recursive: true })
)
)
);
console.log(chalk.magenta('Copying files to ./.build'))
await Promise.all([
fs.cp('package.json', './.build/package.json'),
fs.cp('package-lock.json', './.build/package-lock.json'),
fs.cp('./bin', './.build/bin/', { recursive: true }),
fs.cp('README.md', './.build/README.md'),
]);
console.log(chalk.magenta('Esbuild src'))
execSync('tsx esbuild.ts', { shell: 'zsh' })
console.log(chalk.magenta('Install production dependencies'))
execSync('npm install --production', { cwd: './.build', shell: 'zsh' })
console.log(chalk.magenta('Running oclif pkg macos'))
execSync('oclif pack macos -r .', { cwd: './.build', shell: 'zsh' });
await patchMacOsInstallers()
console.log(chalk.magenta('Running oclif pkg tarballs'))
execSync('oclif pack tarballs -r . -t darwin-arm64,darwin-x64,linux-x64,linux-arm64', { cwd: './.build', shell: 'zsh' })
console.log(chalk.magenta('Copying files back'))
await Promise.all([
ignoreError(() => fs.rename('./.build/README.md', './README.md')),
]);
async function ignoreError(fn: () => Promise<any> | any): Promise<void> {
try {
await fn();
} catch (e) {
}
}
// Oclif has a bug where the installer doesn't clear out the auto-updater location. This causes older versions
// to be re-used even with a clean install
async function patchMacOsInstallers() {
console.log(chalk.magenta('Patching MacOS installers with bug fix'))
const pkgFolder = './.build/dist/macos';
const files = await fs.readdir(pkgFolder)
const pkgFiles = files.filter((name) => name.endsWith('.pkg'))
for (const pkgFile of pkgFiles) {
const pkgPath = path.join(pkgFolder, pkgFile);
const tmpPath = path.join(pkgFolder, 'tmp');
execSync(`pkgutil --expand ${pkgPath} ${tmpPath}`)
await fs.appendFile(path.join(tmpPath, 'Scripts', 'preinstall'), '\nsudo rm -rf ~/.local/share/codify', 'utf8');
execSync(`pkgutil --flatten ${tmpPath} ${pkgPath} `)
execSync(`rm -rf ${tmpPath}`);
console.log(chalk.magenta(`Done patching installer ${pkgFile}`))
}
}