UNPKG

2.03 kBJavaScriptView Raw
1'use strict'
2
3const ora = require('ora')
4const path = require('path')
5const fs = require('fs')
6const glob = require('glob')
7const chalk = require('chalk')
8const { fetch } = require('@mara/devkit')
9const paths = require('../config/paths')
10
11const { name: pkgName, version: pkgVer } = require(paths.packageJson)
12const files = glob.sync(paths.lib + '/**')
13const spinner = ora('开始上线 umd 资源到 mjs...')
14
15// marauder.config.js
16// 用于描述 组件 工程化相关属性
17// pkgConfig:{
18// noticeAfterPublish:true,//false
19// noticeLevel:"",//patch minor major 分别对应 发小版本,中版本,大版本 以及以上才发,比如 prepatch ,preminor 都不进行触发。
20// }
21let noticeAfterPublish = false
22let noticeLevel = 'minor'
23
24if (fs.existsSync(paths.marauder)) {
25 const maraConf = require(paths.marauder)
26
27 if (
28 maraConf &&
29 maraConf.pkgConfig &&
30 maraConf.pkgConfig.noticeAfterPublish == true
31 ) {
32 noticeAfterPublish = maraConf.pkgConfig.noticeAfterPublish
33 noticeLevel = maraConf.pkgConfig.noticeLevel || 'minor'
34 }
35}
36
37spinner.start()
38
39const url = 'http://exp.smfe.sina.cn/componentUmd'
40const data = { name: pkgName, version: pkgVer }
41
42if (noticeAfterPublish) {
43 data.noticeAfterPublish = 1
44 data.noticeLevel = noticeLevel
45}
46
47fetch
48 .get(url, data)
49 .then(rep => {
50 spinner.stop()
51
52 console.log('静态资源 CDN 上线成功,线上路径为:\n')
53
54 files.forEach(f => {
55 if (
56 path.relative(paths.lib, f) == null ||
57 path.relative(paths.lib, f) == ''
58 ) {
59 return
60 }
61
62 console.log(
63 chalk.cyan(
64 path.join(
65 'https://mjs.sinaimg.cn/umd/',
66 pkgName.replace('@mfelibs/', ''),
67 '/',
68 pkgVer,
69 '/',
70 path.relative(paths.lib, f)
71 )
72 )
73 )
74 })
75 })
76 .catch(e => {
77 spinner.stop()
78
79 console.log(e)
80 console.log(
81 chalk.red('静态资源 CDN 上线失败\n请访问此链接手动发布:' + url)
82 )
83 })