UNPKG

1.34 kBJavaScriptView Raw
1'use strict'
2
3const path = require('path')
4const fs = require('fs')
5const updateNotifier = require('update-notifier')
6const shelljs = require('shelljs')
7const pkg = require('../package.json')
8const PLUGIN_PATH = require('./path').PLUGIN_PATH
9const CWD_PATH = require('./path').CWD_PATH
10
11exports.registry = function (registry) {
12 if (!registry) {
13 return ''
14 }
15
16 return '--registry=' + registry
17}
18
19/* istanbul ignore next */
20exports.initPluginPackage = function () {
21 if (!fs.existsSync(PLUGIN_PATH)) {
22 fs.mkdirSync(PLUGIN_PATH)
23 }
24
25 var pluginPkg = path.join(PLUGIN_PATH, 'package.json')
26
27 if (!fs.existsSync(pluginPkg)) {
28 fs.writeFileSync(pluginPkg, '{}')
29 }
30}
31
32/* istanbul ignore next */
33exports.checkPermission = function () {
34 const tmpFile = path.join(PLUGIN_PATH, 'tmp')
35
36 fs.writeFileSync(path.join(PLUGIN_PATH, 'tmp'))
37 shelljs.rm(tmpFile)
38}
39
40/* istanbul ignore next */
41exports.checkVersion = function () {
42 var notifier = updateNotifier({pkg})
43
44 notifier.notify()
45 if (notifier.update) {
46 console.log(notifier.update)
47 }
48}
49
50/* istanbul ignore next */
51exports.pluginExists = function (name) {
52 return fs.existsSync(path.join(PLUGIN_PATH, 'node_modules', name))
53}
54
55/* istanbul ignore next */
56exports.localExists = function (name) {
57 return fs.existsSync(path.join(CWD_PATH, 'node_modules', name))
58}
59