@pie-framework/build-helper
Advanced tools
Comparing version 4.0.1 to 4.1.0
@@ -20,3 +20,4 @@ export declare const getPackages: (root: string) => { | ||
}[]>; | ||
export declare const rmChangelogJson: (packagesDir: any) => Promise<[void, void][]>; | ||
export declare const rmChangelogJson: (packagesDir: any) => Promise<void[]>; | ||
export declare const rmNextChangelogJson: (packagesDir: any) => Promise<void[]>; | ||
export declare const changelogJson: (pk: { | ||
@@ -23,0 +24,0 @@ dir: string; |
@@ -49,5 +49,4 @@ "use strict"; | ||
const promises = packages.map((p) => __awaiter(this, void 0, void 0, function* () { | ||
log('next changelog for : ', p.dir); | ||
log('changelog for : ', p.dir); | ||
const changelog = yield exports.changelogJson(p, { type }); | ||
log(changelog); | ||
return Object.assign({}, p, { changelog }); | ||
@@ -67,9 +66,17 @@ })); | ||
const packages = exports.getPackages(packagesDir); | ||
return Promise.all(packages.map(p => { | ||
return Promise.all([ | ||
fs_extra_1.remove(path_1.join(p.dir, NEXT_CHANGELOG)), | ||
fs_extra_1.remove(path_1.join(p.dir, CHANGELOG)) | ||
]); | ||
})); | ||
return Promise.all(packages.map(p => fs_extra_1.remove(path_1.join(p.dir, CHANGELOG)))); | ||
}); | ||
exports.rmNextChangelogJson = (packagesDir) => __awaiter(this, void 0, void 0, function* () { | ||
const packages = exports.getPackages(packagesDir); | ||
return Promise.all(packages.map(p => fs_extra_1.remove(path_1.join(p.dir, NEXT_CHANGELOG)))); | ||
}); | ||
const readExistingChangelog = (dir) => fs_extra_1.readJson(path_1.join(dir, CHANGELOG)).catch(e => undefined); | ||
const getLatestHashFromExistingChangelog = (existingChangelog) => { | ||
if (Array.isArray(existingChangelog) && existingChangelog.length > 0) { | ||
return existingChangelog[0].hash || ''; | ||
} | ||
else { | ||
return ''; | ||
} | ||
}; | ||
const getTagList = (hash) => { | ||
@@ -83,53 +90,56 @@ let tags = child_process_1.execSync(`git tag --contains ${hash}`) | ||
}; | ||
exports.changelogJson = (pk, opts) => { | ||
exports.changelogJson = (pk, opts) => __awaiter(this, void 0, void 0, function* () { | ||
const options = Object.assign({ preset: 'angular', pkg: { | ||
path: pk.dir | ||
}, lernaPackage: pk.pkg.name, releaseCount: 0 }, opts); | ||
const existingChangelog = yield readExistingChangelog(pk.dir); | ||
log('found existing changelog:', existingChangelog !== undefined, pk.dir); | ||
const from = getLatestHashFromExistingChangelog(existingChangelog); | ||
const gitRawCommitsOpts = { | ||
path: pk.dir, | ||
merges: true | ||
merges: true, | ||
from | ||
}; | ||
const context = undefined; | ||
return mergeConfig(options, context, gitRawCommitsOpts).then(merged => { | ||
return new Promise((resolve, reject) => { | ||
const ws = new ArrayBufferWritable((err, s) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
else { | ||
resolve(s); | ||
} | ||
}); | ||
gitRawCommits(merged.gitRawCommitsOpts).pipe(ws); | ||
}).then((chunks) => { | ||
const out = chunks | ||
.map(b => conventional_commits_parser_1.sync(b.toString(), merged.parserOpts)) | ||
.filter(d => d.type) | ||
.map(data => { | ||
try { | ||
const tagList = getTagList(data.hash); | ||
const list = tagList.filter(s => s.startsWith(pk.pkg.name)); | ||
data.isTagged = list.length > 0; | ||
data.earliestTag = list.length >= 1 ? list[0] : undefined; | ||
delete data.mentions; | ||
delete data.references; | ||
delete data.revert; | ||
return data; | ||
} | ||
catch (e) { | ||
return data; | ||
} | ||
}); | ||
if (options.type === 'released') { | ||
return out.filter(d => d.isTagged); | ||
const merged = yield mergeConfig(options, context, gitRawCommitsOpts); | ||
const chunks = yield new Promise((resolve, reject) => { | ||
const ws = new ArrayBufferWritable((err, s) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
else if (options.type === 'unreleased') { | ||
return out.filter(d => !d.isTagged); | ||
} | ||
else { | ||
return out; | ||
resolve(s); | ||
} | ||
}); | ||
gitRawCommits(merged.gitRawCommitsOpts).pipe(ws); | ||
}); | ||
}; | ||
const out = chunks | ||
.map(b => conventional_commits_parser_1.sync(b.toString(), merged.parserOpts)) | ||
.filter(d => d.type) | ||
.map(data => { | ||
try { | ||
const tagList = getTagList(data.hash); | ||
const list = tagList.filter(s => s.startsWith(`${pk.pkg.name}@`)); | ||
data.isTagged = list.length > 0; | ||
data.earliestTag = list.length >= 1 ? list[0] : undefined; | ||
delete data.mentions; | ||
delete data.references; | ||
delete data.revert; | ||
return data; | ||
} | ||
catch (e) { | ||
return data; | ||
} | ||
}); | ||
if (options.type === 'released') { | ||
const tagged = out.filter(d => d.isTagged); | ||
return tagged.concat(existingChangelog || []); | ||
} | ||
else if (options.type === 'unreleased') { | ||
return out.filter(d => !d.isTagged); | ||
} | ||
else { | ||
return out.concat(existingChangelog || []); | ||
} | ||
}); | ||
//# sourceMappingURL=changelog.js.map |
@@ -80,3 +80,5 @@ "use strict"; | ||
} | ||
yield changelog_1.rmChangelogJson(dir); | ||
else { | ||
yield changelog_1.rmNextChangelogJson(dir); | ||
} | ||
yield changelog_1.writeReleasedChangelogJson(dir); | ||
@@ -83,0 +85,0 @@ }); |
{ | ||
"name": "@pie-framework/build-helper", | ||
"version": "4.0.1", | ||
"version": "4.1.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
256601
588