-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.ts
106 lines (86 loc) · 2.12 KB
/
index.ts
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
#!/usr/bin/env node
import { mkdtempSync, writeFileSync } from 'fs'
import { pick } from 'lodash'
import { resolve } from 'path'
import { exec } from 'shelljs'
const pkg = require(resolve('package.json'))
const CWD = resolve()
const DIST_PATH = resolve(process.env.DIST_PATH || 'dist')
const SYNC_PATH = resolve('node_modules/.sync')
const PKG_PATH = resolve(SYNC_PATH, pkg.name)
const PKG_PATH_WITH_VERSION = resolve(SYNC_PATH, pkg.name, pkg.version)
const PKG_TEMP_DIR = mkdtempSync(SYNC_PATH)
const PKG_TEMP_PATH = resolve(PKG_TEMP_DIR, 'package.json')
writeFileSync(
PKG_TEMP_PATH,
JSON.stringify(
pick(
pkg,
'name',
'version',
'description',
'repository',
'author',
'license',
'dependencies',
'devDependencies',
),
null,
2,
),
)
exec(`
#!/usr/bin/env bash
set -e
rm -rf ${SYNC_PATH}
main() {
git log -1 --pretty=%B | cat |
if read -r MESSAGE
then
echo "last commit message:"
echo "$MESSAGE"
local CREATED=1
{
git clone https://user:[email protected]/1stg/modules.git ${SYNC_PATH} -b gh-pages
} || {
echo "branch \\\`gh-pages\\\` has not been created"
CREATED=0
mkdir ${SYNC_PATH}
cd ${SYNC_PATH}
git init
git checkout -b gh-pages
git remote add origin https://user:[email protected]/1stg/modules.git
cd ..
}
mkdir -p ${PKG_PATH_WITH_VERSION}
cd ${PKG_PATH}
find . -maxdepth 1 -type f -exec rm -iv {} \\\;
cp -rf ${DIST_PATH}/* .
cp ${CWD}/*.md .
cp ${PKG_TEMP_PATH} ./package.json
rm -rf ${PKG_PATH_WITH_VERSION}/*
cd ${PKG_PATH_WITH_VERSION}
cp -rf ${DIST_PATH}/* .
cp ${CWD}/*.md .
cp ${PKG_TEMP_PATH} ./package.json
rm -rf ${PKG_TEMP_DIR}
git add -A
git status -s |
if read
then
git commit -m "$MESSAGE"
if [ "$CREATED" == "1" ]
then
git push --quiet
else
echo "first push, create \\\`gh-pages\\\` branch"
git push --quiet --set-upstream origin gh-pages
fi
else
echo "there is nothing changed to commit"
fi
rm -rf ${SYNC_PATH}
fi
}
main
`)