-
Notifications
You must be signed in to change notification settings - Fork 39
/
publish.sh
executable file
·73 lines (65 loc) · 1.8 KB
/
publish.sh
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
#!/bin/bash
# Usage: bash publish.sh --build-only --emit
set -e # -x
dir=$(pwd)
bash_args="$@"
prefix="doc-editor-"
packages=(delta utils core plugin)
# npm version patch --no-git-tag-version
version=$(echo "console.log(require(\"./package.json\").version)" | node)
function check_argument {
local value=$1
for arg in $bash_args; do
if [ "$arg" == "$value" ]; then
return 0 # success
fi
done
return 1 # failure
}
function echo_notice {
local value=$1
echo -e "\033[32m$value\033[0m"
}
echo_notice "Version: $version"
if ! check_argument "--emit" || check_argument "--build-only"; then
echo_notice "Notice: Current Version Will Not Publish To NPM"
fi
for item in "${packages[@]}"; do
cd $dir
path="./packages/$item"
cd $path
npm run build
done
if check_argument "--build-only"; then
exit 0
fi
for item in "${packages[@]}"; do
cd $dir
path="./packages/$item"
cd $path
echo "const fs = require('fs');
const json = require('./package.json');
json.version = '$version';
const dep = json.dependencies || {};
for(const [key, value] of Object.entries(dep)) {
if(key.startsWith('$prefix')) dep[key] = '$version';
}
fs.writeFileSync('./package.json', JSON.stringify(json, null, 2));
" | node
set +e
if check_argument "--emit"; then
npm publish --registry=https://registry.npmjs.org/
else
npm publish --registry=https://registry.npmjs.org/ --dry-run
fi
set -e
echo "const fs = require('fs');
const json = require('./package.json');
json.version = '1.0.0';
const dep = json.dependencies || {};
for(const [key, value] of Object.entries(dep)) {
if(key.startsWith('$prefix')) dep[key] = 'workspace: *';
}
fs.writeFileSync('./package.json', JSON.stringify(json, null, 2));
" | node
done