forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
deploy scripts #20
Open
yuedou
wants to merge
1
commit into
oppenfuture:dev
Choose a base branch
from
yuedou:dev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
deploy scripts #20
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
const { exec } = require('child_process') | ||
const fs = require('fs') | ||
const path = require('path') | ||
const OSS = require('ali-oss'); | ||
const pkg = require('./package.json') | ||
const { env } = require('process'); | ||
|
||
const config = { | ||
Version: env['Version'], | ||
REGION: env['REGION'], | ||
ACCESSKEYID: env['ACCESSKEYID'], | ||
ACCESSKEYSECRET: env['ACCESSKEYSECRET'], | ||
BUCKETNAME: env['BUCKETNAME'], | ||
GitSHA: env["GIT_COMMIT"], | ||
ThreeJSTag: env["ThreeJSTag"], | ||
TrackerJSTag: env["TrackerJSTag"], | ||
APIKey: env['APIKey'], | ||
APISecret: env['APISecret'], | ||
SkipNpmPublish: env['skipNpmPublish'] === 'true', | ||
}; | ||
|
||
const distPath = path.resolve(__dirname, 'build'); | ||
|
||
function checkAliOSSConfig(config) { | ||
const configItems = ['REGION', 'ACCESSKEYID', 'ACCESSKEYSECRET', 'BUCKETNAME'] | ||
const notConfigured = []; | ||
configItems.forEach((item) => { | ||
if (!Object.keys(config).includes(item)) { | ||
notConfigured.push(item); | ||
} | ||
}); | ||
|
||
if (notConfigured.length) { | ||
console.log(chalk.red(`检测到未进行配置: ${notConfigured},请在环境变量中配置此项`)) | ||
process.exit(4); | ||
} | ||
} | ||
|
||
function getOssJsFilePath(jsFileName) { | ||
return jsFileName; | ||
} | ||
|
||
function uploadAliOSS(config, uploadFileName) { | ||
console.log('上传阿里oss') | ||
checkAliOSSConfig(config); | ||
const { | ||
REGION, ACCESSKEYID, ACCESSKEYSECRET, BUCKETNAME, | ||
} = config; | ||
const localFilePath = (fileName) => `${path.resolve(distPath, fileName)}`; | ||
|
||
const client = new OSS({ | ||
region: REGION, | ||
accessKeyId: ACCESSKEYID, | ||
accessKeySecret: ACCESSKEYSECRET, | ||
bucket: BUCKETNAME, | ||
}); | ||
|
||
uploadFileName.forEach(async (file) => { | ||
try { | ||
const ossfile = getOssJsFilePath(file); | ||
const result = await client.put(`holodeck/js/${ossfile}`, localFilePath(file)); | ||
if (result.res.status === 200) { | ||
console.log(chalk.white(`${chalk.bgBlue(ossfile)} 上传成功!`)); | ||
} | ||
} catch (error) { | ||
console.log(chalk.red(`上传${file}出错::: ${error}`)); | ||
process.exit(5); | ||
} | ||
}); | ||
} | ||
|
||
const getRemoteTreeversion = () => { | ||
return new Promise((resolve, reject) => { | ||
exec(`npm view @oppentech/three | grep latest`, (err, res) => { | ||
const [_, version] = res.split(':') | ||
if (err) { | ||
reject(err) | ||
} | ||
resolve(version.trim()) | ||
}) | ||
}) | ||
} | ||
|
||
const compareVersion = (version, otherVersion) => { | ||
const [major, mirror, patch] = version.split('.') | ||
const [otherMajor, otherMirror, otherPatch] = otherVersion.split('.') | ||
|
||
if (major > otherMajor || mirror > otherMirror || patch > otherPatch) { | ||
return true; | ||
} | ||
|
||
return false | ||
} | ||
|
||
const checkVersion = async onlineVersion => { | ||
console.log('检查版本号...') | ||
const { version: localVersion } = pkg | ||
const compareResult = compareVersion(localVersion, onlineVersion) | ||
if (!compareResult) { | ||
console.error(`本地版本过低: 线上: ${onlineVersion}, 本地: ${localVersion}`) | ||
process.exit(1); | ||
} | ||
} | ||
|
||
const checkDevDependencies = () => { | ||
return fs.existsSync(path.resolve(__dirname, 'node_modules')) | ||
} | ||
|
||
const getFileMD5 = (url) => { | ||
return new Promise((resolve, reject) => { | ||
exec(`md5 ${url}`, (err, res) => { | ||
if (err) { | ||
reject(err) | ||
} | ||
const [_, result] = res.split('=') | ||
const [splitResult] = result.trim().match(/.{8}/) | ||
resolve(splitResult) | ||
}) | ||
}) | ||
} | ||
|
||
const buildThreeJSBundle = () => { | ||
return new Promise((resolve, reject) => { | ||
let command = 'npm run build' | ||
console.log('构建中...') | ||
if (!checkDevDependencies()) { | ||
command = 'npm i && npm run build' | ||
} | ||
exec(command, (err, result) => { | ||
if (err) { | ||
reject(err) | ||
} | ||
resolve(result) | ||
}) | ||
}) | ||
} | ||
|
||
const hashFileGenerator = async () => { | ||
console.log('生成文件hash...') | ||
const threeBundlePath = path.resolve(__dirname, 'build', 'three.js'); | ||
if (!threeBundlePath) { | ||
console.error('没有检测到生成文件') | ||
process.exit(2); | ||
} | ||
const md5 = await getFileMD5(threeBundlePath) | ||
return new Promise((resolve, reject) => { | ||
exec(`cp ${threeBundlePath} ${path.resolve(__dirname, 'build', 'three.' + md5 + '.js')}`, (err, res) => { | ||
if(err) { | ||
console.log(err); | ||
reject(err) | ||
} | ||
resolve(`three.${md5}.js`) | ||
}) | ||
}) | ||
} | ||
|
||
|
||
|
||
async function main() { | ||
const onlineVersion = await getRemoteTreeversion() | ||
checkVersion(onlineVersion) | ||
await buildThreeJSBundle() | ||
const hashedFile = await hashFileGenerator() | ||
uploadAliOSS(config, [hashedFile]) | ||
} | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@oppentech/three", | ||
"version": "0.115.0", | ||
"version": "0.115.3", | ||
"description": "JavaScript 3D library", | ||
"main": "build/three.js", | ||
"module": "build/three.module.js", | ||
|
@@ -9,7 +9,7 @@ | |
"type": "git", | ||
"url": "https://github.com/mrdoob/three.js" | ||
}, | ||
"sideEffects":[ | ||
"sideEffects": [ | ||
"src/Three.js" | ||
], | ||
"files": [ | ||
|
@@ -107,5 +107,8 @@ | |
"build/three.module.js" | ||
], | ||
"directories": {} | ||
}, | ||
"dependencies": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be dev-dependencies |
||
"ali-oss": "^6.15.2" | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these vars are not used