UNPKG

2.25 kBJavaScriptView Raw
1'use strict'
2
3const path = require('path')
4const fs = require('fs')
5const cwd = process.cwd()
6
7const packageConfig = require(path.resolve(cwd, 'package.json'))
8const distPath = path.resolve(cwd, 'dist')
9const libsPath = path.resolve(cwd, 'lib')
10
11const glob = require('glob')
12const files = glob.sync(libsPath + '/**')
13// const fileslib = glob.sync(libsPath+"/**");
14const http = require('http')
15const chalk = require('chalk')
16const ora = require('ora')
17
18const spinner = ora('开始上线umd资源到mjs...')
19
20// marauder.config.js
21// //用于描述 组件 工程化相关属性
22// pkgConfig:{
23// noticeAfterPublish:true,//false
24// noticeLevel:"",//patch minor major 分别对应 发小版本,中版本,大版本 以及以上才发,比如 prepatch ,preminor 都不进行触发。
25// }
26let noticeAfterPublish = false
27let noticeLevel = 'minor'
28
29if (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
42console.log('开始上线umd资源到mjs...')
43
44spinner.start()
45let url =
46 'http://exp.smfe.sina.cn/componentUmd?name=' +
47 packageConfig.name +
48 '&version=' +
49 packageConfig.version
50if (noticeAfterPublish) {
51 url += '&noticeAfterPublish=1&noticeLevel=' + noticeLevel
52}
53http
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 })