|
| 1 | +const pkg = require('./package.json'); |
| 2 | +const fs = require('fs'); |
| 3 | +const path = require('path'); |
| 4 | +const { execSync } = require('child_process'); |
| 5 | + |
| 6 | +const rmDir = function(dirPath) { |
| 7 | + if(fs.existsSync(dirPath)) { |
| 8 | + const files = fs.readdirSync(dirPath); |
| 9 | + files.forEach(function(file) { |
| 10 | + const curPath = path.join(dirPath, file); |
| 11 | + if(fs.lstatSync(curPath).isDirectory()) { |
| 12 | + rmDir(curPath); |
| 13 | + } else { |
| 14 | + fs.unlinkSync(curPath); |
| 15 | + } |
| 16 | + }); |
| 17 | + fs.rmdirSync(dirPath); |
| 18 | + } |
| 19 | +}; |
| 20 | + |
| 21 | +const exec = function(cmd) { |
| 22 | + execSync(cmd, { stdio: 'inherit' }); |
| 23 | +}; |
| 24 | + |
| 25 | +console.log(`Building JavaScript SDK v${pkg.version}...\n`) |
| 26 | + |
| 27 | +console.log('Cleaning up old builds...\n'); |
| 28 | + |
| 29 | +rmDir(path.join(__dirname, 'dist')); |
| 30 | +rmDir(path.join(__dirname, 'lib')); |
| 31 | + |
| 32 | +const crossEnv = 'npm run cross-env'; |
| 33 | +const gulp = 'npm run gulp'; |
| 34 | + |
| 35 | +console.log('Browser Release:'); |
| 36 | +exec(`${crossEnv} PARSE_BUILD=browser ${gulp} compile`); |
| 37 | + |
| 38 | +console.log('Weapp Release:'); |
| 39 | +exec(`${crossEnv} PARSE_BUILD=weapp ${gulp} compile`); |
| 40 | + |
| 41 | +console.log('Node.js Release:'); |
| 42 | +exec(`${crossEnv} PARSE_BUILD=node ${gulp} compile`); |
| 43 | + |
| 44 | +console.log('React Native Release:'); |
| 45 | +exec(`${crossEnv} PARSE_BUILD=react-native ${gulp} compile`); |
| 46 | + |
| 47 | +console.log('Bundling and minifying for CDN distribution:'); |
| 48 | +exec(`${gulp} browserify`); |
| 49 | +exec(`${gulp} browserify-weapp`); |
| 50 | +exec(`${gulp} minify`); |
| 51 | +exec(`${gulp} minify-weapp`); |
0 commit comments