-
-
Notifications
You must be signed in to change notification settings - Fork 216
/
Copy pathreleasePackagesRename.js
79 lines (65 loc) · 2.64 KB
/
releasePackagesRename.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
import { rename, access, mkdir } from 'fs/promises';
import packageJson from '../package.json';
import path from 'path';
import simpleGit from 'simple-git';
const git = simpleGit({ baseDir: process.cwd() });
async function fileExists(checkPath) {
try {
await access(checkPath);
return true;
} catch (e) {
return false;
}
}
async function checkAndRenameFile(generatedPath, newPath) {
if (await fileExists(generatedPath)) {
await rename(generatedPath, newPath);
}
}
async function createDirectory(directoryPath) {
const exists = await fileExists(directoryPath);
if (!exists) {
await mkdir(directoryPath);
}
}
async function renameDeb({ version, name, sha }) {
const dist = 'dist/deb';
// deb package naming convention: https://github.com/oclif/oclif/blob/fb5da961f925fa0eba5c5b05c8cee0c9bd156c00/src/upload-util.ts#L51
const generatedPath = path.resolve(dist, `${name}_${version}.${sha}-1_amd64.deb`);
const newPath = path.resolve(dist, 'asyncapi.deb');
await checkAndRenameFile(generatedPath, newPath);
}
async function renameTar({ version, name, sha }) {
const dist = 'dist';
const generatedPath = path.resolve(dist, `${name}-v${version}-${sha}-linux-x64.tar.gz`);
// for tarballs, the files are generated in `dist/` directory.
// Creates a new `tar` directory(`dist/tar`), and moves the generated tarball inside that directory.
const tarDirectory = path.resolve(dist, 'tar');
await createDirectory(tarDirectory);
const newPath = path.resolve(tarDirectory, 'asyncapi.tar.gz');
await checkAndRenameFile(generatedPath, newPath);
}
async function renameWindows({ version, name, sha, arch }) {
const dist = 'dist/win32';
const generatedPath = path.resolve(dist, `${name}-v${version}-${sha}-${arch}.exe`);
const newPath = path.resolve(dist, `asyncapi.${arch}.exe`);
await checkAndRenameFile(generatedPath, newPath);
}
async function renamePkg({ version, name, sha, arch }) {
const dist = 'dist/macos';
const generatedPath = path.resolve(dist, `${name}-v${version}-${sha}-${arch}.pkg`);
const newPath = path.resolve(dist, `asyncapi.${arch}.pkg`);
await checkAndRenameFile(generatedPath, newPath);
}
async function renamePackages() {
const version = packageJson.version;
const name = 'asyncapi';
const sha = await git.revparse(['--short', 'HEAD']);
await renameDeb({ version: version.split('-')[0], name, sha });
await renamePkg({ version, name, sha, arch: 'x64' });
await renamePkg({ version, name, sha, arch: 'arm64' });
await renameWindows({ version, name, sha, arch: 'x64' });
await renameWindows({ version, name, sha, arch: 'x86' });
await renameTar({ version, name, sha });
}
renamePackages();