UNPKG

870 BJavaScriptView Raw
1const fs = require('fs')
2const cwd = process.cwd()
3const path = require('path')
4const { log } = require('./log')
5
6/**
7 * 检查是否已经初始化:
8 * 1.npm
9 * 2.git
10 */
11
12module.exports = () => {
13 let packageJson
14 try {
15 packageJson = require(path.posix.join(cwd, 'package.json'))
16 } catch (err) {
17 if (err.code === 'MODULE_NOT_FOUND') {
18 log('Please init package.json!\nPlease init package.json!\nPlease init package.json!', 'red')
19 log('Sorry, important things should be mentioned three times...')
20 process.exit(1)
21 } else {
22 throw err
23 }
24 }
25
26 if (!fs.existsSync(path.posix.join(cwd, '.git'))) {
27 log('Please init git!\nPlease init git!\nPlease init git!', 'red')
28 log('Sorry, important things should be mentioned three times...')
29 process.exit(1)
30 }
31}