2019-12-20 11:19:30 +08:00
|
|
|
import resolve from '@rollup/plugin-node-resolve'
|
2019-12-23 10:36:33 +08:00
|
|
|
import commonjs from '@rollup/plugin-commonjs'
|
2019-12-04 14:07:14 +08:00
|
|
|
import bundles from './build/index'
|
2019-12-18 15:28:32 +08:00
|
|
|
import fs from 'fs'
|
|
|
|
import path from 'path'
|
2020-04-18 15:59:21 +08:00
|
|
|
import buble from '@rollup/plugin-buble'
|
2020-03-03 18:58:53 +08:00
|
|
|
import json from "@rollup/plugin-json"
|
2020-04-18 15:59:21 +08:00
|
|
|
import image from '@rollup/plugin-image'
|
|
|
|
|
|
|
|
function searchImages(dir, images) {
|
|
|
|
const files = fs.readdirSync(dir)
|
|
|
|
files.forEach((item, index) => {
|
|
|
|
var fullPath = path.join(dir, item)
|
|
|
|
const stat = fs.statSync(fullPath)
|
|
|
|
if (stat.isDirectory()) {
|
|
|
|
searchImages(path.join(dir, item), images)
|
|
|
|
} else {
|
2021-01-20 17:22:26 +08:00
|
|
|
if (fullPath.endsWith('.png')) {
|
2020-04-18 15:59:21 +08:00
|
|
|
images.push(fullPath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return images
|
|
|
|
}
|
|
|
|
|
|
|
|
const allImages = []
|
|
|
|
searchImages('src', allImages)
|
|
|
|
|
|
|
|
function mkdirsSync(dirname) {
|
|
|
|
if (fs.existsSync(dirname)) {
|
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
if (mkdirsSync(path.dirname(dirname))) {
|
|
|
|
fs.mkdirSync(dirname)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
allImages.forEach((value) => {
|
|
|
|
let path = __dirname + '/build/' + value
|
2021-01-20 17:22:26 +08:00
|
|
|
path = path.split("\\").join("/")
|
2020-04-18 15:59:21 +08:00
|
|
|
let index = path.lastIndexOf('/')
|
|
|
|
mkdirsSync(path.substring(0, index))
|
|
|
|
|
|
|
|
fs.copyFile(__dirname + '/' + value, __dirname + '/build/' + value, error => {
|
2021-01-20 17:22:26 +08:00
|
|
|
if (error)
|
|
|
|
console.log(error)
|
2020-04-18 15:59:21 +08:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-12-04 14:07:14 +08:00
|
|
|
|
2019-12-18 15:28:32 +08:00
|
|
|
function readDirs(dirPath, files) {
|
|
|
|
if (fs.statSync(dirPath).isDirectory()) {
|
|
|
|
fs.readdirSync(dirPath).forEach(e => {
|
|
|
|
readDirs(path.join(dirPath, e), files)
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
for (let bundle of bundles) {
|
2021-01-20 17:22:26 +08:00
|
|
|
if (dirPath.replace("\\", "/").match(new RegExp(`^${bundle}`))) {
|
2019-12-18 15:28:32 +08:00
|
|
|
files.push(dirPath)
|
|
|
|
}
|
2019-12-04 14:07:14 +08:00
|
|
|
}
|
|
|
|
}
|
2019-12-18 15:28:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const dirs = fs.readdirSync('.')
|
|
|
|
.filter(e => {
|
|
|
|
for (let bundle of bundles) {
|
|
|
|
if (bundle.match(new RegExp(`^${e}/`))) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
|
|
|
|
const allFiles = []
|
|
|
|
|
|
|
|
dirs.forEach(e => {
|
|
|
|
readDirs(e, allFiles)
|
|
|
|
})
|
2020-01-15 17:24:11 +08:00
|
|
|
export default
|
|
|
|
allFiles
|
|
|
|
.map(e => e.replace('.ts', ''))
|
|
|
|
.map(bundle => {
|
|
|
|
return {
|
|
|
|
input: `build/${bundle}.js`,
|
|
|
|
output: {
|
|
|
|
format: "cjs",
|
|
|
|
file: `bundle/${bundle}.js`,
|
|
|
|
sourcemap: true,
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
resolve({ mainFields: ["jsnext"] }),
|
|
|
|
commonjs(),
|
2020-03-03 18:58:53 +08:00
|
|
|
json(),
|
2020-04-18 15:59:21 +08:00
|
|
|
image(),
|
2020-01-15 17:24:11 +08:00
|
|
|
],
|
|
|
|
external: ['reflect-metadata', 'doric'],
|
|
|
|
onwarn: function (warning) {
|
2020-04-18 15:59:21 +08:00
|
|
|
if (warning.code === 'THIS_IS_UNDEFINED') { return }
|
|
|
|
console.warn(warning.message)
|
2020-01-15 17:24:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}).concat(
|
|
|
|
allFiles
|
|
|
|
.map(e => e.replace('.ts', ''))
|
|
|
|
.map(bundle => {
|
|
|
|
return {
|
|
|
|
input: `build/${bundle}.js`,
|
|
|
|
output: {
|
|
|
|
format: "cjs",
|
|
|
|
file: `bundle/${bundle}.es5.js`,
|
|
|
|
sourcemap: true,
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
resolve({ mainFields: ["jsnext"] }),
|
|
|
|
commonjs(),
|
2020-03-03 18:58:53 +08:00
|
|
|
json(),
|
2020-01-15 17:24:11 +08:00
|
|
|
buble({
|
2020-04-28 11:46:38 +08:00
|
|
|
transforms: {
|
|
|
|
dangerousForOf: true,
|
|
|
|
generator: false,
|
|
|
|
}
|
2020-01-15 17:24:11 +08:00
|
|
|
}),
|
2020-04-18 15:59:21 +08:00
|
|
|
image(),
|
2020-01-15 17:24:11 +08:00
|
|
|
],
|
|
|
|
external: ['reflect-metadata', 'doric'],
|
|
|
|
onwarn: function (warning) {
|
2020-04-18 15:59:21 +08:00
|
|
|
if (warning.code === 'THIS_IS_UNDEFINED') { return }
|
|
|
|
console.warn(warning.message)
|
2020-01-15 17:24:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}))
|