1 | 'use strict'
|
2 |
|
3 | const path = require('path')
|
4 | const fs = require('fs')
|
5 | const updateNotifier = require('update-notifier')
|
6 | const shelljs = require('shelljs')
|
7 | const pkg = require('../package.json')
|
8 | const PLUGIN_PATH = require('./path').PLUGIN_PATH
|
9 | const CWD_PATH = require('./path').CWD_PATH
|
10 |
|
11 | exports.registry = function (registry) {
|
12 | if (!registry) {
|
13 | return ''
|
14 | }
|
15 |
|
16 | return '--registry=' + registry
|
17 | }
|
18 |
|
19 |
|
20 | exports.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 |
|
33 | exports.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 |
|
41 | exports.checkVersion = function () {
|
42 | var notifier = updateNotifier({pkg})
|
43 |
|
44 | notifier.notify()
|
45 | if (notifier.update) {
|
46 | console.log(notifier.update)
|
47 | }
|
48 | }
|
49 |
|
50 |
|
51 | exports.pluginExists = function (name) {
|
52 | return fs.existsSync(path.join(PLUGIN_PATH, 'node_modules', name))
|
53 | }
|
54 |
|
55 |
|
56 | exports.localExists = function (name) {
|
57 | return fs.existsSync(path.join(CWD_PATH, 'node_modules', name))
|
58 | }
|
59 |
|