1 | 'use strict'
|
2 |
|
3 | const path = require('path')
|
4 | const fs = require('fs')
|
5 | const cwd = process.cwd()
|
6 |
|
7 | const packageConfig = require(path.resolve(cwd, 'package.json'))
|
8 | const distPath = path.resolve(cwd, 'dist')
|
9 | const libsPath = path.resolve(cwd, 'lib')
|
10 |
|
11 | const glob = require('glob')
|
12 | const files = glob.sync(libsPath + '/**')
|
13 |
|
14 | const http = require('http')
|
15 | const chalk = require('chalk')
|
16 | const ora = require('ora')
|
17 |
|
18 | const spinner = ora('开始上线umd资源到mjs...')
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | let noticeAfterPublish = false
|
27 | let noticeLevel = 'minor'
|
28 |
|
29 | if (fs.existsSync(path.resolve(cwd, 'marauder.config.js'))) {
|
30 | const maraConf = require(path.resolve(cwd, 'marauder.config.js'))
|
31 |
|
32 | if (
|
33 | maraConf &&
|
34 | maraConf.pkgConfig &&
|
35 | maraConf.pkgConfig.noticeAfterPublish == true
|
36 | ) {
|
37 | noticeAfterPublish = maraConf.pkgConfig.noticeAfterPublish
|
38 | noticeLevel = maraConf.pkgConfig.noticeLevel || 'minor'
|
39 | }
|
40 | }
|
41 |
|
42 | console.log('开始上线umd资源到mjs...')
|
43 |
|
44 | spinner.start()
|
45 | let url =
|
46 | 'http://exp.smfe.sina.cn/componentUmd?name=' +
|
47 | packageConfig.name +
|
48 | '&version=' +
|
49 | packageConfig.version
|
50 | if (noticeAfterPublish) {
|
51 | url += '¬iceAfterPublish=1¬iceLevel=' + noticeLevel
|
52 | }
|
53 | http
|
54 | .get(url, function(res) {
|
55 | spinner.stop()
|
56 | console.log(chalk.cyan('静态资源上线cnpm-mjs通知成功\n,线上相对路径为:'))
|
57 | for (var i = 0; i < files.length; i++) {
|
58 | if (
|
59 | path.relative(libsPath, files[i]) == null ||
|
60 | path.relative(libsPath, files[i]) == ''
|
61 | ) {
|
62 | continue
|
63 | }
|
64 | console.log(
|
65 | chalk.cyan(
|
66 | path.join('http://mjs.sinaimg.cn/umd/',packageConfig.name.replace('@mfelibs/', '') ,"/", packageConfig.version,"/", path.relative(libsPath, files[i]))
|
67 | )
|
68 | )
|
69 | }
|
70 | })
|
71 | .on('error', function(e) {
|
72 | spinner.stop()
|
73 | console.log(e)
|
74 | console.log(
|
75 | chalk.red('静态资源上线cnpm-mjs通知失败\n请手动重试如下链接:' + url)
|
76 | )
|
77 | })
|