forked from samizdatco/skia-canvas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.js
95 lines (79 loc) · 2.49 KB
/
upload.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const childProcess = require('child_process')
const fs = require('fs')
const path = require('path')
const util = require('util')
const nopt = require('nopt');
const versioning = require('@mapbox/node-pre-gyp/lib/util/versioning.js')
const OSS = require('ali-oss')
const execAsync = util.promisify(childProcess.exec)
const readFileAsync = util.promisify(fs.readFile)
const configDefs = {
help: Boolean, // everywhere
arch: String, // 'configure'
debug: Boolean, // 'build'
directory: String, // bin
proxy: String, // 'install'
loglevel: String // everywhere
};
/**
* nopt shorthands
*/
const shorthands = {
release: '--no-debug',
C: '--directory',
debug: '--debug',
j: '--jobs',
silent: '--loglevel=silent',
silly: '--loglevel=silly',
verbose: '--loglevel=verbose'
};
const ALI_ACCESS_KEY_ID = process.env.ALI_ACCESS_KEY_ID
const ALI_SECRET_ACCESS_KEY = process.env.ALI_SECRET_ACCESS_KEY
const main = async () => {
const buffer = await readFileAsync(path.resolve(__dirname, 'package.json'))
const pkg = JSON.parse(buffer.toString())
await upload(pkg)
}
main().catch((e) => {
console.error(e)
process.exit(1)
})
const upload = async (pkg) => {
const gypOpts = nopt(configDefs, shorthands);
const npm_config_prefix = 'npm_config_';
Object.keys(process.env).forEach((name) => {
if (name.indexOf(npm_config_prefix) !== 0) return;
const val = process.env[name];
if (name !== npm_config_prefix + 'loglevel') {
// add the user-defined options to the config
name = name.substring(npm_config_prefix.length);
// avoid npm argv clobber already present args
// which avoids problem of 'npm test' calling
// script that runs unique npm install commands
if (name === 'argv') {
if (gypOpts.argv &&
gypOpts.argv.remain &&
gypOpts.argv.remain.length) {
// do nothing
} else {
gypOpts[name] = val;
}
} else {
gypOpts[name] = val;
}
}
})
const opts = versioning.evaluate(pkg, gypOpts, 6);
const tarball = opts.staged_tarball;
const client = new OSS({
region: 'oss-cn-hangzhou',
accessKeyId: ALI_ACCESS_KEY_ID,
accessKeySecret: ALI_SECRET_ACCESS_KEY,
bucket: 'arkie-mirror'
})
try{
const result = await client.put("/skia-canvas" + `${opts.remote_path}${opts.package_name}`.slice(1), __dirname + "/" + tarball);
}catch(e){
console.error(e)
}
}