Skip to content

Commit 4ef6ee4

Browse files
lianghx-319levy9527
authored andcommitted
fix: release zip 包缺少了部分 rc 文件 (#107)
1 parent 114532b commit 4ef6ee4

File tree

8 files changed

+321
-55
lines changed

8 files changed

+321
-55
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ node_modules
33

44
# Logs
55
npm-debug.log
6+
*.log
67

78
# Coverage
89
coverage

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ git:
99
install:
1010
- yarn --frozen-lockfile
1111
script:
12-
- yarn test
12+
# 先 build 再 test 是因为需要测试 zip 脚本的 glob files 是否符合预期
1313
- yarn build:release
14+
- yarn test
1415
- yarn deploy
1516
cache:
1617
- yarn

bin/zip.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,51 @@
11
const fs = require('fs')
22
const path = require('path')
3+
// eslint-disable-next-line node/no-unpublished-require
34
const archiver = require('archiver')
45
const glob = require('glob')
56

67
const releaseDir = path.join(__dirname, '../release')
78

89
const zipDirList = glob.sync('*', {
910
cwd: releaseDir,
10-
ignore: '*.zip'
11+
ignore: '*.zip',
1112
})
1213

14+
const zipFileGlobOptions = source => ({
15+
cwd: source,
16+
dot: true,
17+
ignore: ['node_modules/**', 'dist/**', '.nuxt/**'],
18+
})
19+
20+
function mockZip(source) {
21+
source = `${releaseDir}/${source}/`
22+
return glob.sync('**', zipFileGlobOptions(source))
23+
}
24+
1325
function zip(source, target) {
1426
const output = fs.createWriteStream(target)
1527
const archive = archiver('zip', {
16-
zlib: { level: 9 }
28+
zlib: {level: 9},
1729
})
1830

1931
// listen for all archive data to be written
2032
// 'close' event is fired only when a file descriptor is involved
21-
output.on('close', function () {
33+
output.on('close', function() {
2234
console.log(archive.pointer() + ' total bytes')
23-
console.log('archiver has been finalized and the output file descriptor has closed.')
35+
console.log(
36+
'archiver has been finalized and the output file descriptor has closed.',
37+
)
2438
})
2539

2640
// This event is fired when the data source is drained no matter what was the data source.
2741
// It is not part of this library but rather from the NodeJS Stream API.
2842
// @see: https://nodejs.org/api/stream.html#stream_event_end
29-
output.on('end', function () {
43+
output.on('end', function() {
3044
console.log('Data has been drained')
3145
})
3246

3347
// good practice to catch warnings (ie stat failures and other non-blocking errors)
34-
archive.on('warning', function (err) {
48+
archive.on('warning', function(err) {
3549
if (err.code === 'ENOENT') {
3650
// log warning
3751
} else {
@@ -41,26 +55,27 @@ function zip(source, target) {
4155
})
4256

4357
// good practice to catch this error explicitly
44-
archive.on('error', function (err) {
58+
archive.on('error', function(err) {
4559
throw err
4660
})
4761

4862
// pipe archive data to the file
4963
archive.pipe(output)
5064

5165
// append files from a sub-directory, putting its contents at the root of archive
52-
archive.glob('**', {
53-
cwd: source,
54-
ignore: ['node_modules/**', 'dist/**', '.nuxt/**']
55-
})
66+
archive.glob('**', zipFileGlobOptions(source))
5667

5768
// finalize the archive (ie we are done appending files but streams have to finish yet)
5869
// 'close', 'end' or 'finish' may be fired right after calling this method so register to them beforehand
5970
archive.finalize()
6071
}
6172

62-
zipDirList.forEach((source) => {
73+
zipDirList.forEach(source => {
6374
const target = `${releaseDir}/${source}.zip`
6475
source = `${releaseDir}/${source}/`
6576
zip(source, target)
6677
})
78+
79+
module.exports = {
80+
mockZip,
81+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
},
3737
"devDependencies": {
3838
"@semantic-release/github": "semantic-release/github",
39-
"archiver": "^3.0.0",
39+
"archiver": "3.0.0",
4040
"ava": "^1.2.1",
4141
"babel-eslint": "^10.0.3",
4242
"eslint": "^6.5.1",

test/index.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import ava from 'ava'
33
import sao from 'sao'
44
import configs from '../template.config'
5+
import {mockZip} from '../bin/zip'
56
/* eslint-enable */
67

78
const getPkgFields = pkg => {
@@ -15,6 +16,7 @@ const verifyPkg = async (t, answers) => {
1516
const generator = require('path').resolve(__dirname, '../generator')
1617
const stream = await sao.mock({generator}, answers)
1718
const pkg = await stream.readFile('package.json')
19+
t.snapshot(mockZip(answers.folder), 'Zip files')
1820
t.snapshot(stream.fileList, 'Generated files')
1921
t.snapshot(getPkgFields(pkg), 'package.json')
2022
}

test/snapshots/index.test.js.md

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,80 @@ Generated by [AVA](https://ava.li).
66

77
## mobile
88

9+
> Zip files
10+
11+
[
12+
'.babelrc',
13+
'.editorconfig',
14+
'.eslintrc.js',
15+
'.gitignore',
16+
'.gitlab-ci.yml',
17+
'.grenrc.js',
18+
'.npmignore',
19+
'.prettierrc',
20+
'.stylelintrc',
21+
'commitlint.config.js',
22+
'nuxt.config.js',
23+
'package.json',
24+
'postcss.config.js',
25+
'README.md',
26+
'src',
27+
'src/assets',
28+
'src/assets/global.less',
29+
'src/assets/icon.png',
30+
'src/assets/README.md',
31+
'src/assets/reset.less',
32+
'src/assets/var.less',
33+
'src/components',
34+
'src/components/agreement.vue',
35+
'src/components/copyright.vue',
36+
'src/components/header-nav-bar.vue',
37+
'src/components/icon-font.vue',
38+
'src/components/logo.vue',
39+
'src/components/README.md',
40+
'src/const',
41+
'src/const/cookie-keys.js',
42+
'src/const/meta.js',
43+
'src/const/path.js',
44+
'src/layouts',
45+
'src/layouts/default.vue',
46+
'src/layouts/layout-with-footer.vue',
47+
'src/layouts/login.vue',
48+
'src/layouts/README.md',
49+
'src/middleware',
50+
'src/middleware/auth-ssr.js',
51+
'src/middleware/auth.js',
52+
'src/middleware/meta.js',
53+
'src/middleware/README.md',
54+
'src/pages',
55+
'src/pages/cart.vue',
56+
'src/pages/goods-detail.vue',
57+
'src/pages/index.vue',
58+
'src/pages/login.vue',
59+
'src/pages/my.vue',
60+
'src/pages/order-list.vue',
61+
'src/pages/README.md',
62+
'src/plugins',
63+
'src/plugins/axios.js',
64+
'src/plugins/filters.js',
65+
'src/plugins/icon-font.js',
66+
'src/plugins/README.md',
67+
'src/plugins/vant.js',
68+
'src/static',
69+
'src/static/favicon.ico',
70+
'src/static/icon.png',
71+
'src/static/README.md',
72+
'src/store',
73+
'src/store/index.js',
74+
'src/store/README.md',
75+
'src/utils',
76+
'src/utils/index.js',
77+
'test',
78+
'test/filters.test.js',
79+
'test/getRouterBase.test.js',
80+
'yarn.lock',
81+
]
82+
983
> Generated files
1084
1185
[
@@ -167,6 +241,88 @@ Generated by [AVA](https://ava.li).
167241

168242
## multiple
169243

244+
> Zip files
245+
246+
[
247+
'.babelrc',
248+
'.editorconfig',
249+
'.eslintrc.js',
250+
'.gitignore',
251+
'.gitlab-ci.yml',
252+
'.grenrc.js',
253+
'.npmignore',
254+
'.prettierrc',
255+
'.stylelintignore',
256+
'.stylelintrc',
257+
'commitlint.config.js',
258+
'nuxt.config.js',
259+
'package.json',
260+
'README.md',
261+
'src',
262+
'src/assets',
263+
'src/assets/export.less',
264+
'src/assets/global.less',
265+
'src/assets/README.md',
266+
'src/assets/reset.less',
267+
'src/assets/var.less',
268+
'src/components',
269+
'src/components/copyright.vue',
270+
'src/components/go-back.vue',
271+
'src/components/icon-font.vue',
272+
'src/components/layout-head.vue',
273+
'src/components/logo.vue',
274+
'src/components/menu-item.vue',
275+
'src/components/README.md',
276+
'src/components/route-tab.vue',
277+
'src/components/scrollbar',
278+
'src/components/scrollbar/bar.js',
279+
'src/components/scrollbar/index.js',
280+
'src/components/scrollbar/index.less',
281+
'src/components/scrollbar/utils',
282+
'src/components/scrollbar/utils/resize-event.js',
283+
'src/components/scrollbar/utils/scrollbar-width.js',
284+
'src/components/scrollbar/utils/util.js',
285+
'src/components/sidebar.vue',
286+
'src/const',
287+
'src/const/api.js',
288+
'src/const/cookie-keys.js',
289+
'src/const/meta.js',
290+
'src/const/path.js',
291+
'src/layouts',
292+
'src/layouts/default.vue',
293+
'src/layouts/login.vue',
294+
'src/layouts/README.md',
295+
'src/middleware',
296+
'src/middleware/auth-ssr.js',
297+
'src/middleware/auth.js',
298+
'src/middleware/meta.js',
299+
'src/middleware/README.md',
300+
'src/pages',
301+
'src/pages/_.vue',
302+
'src/pages/index.vue',
303+
'src/pages/login.vue',
304+
'src/pages/README.md',
305+
'src/plugins',
306+
'src/plugins/axios.js',
307+
'src/plugins/element.js',
308+
'src/plugins/filters.js',
309+
'src/plugins/icon-font.js',
310+
'src/plugins/README.md',
311+
'src/static',
312+
'src/static/favicon.ico',
313+
'src/static/icon.png',
314+
'src/static/README.md',
315+
'src/store',
316+
'src/store/index.js',
317+
'src/store/README.md',
318+
'src/utils',
319+
'src/utils/index.js',
320+
'test',
321+
'test/filters.test.js',
322+
'test/getRouterBase.test.js',
323+
'yarn.lock',
324+
]
325+
170326
> Generated files
171327
172328
[
@@ -336,6 +492,75 @@ Generated by [AVA](https://ava.li).
336492

337493
## single
338494

495+
> Zip files
496+
497+
[
498+
'.babelrc',
499+
'.editorconfig',
500+
'.eslintrc.js',
501+
'.gitignore',
502+
'.gitlab-ci.yml',
503+
'.grenrc.js',
504+
'.npmignore',
505+
'.prettierrc',
506+
'.stylelintrc',
507+
'commitlint.config.js',
508+
'nuxt.config.js',
509+
'package.json',
510+
'README.md',
511+
'src',
512+
'src/assets',
513+
'src/assets/global.less',
514+
'src/assets/README.md',
515+
'src/assets/reset.less',
516+
'src/assets/var.less',
517+
'src/components',
518+
'src/components/copyright.vue',
519+
'src/components/go-back.vue',
520+
'src/components/icon-font.vue',
521+
'src/components/logo.vue',
522+
'src/components/menu-item.vue',
523+
'src/components/README.md',
524+
'src/components/route-tab.vue',
525+
'src/const',
526+
'src/const/api.js',
527+
'src/const/cookie-keys.js',
528+
'src/const/meta.js',
529+
'src/const/path.js',
530+
'src/layouts',
531+
'src/layouts/default.vue',
532+
'src/layouts/login.vue',
533+
'src/layouts/README.md',
534+
'src/middleware',
535+
'src/middleware/auth-ssr.js',
536+
'src/middleware/auth.js',
537+
'src/middleware/meta.js',
538+
'src/middleware/README.md',
539+
'src/pages',
540+
'src/pages/index.vue',
541+
'src/pages/login.vue',
542+
'src/pages/README.md',
543+
'src/plugins',
544+
'src/plugins/axios.js',
545+
'src/plugins/element.js',
546+
'src/plugins/filters.js',
547+
'src/plugins/icon-font.js',
548+
'src/plugins/README.md',
549+
'src/static',
550+
'src/static/favicon.ico',
551+
'src/static/icon.png',
552+
'src/static/README.md',
553+
'src/store',
554+
'src/store/index.js',
555+
'src/store/README.md',
556+
'src/utils',
557+
'src/utils/index.js',
558+
'test',
559+
'test/filters.test.js',
560+
'test/getRouterBase.test.js',
561+
'yarn.lock',
562+
]
563+
339564
> Generated files
340565
341566
[

test/snapshots/index.test.js.snap

1.36 KB
Binary file not shown.

0 commit comments

Comments
 (0)