|
| 1 | +import { execSync } from "child_process"; |
| 2 | +import { existsSync } from "fs"; |
| 3 | +import { join } from 'path' |
| 4 | + |
| 5 | +export const packages = [ |
| 6 | + "packages/@vuexhydrate/types", |
| 7 | + "packages/@vuexhydrate/state", |
| 8 | + "packages/@vuexhydrate/routing", |
| 9 | + "packages/@vuexhydrate/webpack-plugin", |
| 10 | + "packages/@vuexhydrate/laravel-mix", |
| 11 | + "packages/@vuexhydrate/phase", |
| 12 | +]; |
| 13 | + |
| 14 | +export function git(cmd) { |
| 15 | + return execSync(`git ${cmd}`).toString().trim().split("\n"); |
| 16 | +} |
| 17 | + |
| 18 | +// release/changelog parseing |
| 19 | +export function parseChangelogLine(line) { |
| 20 | + const regex = /^\[(?<hash>.{7,7})\] (?<type>[\w\s\d]*)(\((?<scope>.*)\))?: (?<change>.*) \((?<author>.*)\)$/gm; |
| 21 | + let m; |
| 22 | + |
| 23 | + while ((m = regex.exec(line)) !== null) { |
| 24 | + // This is necessary to avoid infinite loops with zero-width matches |
| 25 | + if (m.index === regex.lastIndex) { |
| 26 | + regex.lastIndex++; |
| 27 | + } |
| 28 | + return m.groups; |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +export function acceptableLines(line) { |
| 33 | + if (!line) return false; |
| 34 | + if (line.change.startsWith("wip")) return false; |
| 35 | + if (line.scope && line.scope.includes("release")) return false; |
| 36 | + return true; |
| 37 | +} |
| 38 | + |
| 39 | +export function formatLine(line) { |
| 40 | + return `- [${line.hash}]: **${line.type}${ |
| 41 | + line.scope ? `(**_${line.scope}_**)` : "" |
| 42 | + }**: ${line.change} - (${line.author})`; |
| 43 | +} |
| 44 | + |
| 45 | +export function formatDiff(tag) { |
| 46 | + return function(line) { |
| 47 | + const [_, _base, _package] = line.split("/") |
| 48 | + const file = `./packages/${_base}/${_package}/package.json` |
| 49 | + const isForNpm = existsSync(file) |
| 50 | + const version = isForNpm |
| 51 | + ? require(join("..", file)).version |
| 52 | + : tag.name.replace(/^v/, "") |
| 53 | + |
| 54 | + const pkg = { |
| 55 | + base: _base, |
| 56 | + package: _package, |
| 57 | + version, |
| 58 | + manager: isForNpm ? "npm" : "composer", |
| 59 | + } |
| 60 | + |
| 61 | + return `- _[${`${pkg.manager}`.padEnd(8, " ")}]_ **${pkg.base}/${ |
| 62 | + pkg.package |
| 63 | + }**@_${pkg.version}_`.toLowerCase(); |
| 64 | + } |
| 65 | +} |
0 commit comments