diff --git a/build_releases.js b/build_releases.js new file mode 100755 index 000000000..c118d2484 --- /dev/null +++ b/build_releases.js @@ -0,0 +1,51 @@ +const pkg = require('./package.json'); +const fs = require('fs'); +const path = require('path'); +const { execSync } = require('child_process'); + +const rmDir = function(dirPath) { + if(fs.existsSync(dirPath)) { + const files = fs.readdirSync(dirPath); + files.forEach(function(file) { + const curPath = path.join(dirPath, file); + if(fs.lstatSync(curPath).isDirectory()) { + rmDir(curPath); + } else { + fs.unlinkSync(curPath); + } + }); + fs.rmdirSync(dirPath); + } +}; + +const exec = function(cmd) { + execSync(cmd, { stdio: 'inherit' }); +}; + +console.log(`Building JavaScript SDK v${pkg.version}...\n`) + +console.log('Cleaning up old builds...\n'); + +rmDir(path.join(__dirname, 'dist')); +rmDir(path.join(__dirname, 'lib')); + +const crossEnv = 'npm run cross-env'; +const gulp = 'npm run gulp'; + +console.log('Browser Release:'); +exec(`${crossEnv} PARSE_BUILD=browser ${gulp} compile`); + +console.log('Weapp Release:'); +exec(`${crossEnv} PARSE_BUILD=weapp ${gulp} compile`); + +console.log('Node.js Release:'); +exec(`${crossEnv} PARSE_BUILD=node ${gulp} compile`); + +console.log('React Native Release:'); +exec(`${crossEnv} PARSE_BUILD=react-native ${gulp} compile`); + +console.log('Bundling and minifying for CDN distribution:'); +exec(`${gulp} browserify`); +exec(`${gulp} browserify-weapp`); +exec(`${gulp} minify`); +exec(`${gulp} minify-weapp`); diff --git a/build_releases.sh b/build_releases.sh deleted file mode 100755 index d82dbfe20..000000000 --- a/build_releases.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -SDK_VERSION=$(cat package.json | sed -n -e '/version/ s/.*: *"\([^"]*\).*/\1/p') -echo "Building JavaScript SDK v$SDK_VERSION...\n" - -echo "Cleaning up old builds...\n" -rm -rf dist lib - -echo "Browser Release:" -PARSE_BUILD=browser gulp compile -echo "Weapp Release:" -PARSE_BUILD=weapp gulp compile -echo "Node.js Release:" -PARSE_BUILD=node gulp compile -echo "React Native Release:" -PARSE_BUILD=react-native gulp compile -echo "Bundling and minifying for CDN distribution:" -gulp browserify -gulp browserify-weapp -gulp minify -gulp minify-weapp diff --git a/package.json b/package.json index 5a7bb9a94..085e4c487 100644 --- a/package.json +++ b/package.json @@ -73,8 +73,8 @@ "vinyl-source-stream": "2.0.0" }, "scripts": { - "build": "./build_releases.sh", - "release": "./build_releases.sh && npm publish", + "build": "node build_releases.js", + "release": "node build_releases.js && npm publish", "test": "cross-env PARSE_BUILD=node jest", "lint": "eslint --cache src/ integration/", "lint:fix": "eslint --fix --cache src/ integration/", @@ -85,7 +85,9 @@ "integration": "cross-env TESTING=1 jasmine --config=jasmine.json", "docs": "jsdoc -c ./jsdoc-conf.json ./src", "prepare": "npm run build", - "release_docs": "./release_docs.sh" + "release_docs": "./release_docs.sh", + "gulp": "gulp", + "cross-env": "cross-env" }, "jest": { "automock": true,