forked from alibaba-fusion/next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
changelog.js
31 lines (26 loc) · 890 Bytes
/
changelog.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
const co = require('co');
const fs = require('fs-extra');
const path = require('path');
const cwd = process.cwd();
const changelog = require('./release/changelog');
const { logger } = require('./utils');
const packagePath = path.resolve('package.json');
co(function*() {
yield changelog();
updateVersionInCode();
}).catch(err => {
logger.error('Generate changelog failed', err.stack);
});
function updateVersionInCode() {
const packageInfo = require(packagePath);
const entryPath = path.join(cwd, 'index.js');
let entryContent = fs.readFileSync(entryPath, 'utf8');
entryContent = entryContent.replace(
/(next\.version = ')[\d.\w]+(';)/,
(all, s1, s2) => {
return `${s1}${packageInfo.version}${s2}`;
}
);
fs.writeFileSync(entryPath, entryContent);
logger.success(`Update version in [${entryPath}] success`);
}