FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
ionic/.scripts/prepare.js at css-variable-docs-test · ModusCreateOrg/ionic · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
ModusCreateOrg
/
ionic
Public
forked from
ionic-team/ionic-framework
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
ionic
/
.scripts
/
prepare.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
223 lines (186 loc) · 6.09 KB
Breadcrumbs
ionic
/
.scripts
/
prepare.js
Copy path
File metadata and controls
223 lines (186 loc) · 6.09 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/**
* Deploy script adopted from https://github.com/sindresorhus/np
* MIT License (c) Sindre Sorhus (sindresorhus.com)
*/
const
chalk
=
require
(
'chalk'
)
;
const
execa
=
require
(
'execa'
)
;
const
inquirer
=
require
(
'inquirer'
)
;
const
Listr
=
require
(
'listr'
)
;
const
fs
=
require
(
'fs-extra'
)
;
const
semver
=
require
(
'semver'
)
;
const
common
=
require
(
'./common'
)
;
const
path
=
require
(
'path'
)
;
async
function
main
(
)
{
try
{
if
(
!
process
.
env
.
GH_TOKEN
)
{
throw
new
Error
(
'env.GH_TOKEN is undefined'
)
;
}
const
version
=
await
askVersion
(
)
;
// compile and verify packages
await
preparePackages
(
common
.
packages
,
version
)
;
console
.
log
(
`\nionic
${
version
}
prepared 🤖\n`
)
;
console
.
log
(
`Next steps:`
)
;
console
.
log
(
` Verify CHANGELOG.md`
)
;
console
.
log
(
` git commit -m "
${
version
}
"`
)
;
console
.
log
(
` npm run release\n`
)
;
}
catch
(
err
)
{
console
.
log
(
'\n'
,
chalk
.
red
(
err
)
,
'\n'
)
;
process
.
exit
(
1
)
;
}
}
async
function
askVersion
(
)
{
const
pkg
=
common
.
readPkg
(
'core'
)
;
const
oldVersion
=
pkg
.
version
;
const
prompts
=
[
{
type
:
'list'
,
name
:
'version'
,
message
:
'Select semver increment or specify new version'
,
pageSize
:
SEMVER_INCREMENTS
.
length
+
2
,
choices
:
SEMVER_INCREMENTS
.
map
(
inc
=>
(
{
name
:
`
${
inc
}
${
prettyVersionDiff
(
oldVersion
,
inc
)
}
`
,
value
:
inc
}
)
)
.
concat
(
[
new
inquirer
.
Separator
(
)
,
{
name
:
'Other (specify)'
,
value
:
null
}
]
)
,
filter
:
input
=>
isValidVersionInput
(
input
)
?
getNewVersion
(
oldVersion
,
input
)
:
input
}
,
{
type
:
'input'
,
name
:
'version'
,
message
:
'Version'
,
when
:
answers
=>
!
answers
.
version
,
filter
:
input
=>
isValidVersionInput
(
input
)
?
getNewVersion
(
pkg
.
version
,
input
)
:
input
,
validate
:
input
=>
{
if
(
!
isValidVersionInput
(
input
)
)
{
return
'Please specify a valid semver, for example, `1.2.3`. See http://semver.org'
;
}
else
if
(
!
common
.
isVersionGreater
(
oldVersion
,
input
)
)
{
return
`Version must be greater than
${
oldVersion
}
`
;
}
return
true
;
}
}
,
{
type
:
'confirm'
,
name
:
'confirm'
,
message
:
answers
=>
{
return
`Will bump from
${
chalk
.
cyan
(
oldVersion
)
}
to
${
chalk
.
cyan
(
answers
.
version
)
}
. Continue?`
;
}
}
]
;
const
{
version
}
=
await
inquirer
.
prompt
(
prompts
)
;
return
version
;
}
async
function
preparePackages
(
packages
,
version
)
{
// execution order matters
const
tasks
=
[
]
;
// check git is nice and clean local and remote
common
.
checkGit
(
tasks
)
;
// test we're good with git
validateGit
(
tasks
,
version
)
;
// add all the prepare scripts
// run all these tasks before updating package.json version
packages
.
forEach
(
package
=>
{
common
.
preparePackage
(
tasks
,
package
,
version
)
;
}
)
;
// add update package.json of each project
packages
.
forEach
(
package
=>
{
updatePackageVersion
(
tasks
,
package
,
version
)
;
}
)
;
// generate changelog
generateChangeLog
(
tasks
)
;
// update core readme with version number
updateCoreReadme
(
tasks
,
version
)
;
const
listr
=
new
Listr
(
tasks
,
{
showSubtasks
:
true
}
)
;
await
listr
.
run
(
)
;
}
function
validateGit
(
tasks
,
version
)
{
tasks
.
push
(
{
title
:
`Validate git tag
${
chalk
.
dim
(
`(v
${
version
}
)`
)
}
`
,
task
:
(
)
=>
execa
(
'git'
,
[
'fetch'
]
)
.
then
(
(
)
=>
{
return
execa
.
stdout
(
'npm'
,
[
'config'
,
'get'
,
'tag-version-prefix'
]
)
;
}
)
.
then
(
output
=>
{
tagPrefix
=
output
;
}
,
(
)
=>
{
}
)
.
then
(
(
)
=>
execa
.
stdout
(
'git'
,
[
'rev-parse'
,
'--quiet'
,
'--verify'
,
`refs/tags/
${
tagPrefix
}
${
version
}
`
]
)
)
.
then
(
output
=>
{
if
(
output
)
{
throw
new
Error
(
`Git tag \`
${
tagPrefix
}
${
version
}
\` already exists.`
)
;
}
}
,
err
=>
{
// Command fails with code 1 and no output if the tag does not exist, even though `--quiet` is provided
// https://github.com/sindresorhus/np/pull/73#discussion_r72385685
if
(
err
.
stdout
!==
''
||
err
.
stderr
!==
''
)
{
throw
err
;
}
}
)
}
,
)
;
}
function
updatePackageVersion
(
tasks
,
package
,
version
)
{
const
projectRoot
=
common
.
projectPath
(
package
)
;
const
pkg
=
common
.
readPkg
(
package
)
;
tasks
.
push
(
{
title
:
`
${
pkg
.
name
}
: update package.json
${
chalk
.
dim
(
`(
${
version
}
)`
)
}
`
,
task
:
async
(
)
=>
{
await
execa
(
'npm'
,
[
'version'
,
version
]
,
{
cwd
:
projectRoot
}
)
;
}
}
)
;
}
function
generateChangeLog
(
tasks
)
{
tasks
.
push
(
{
title
:
`Generate CHANGELOG.md`
,
task
:
(
)
=>
execa
(
'npm'
,
[
'run'
,
'changelog'
]
,
{
cwd
:
common
.
rootDir
}
)
,
}
)
;
}
function
updateCoreReadme
(
tasks
,
version
)
{
tasks
.
push
(
{
title
:
`Update core README.md`
,
task
:
(
)
=>
execa
(
'node'
,
[
'update-readme.js'
,
version
]
,
{
cwd
:
path
.
join
(
common
.
rootDir
,
'core'
,
'scripts'
)
}
)
,
}
)
;
}
const
SEMVER_INCREMENTS
=
[
'patch'
,
'minor'
,
'major'
]
;
const
isValidVersionInput
=
input
=>
SEMVER_INCREMENTS
.
indexOf
(
input
)
!==
-
1
||
common
.
isValidVersion
(
input
)
;
function
getNewVersion
(
oldVersion
,
input
)
{
if
(
!
isValidVersionInput
(
input
)
)
{
throw
new
Error
(
`Version should be either
${
SEMVER_INCREMENTS
.
join
(
', '
)
}
or a valid semver version.`
)
;
}
return
SEMVER_INCREMENTS
.
indexOf
(
input
)
===
-
1
?
input
:
semver
.
inc
(
oldVersion
,
input
)
;
}
;
function
prettyVersionDiff
(
oldVersion
,
inc
)
{
const
newVersion
=
getNewVersion
(
oldVersion
,
inc
)
.
split
(
'.'
)
;
oldVersion
=
oldVersion
.
split
(
'.'
)
;
let
firstVersionChange
=
false
;
const
output
=
[
]
;
for
(
let
i
=
0
;
i
<
newVersion
.
length
;
i
++
)
{
if
(
(
newVersion
[
i
]
!==
oldVersion
[
i
]
&&
!
firstVersionChange
)
)
{
output
.
push
(
`
${
chalk
.
dim
.
cyan
(
newVersion
[
i
]
)
}
`
)
;
firstVersionChange
=
true
;
}
else
if
(
newVersion
[
i
]
.
indexOf
(
'-'
)
>=
1
)
{
let
preVersion
=
[
]
;
preVersion
=
newVersion
[
i
]
.
split
(
'-'
)
;
output
.
push
(
`
${
chalk
.
dim
.
cyan
(
`
${
preVersion
[
0
]
}
-
${
preVersion
[
1
]
}
`
)
}
`
)
;
}
else
{
output
.
push
(
chalk
.
reset
.
dim
(
newVersion
[
i
]
)
)
;
}
}
return
output
.
join
(
chalk
.
reset
.
dim
(
'.'
)
)
;
}
main
(
)
;
Back
|
FazBrowse Home
|
New Git URL