forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepublish.js
executable file
·109 lines (91 loc) · 2.64 KB
/
prepublish.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env node
//@ts-check
var p = require('child_process')
var path = require('path')
var fs = require('fs')
var assert = require('assert')
var root = path.join(__dirname, '..')
var root_config = { cwd: root, encoding: 'utf8' }
var json = require(path.join(root, 'package.json'))
var os = require('os')
function clean() {
console.log(`cleanning`)
p.execSync(`git clean -dfx . -e native/`, root_config)
}
function verifyIsCleanWorkTree() {
var output = p.execSync(`git status -uno`, root_config)
if (output.includes('nothing to commit')) {
console.log(`still clean tree`)
} else {
console.log(output)
console.log(`Error: not fixed point`)
process.exit(2)
}
}
function checkWinBinary(){
var assocs = ['bsppx', 'bsb', 'bsb_helper', 'refmt', 'bsc'].map(x=>{
return [x, { win32 : false, darwin : false}]
})
/**
* @type{Map<string,*>}
*/
// @ts-ignore
var files = new Map( assocs )
// check sound
var libDir = path.join(root,'lib')
fs.readdirSync(libDir).forEach(x=>{
var y = path.parse(x)
if(y.ext === '.win32'){
assert (files.has(y.name), `unknown ${x}`)
files.get(y.name).win32 = true
} else if(y.ext === '.darwin'){
assert (files.has(y.name), `unknown ${x}`)
files.get(y.name).darwin = true
}
})
// check complete
files.forEach(x => {
assert(x.win32, `${x}.win32 not available`)
assert(x.darwin, `${x}.darwin not available`)
} )
}
clean()
// require('./release').run()
// Not needed
verifyIsCleanWorkTree()
clean()
console.log(`start packing`)
p.execSync(`yarn pack`, root_config)
console.log(`finish packing`)
var tmpdir = 'tmp'
fs.mkdirSync(path.join(root, tmpdir))
p.execSync(`tar -xzf ${json.name}-v${json.version}.tgz -C ${tmpdir} `, root_config)
process.env.BS_ALWAYS_BUILD_YOUR_COMPILER = 'true'
var tmpdir_config = {
cwd: path.join(root, tmpdir, 'package'),
encoding: 'utf8', stdio: 'inherit'
}
console.log(`start installing`)
// @ts-ignore
p.execSync(`npm install`, tmpdir_config)
console.log(`finish installing`)
clean()
verifyIsCleanWorkTree()
console.log(`okay to publish`)
if(!process.argv.includes('-weekly')){
console.log(`checking windows`)
checkWinBinary()
}
/**
*
* @param {string} data
*/
function pbcopy(data) {
var proc = require('child_process').spawn('pbcopy');
proc.stdin.write(data); proc.stdin.end();
}
var publishCommand = `yarn publish --network-timeout 100000000 --tag ${json.version}`
console.log(`please run: \n${publishCommand}`)
if(os.platform() === 'darwin'){
pbcopy(publishCommand)
}