|
2 | 2 | # Usage: bash publish.sh --build-only --emit
|
3 | 3 |
|
4 | 4 | set -e # -x
|
5 |
| -dir=$(pwd); |
6 |
| -bash_args="$@"; |
7 |
| -prefix="doc-editor-"; |
8 |
| -packages=(delta utils core plugin); |
| 5 | +dir=$(pwd) |
| 6 | +bash_args="$@" |
| 7 | +prefix="doc-editor-" |
| 8 | +packages=(delta utils core plugin) |
9 | 9 | # npm version patch --no-git-tag-version
|
10 |
| -version=`echo "console.log(require(\"./package.json\").version)" | node`; |
| 10 | +version=$(echo "console.log(require(\"./package.json\").version)" | node) |
11 | 11 |
|
12 | 12 | function check_argument {
|
13 |
| - local value=$1; |
| 13 | + local value=$1 |
14 | 14 | for arg in $bash_args; do
|
15 |
| - if [ "$arg" == "$value" ] ; then |
16 |
| - return 0; # success |
| 15 | + if [ "$arg" == "$value" ]; then |
| 16 | + return 0 # success |
17 | 17 | fi
|
18 | 18 | done
|
19 |
| - return 1; # failure |
| 19 | + return 1 # failure |
20 | 20 | }
|
21 | 21 |
|
22 | 22 | function echo_notice {
|
23 |
| - local value=$1; |
| 23 | + local value=$1 |
24 | 24 | echo -e "\033[32m$value\033[0m"
|
25 | 25 | }
|
26 | 26 |
|
27 |
| -echo_notice "Version: $version"; |
| 27 | +echo_notice "Version: $version" |
28 | 28 |
|
29 | 29 | if ! check_argument "--emit" || check_argument "--build-only"; then
|
30 |
| - echo_notice "Notice: Current Version Will Not Publish To NPM"; |
| 30 | + echo_notice "Notice: Current Version Will Not Publish To NPM" |
31 | 31 | fi
|
32 | 32 |
|
33 | 33 | for item in "${packages[@]}"; do
|
34 |
| - cd $dir; |
35 |
| - path="./packages/$item"; |
36 |
| - cd $path; |
37 |
| - npm run build |
| 34 | + cd $dir |
| 35 | + path="./packages/$item" |
| 36 | + cd $path |
| 37 | + npm run build |
38 | 38 | done
|
39 | 39 |
|
40 | 40 | if check_argument "--build-only"; then
|
41 |
| - exit 0; |
| 41 | + exit 0 |
42 | 42 | fi
|
43 | 43 |
|
44 | 44 | for item in "${packages[@]}"; do
|
45 |
| - cd $dir; |
46 |
| - path="./packages/$item"; |
47 |
| - cd $path; |
48 |
| - echo "const fs = require('fs'); |
| 45 | + cd $dir |
| 46 | + path="./packages/$item" |
| 47 | + cd $path |
| 48 | + echo "const fs = require('fs'); |
49 | 49 | const json = require('./package.json');
|
50 | 50 | json.version = '$version';
|
51 | 51 | const dep = json.dependencies || {};
|
52 | 52 | for(const [key, value] of Object.entries(dep)) {
|
53 | 53 | if(key.startsWith('$prefix')) dep[key] = '$version';
|
54 | 54 | }
|
55 | 55 | fs.writeFileSync('./package.json', JSON.stringify(json, null, 2));
|
56 |
| - " | node; |
57 |
| - set +e; |
58 |
| - if check_argument "--emit"; then |
59 |
| - npm publish --registry=https://registry.npmjs.org/ |
60 |
| - else |
61 |
| - npm publish --registry=https://registry.npmjs.org/ --dry-run |
62 |
| - fi |
63 |
| - set -e; |
64 |
| - echo "const fs = require('fs'); |
| 56 | + " | node |
| 57 | + set +e |
| 58 | + if check_argument "--emit"; then |
| 59 | + npm publish --registry=https://registry.npmjs.org/ |
| 60 | + else |
| 61 | + npm publish --registry=https://registry.npmjs.org/ --dry-run |
| 62 | + fi |
| 63 | + set -e |
| 64 | + echo "const fs = require('fs'); |
65 | 65 | const json = require('./package.json');
|
66 | 66 | json.version = '1.0.0';
|
67 | 67 | const dep = json.dependencies || {};
|
68 | 68 | for(const [key, value] of Object.entries(dep)) {
|
69 | 69 | if(key.startsWith('$prefix')) dep[key] = 'workspace: *';
|
70 | 70 | }
|
71 | 71 | fs.writeFileSync('./package.json', JSON.stringify(json, null, 2));
|
72 |
| - " | node; |
| 72 | + " | node |
73 | 73 | done
|
0 commit comments