Skip to content

Commit

Permalink
release script
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Jul 18, 2018
1 parent 8db839f commit a1cd9c5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 98 deletions.
4 changes: 2 additions & 2 deletions packages/moon-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"moon": "index.js"
},
"scripts": {
"build": "",
"build": "echo \"Build Moon CLI\"",
"test": ""
},
"repository": {
Expand All @@ -24,4 +24,4 @@
"url": "https://github.com/kbrsh/moon/issues"
},
"homepage": "https://github.com/kbrsh/moon#readme"
}
}
4 changes: 2 additions & 2 deletions packages/moon-mvl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Moon MVL component compiler",
"main": "index.js",
"scripts": {
"build": "",
"build": "echo \"Build Moon MVL\"",
"test": ""
},
"repository": {
Expand All @@ -24,4 +24,4 @@
"peerDependencies": {
"moon": "*"
}
}
}
2 changes: 1 addition & 1 deletion packages/moon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
"rollup-plugin-eslint": "^4.0.0",
"uglify-js": "^3.3.22"
}
}
}
120 changes: 27 additions & 93 deletions release.js
Original file line number Diff line number Diff line change
@@ -1,110 +1,44 @@
const exec = require("child_process").execSync;
const fs = require("fs");
const path = require("path");
const exec = require("child_process").execSync;

let tags = exec("git tag --sort=committerdate").toString().split("\n");
tags.pop();
tags = tags.slice(-2);

let commits = exec(`git log --pretty=format:"%H%n%B%n%n%n~~~COMMIT~~~%n%n%n" ${tags[0]}...${tags[1]}`).toString().split("\n\n\n~~~COMMIT~~~\n\n\n");
commits.pop();

let log = "";
let i = 0;
let commit;
let commitEntry;
let hash;
let category;
let breaking = [];
let features = [];
let patches = [];
let performance = [];
let refactor = [];
let docs = [];

for(; i < commits.length; i++) {
commit = commits[i].split("\n");
commit.shift();
commit.pop();
hash = commit.shift();
commit = commit.join("\n").split(":");
category = commit.shift();
commit = commit.join(":").split("\n");
const version = process.argv[2];

let body;
if(commit.length > 1) {
let commitSubject = commit.shift();
body = commit.map((item) => ` ${item}`).join("\n");
if(body.trim().length === 0) {
body = undefined;
}
commit = commitSubject;
const packages = fs.readdirSync("./packages");
for (let i = 0; i < packages.length; i++) {
const package = path.join("./packages", packages[i]);
if (fs.statSync(package).isDirectory()) {
const packageJSONPath = path.join(package, "package.json");
const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath).toString());
packageJSON.version = version;
fs.writeFileSync(packageJSONPath, JSON.stringify(packageJSON, null, 2));
}
}

commitEntry = {
hash: hash,
subject: commit,
body: body
}
console.log(exec("npm run build").toString());

switch(category) {
case "fix":
patches.push(commitEntry);
break;
case "feat":
features.push(commitEntry);
break;
case "perf":
performance.push(commitEntry);
break;
case "docs":
docs.push(commitEntry);
break;
case "refactor":
refactor.push(commitEntry);
break;
case "breaking":
breaking.push(commitEntry);
break;
}
}
const trailingNewlinesRE = /\n+$/;
const trailingLinesRE = /\n([^\n]*)/g;

let entry;
let first = true;
exec(`git tag v${version}`);

let tags = exec("git tag --sort=committerdate").toString().split("\n");
tags.pop();
tags = tags.slice(-2);

const generateCategory = (header, entries) => {
if(entries.length > 0) {
if(first === true) {
log += `## ${header}\n\n`;
first = false;
} else {
log += `\n\n## ${header}\n\n`;
}
const commits = exec(`git log --pretty=tformat:"###COMMIT###%H###SEPARATOR###%B" ${tags[0]}...${tags[1]}`).toString().split("###COMMIT###");
commits.shift();

for(i = 0; i < entries.length - 1; i++) {
entry = entries[i];
log += `* ${entry.hash}${entry.subject}\n`;
let log = "";

if(entry.body !== undefined) {
log += `${entry.body}\n`;
}
}
for (let i = 0; i < commits.length; i++) {
const commit = commits[i].replace(trailingNewlinesRE, "").split("###SEPARATOR###");
const hash = commit[0];
const message = commit[1].replace(trailingLinesRE, "\n $1");

entry = entries[i];
log += `* ${entry.hash}${entry.subject}`;
if(entry.body !== undefined) {
log += `\n${entry.body}`;
}
}
log += `* ${hash}: ${message}\n`;
}

generateCategory("Breaking Changes", breaking);
generateCategory("Features", features);
generateCategory("Patches", patches);
generateCategory("Performance", performance);
generateCategory("Refactoring", refactor);
generateCategory("Documentation", docs);

const releaseNotePath = path.resolve("./RELEASE_NOTE");
fs.writeFileSync(releaseNotePath, log);
exec(`cat ./RELEASE_NOTE | pbcopy`);
Expand Down

0 comments on commit a1cd9c5

Please sign in to comment.