-
Notifications
You must be signed in to change notification settings - Fork 1
/
push.js
134 lines (104 loc) · 3.31 KB
/
push.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
const fs = require('fs');
const { spawn, exec, execSync } = require('child_process');
const path = require('path');
const process = require('process');
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
function parseVersion(str) {
const parts = str.split('.').map((a) => parseInt(a));
if(parts.length > 1) {
return parts;
}
else {
return null;
}
}
function getCurrentVersion() {
return parseVersion(execSync("git describe --abbrev=0 --tags", { encoding: 'utf8' }).toString().trim());
}
function nextMinorVersion(v) {
const res = v.slice(0, v.length - 1);
res.push(v[v.length-1] + 1);
return res;
}
function nextMajorVersion(v) {
const res = v.slice(0, v.length - 2);
res.push(v[v.length-2] + 1);
res.push(0);
return res;
}
function versionString(v) {
return v.join(".");
}
const outputDirectory = path.join(__dirname, "dist");
function getPackCmd (v) {
const args =
[
"/p:Version=" + versionString(v),
"/p:AssemblyVersion=" + versionString(v),
"/p:Authors=Aardworx",
"/p:Copyright=Aardworx",
"/p:RepositoryUrl=https://github.com/aardworx/aardvark.web",
"/p:PackageLicenseExpression=AGPL-3.0-only",
"-o \"" + outputDirectory + "\"",
"-c Release",
];
return "dotnet pack " + args.join(" ");
}
const currentVersion = getCurrentVersion();
let newVersion = currentVersion;
if (process.argv.length > 2) {
if (process.argv[2].toLowerCase() == "minor") newVersion = nextMinorVersion(currentVersion);
else if (process.argv[2].toLowerCase() == "major") newVersion = nextMajorVersion(currentVersion);
}
function getUserHome() {
return process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];
}
var deleteFolderRecursive = function(path) {
if (fs.existsSync(path)) {
fs.readdirSync(path).forEach(function(file, index){
var curPath = path + "/" + file;
if (fs.lstatSync(curPath).isDirectory()) { // recurse
deleteFolderRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
};
readline.question("\x1b[33mcreate packages with version " + versionString(newVersion) + "? [Y|n]\x1b[0m", (r) => {
if (r.toLowerCase() == "n") {
process.exit(0);
}
deleteFolderRecursive(path.join(__dirname, "dist"));
const packCmd = getPackCmd(newVersion);
console.log("\x1b[33mcreating packages\x1b[0m");
execSync(packCmd, { stdio: 'inherit' });
fs.readdir(outputDirectory, function (err, files) {
if(err) {
console.log("\x1b[31munable to scan directory: " + err + "\x1b[0m");
process.exit(1);
}
const key = fs.readFileSync(path.join(getUserHome(), ".ssh", "aardworx.key"));
console.log("using key: \x1b[33m" + key + "\x1b[0m");
const paket = path.join(__dirname, ".paket", "paket.exe");
files
.filter((f) => path.extname(f).toLowerCase() == ".nupkg")
.map((f) => path.join(__dirname, "dist", f))
.forEach((f) => {
console.log("\x1b[31m" + f + "\x1b[0m");
execSync(paket + " push --api-key " + key + " \"" + f + "\"");
});
process.exit(0);
});
});
//
//console.log("\x1b[33mcreate packages with version " + versionString(newVersion) + "? [Y|n]\x1b[0m");
//
//
//const packCmd = getPackCmd(newVersion);
//console.log("\x1b[33mcreating packages\x1b[0m");
//execSync(packCmd, { stdio: 'inherit' });