diff --git a/src/index.js b/src/index.js index c7df0c613c67cb2c8c5e7922264dda916cf64e98..bce2c7b130db3b9395b72070fe08767b51276cd4 100644 --- a/src/index.js +++ b/src/index.js @@ -68,6 +68,10 @@ function getTranslation() { return locales[locale]; } +if (!fs.existsSync(path.join(process.cwd(), 'package.json'))) { + logger.error('package.json does not exist'); + process.exit(1); +} const PKG = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'package.json'))); const INITIAL_VERSION = '1.0.0'; const TAG_PREFIX = 'v'; @@ -100,7 +104,7 @@ async function fetchLatestVersion(info) { }); }); if (release.tag_name && release.tag_name.charAt(0) === 'v') { - const version = release.tag_name.substr(1); + const version = release.tag_name.slice(1); logger.log(`Latest version: ${version}`); return [version, release.target_commitish]; } @@ -173,8 +177,8 @@ function getGitRepoInfo() { function parseUrl(url) { [info.owner, info.repo] = url.split(':')[1].split('/'); - if (info.repo.substr(info.repo.length - 4) === '.git') { - info.repo = info.repo.substr(0, info.repo.length - 4); + if (info.repo.endsWith('.git')) { + info.repo = info.repo.slice(0, -4); } } @@ -220,11 +224,11 @@ async function collect(latestVersion) { return false; } - let message = line.substr(1); + let message = line.slice(1); const i = message.indexOf('('); if (i > 0) { - message = message.substr(0, i).trim(); + message = message.substring(0, i).trim(); } // 忽略重复的提交信息 if (messages.has(message)) {