1 | 'use strict'
|
2 |
|
3 | const ora = require('ora')
|
4 | const path = require('path')
|
5 | const fs = require('fs')
|
6 | const glob = require('glob')
|
7 | const chalk = require('chalk')
|
8 | const { fetch } = require('@mara/devkit')
|
9 | const paths = require('../config/paths')
|
10 |
|
11 | const { name: pkgName, version: pkgVer } = require(paths.packageJson)
|
12 | const files = glob.sync(paths.lib + '/**')
|
13 | const spinner = ora('开始上线 umd 资源到 mjs...')
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | let noticeAfterPublish = false
|
22 | let noticeLevel = 'minor'
|
23 |
|
24 | if (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 |
|
37 | spinner.start()
|
38 |
|
39 | const url = 'http://exp.smfe.sina.cn/componentUmd'
|
40 | const data = { name: pkgName, version: pkgVer }
|
41 |
|
42 | if (noticeAfterPublish) {
|
43 | data.noticeAfterPublish = 1
|
44 | data.noticeLevel = noticeLevel
|
45 | }
|
46 |
|
47 | fetch
|
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 | })
|