class PostInstall {
constructor() {
this.text = ''
}
bright = (text) => {
this.text += `\x1b[1m${text}\x1b[0m`
return this
}
fgRed = (text) => {
this.text += `\x1b[31m${text}\x1b[0m`
return this
}
fgRedBold = (text) => {
this.text += `\x1b[31;1m${text}\x1b[0m`
return this
}
fgYellow = (text) => {
this.text += `\x1b[33m${text}\x1b[0m`
return this
}
fgYellowBold = (text) => {
this.text += `\x1b[33;1m${text}\x1b[0m`
return this
}
dim = (text) => {
this.text += `\x1b[2m${text}\x1b[0m`
return this
}
fgCyan = (text) => {
this.text += `\x1b[36m${text}\x1b[0m`
return this
}
underscore = (text) => {
this.text += `\x1b[4m${text}\x1b[0m`
return this
}
fgGreen = (text) => {
this.text += `\x1b[32m${text}\x1b[0m`
return this
}
endl = () => {
this.text += '\n'
return this
}
log = () => {
console.log(decodeURIComponent(this.text))
return this
}
}
new PostInstall()
.endl()
.fgYellow('='.repeat(60))
.endl()
.endl()
.fgGreen('%5B!%5D ')
.fgCyan(
'请关注VV%E5%89%8D%E7%AB%AF%E6%8A%80%E6%9C%AF%E7%A4%BE%E5%8C%BA%2C 结合文档进行开发 '
)
.endl()
.fgGreen('%5B!%5D ')
.fgCyan(
'%E6%96%87%E6%A1%A3%E5%9C%B0%E5%9D%80%3A%20http%3A%2F%2F*.*.*.*%3A8001%2FeSightFront%2F'
)
.endl()
.endl()
.fgYellow('='.repeat(60))
.endl()
.log()
const gulp = require('gulp')
const babel = require('gulp-babel')
const clean = require('gulp-clean')
const uglify = require('gulp-uglify')
const strip = require('gulp-strip-comments')
const sourcemaps = require('gulp-sourcemaps')
const ts = require('gulp-typescript')
const less = require('gulp-less')
const fs = require('fs')
const path = require('path')
const replace = require('gulp-replace')
const packageJson = require('./package.json')
const cleanConfig = { read: false, allowEmpty: true }
const dest = () => gulp.dest('dist')
const toClean = () => gulp.src('dist', cleanConfig).pipe(clean())
const srcPath = 'components/'
const SCRIPT_PATH = 'dist/_scripts'
gulp.task('clean', toClean)
function replaceTemplate() {
return replace(/(@cloudsop\/){0,1}eview-ui/g, () => {
return '@cloudsop/eview-ui'
})
}
function compileJS() {
return gulp
.src([`${srcPath}**/*.{js,jsx}`])
.pipe(replaceTemplate())
.pipe(babel())
.pipe(dest())
}
function copyImages() {
return gulp.src([`${srcPath}**/*.{png,gif,jpg,svg,bmp}`]).pipe(dest())
}
function copyFonts() {
return gulp.src([`${srcPath}**/*.{eot,ttf,woff,woff2}`]).pipe(dest())
}
function copyJson() {
return gulp
.src([`${srcPath}**/**/*.json`, `${srcPath}**/*.json`])
.pipe(dest())
}
function stripJS() {
return gulp
.src([`dist/${srcPath}**/*.js`])
.pipe(strip())
.pipe(dest())
}
function copyPackageAndRemoveUnusedDep(cb) {
if (packageJson.peerDependencies) {
for (const key in packageJson.peerDependencies) {
if (packageJson.dependencies[key]) {
delete packageJson.dependencies[key]
}
}
}
packageJson.scripts = {}
packageJson.scripts.postinstall = 'node _scripts/postinstall.js'
delete packageJson.devDependencies
fs.writeFile('./dist/package.json', JSON.stringify(packageJson, null, 2), cb)
}
const copyLessAndCss = () => gulp.src(`${srcPath}**/*.{less,css}`).pipe(dest())
const lessToCss = () =>
gulp
.src(`${srcPath}**/*.less`)
.pipe(sourcemaps.init())
.pipe(
less({
paths: [path.join(__dirname)],
})
)
.pipe(dest())
gulp.task(
'default',
gulp.series(
toClean,
gulp.parallel(
gulp.series(
compileTS,
compileJS,
copyLessAndCss,
copyImages,
copyFonts,
copyJson,
stripJS,
copyPackageAndRemoveUnusedDep,
copyScript
)
)
)
)
const tsProject = ts.createProject('tsconfig.json')
async function compileTS() {
const compiledFiles = tsProject
.src()
.pipe(replaceTemplate())
.pipe(sourcemaps.init())
.pipe(tsProject())
return [
compiledFiles.js.pipe(sourcemaps.write('.')).pipe(dest()),
compiledFiles.dts.pipe(dest()),
]
}
gulp.task('script', copyScript)
function copyScript() {
return gulp
.src('script/postinstall.js')
.pipe(babel())
.pipe(
uglify({
mangle: true,
compress: true,
})
)
.pipe(gulp.dest(SCRIPT_PATH))
}
{
"name": "*****",
"version": "0.0.61",
"description": "React components implementation",
"main": "index.js",
"scripts": {
"postinstall": "node _scripts/postinstall.js"
},
"author": "",
"license": "ISC",
"browserslist": [
"Firefox >= 40",
"chrome >= 50",
"ie >= 11",
"edge >= 12"
],
"dependencies": {
"@cloudsop/eview-ui": "0.1.137",
"echarts": "5.2.1",
"lodash": "4.17.21",
"react": "16.14.0",
"react-dom": "16.14.0",
"react-redux": "7.2.4",
"axios": "0.23.0",
"redux": "4.1.1"
}
}