MCPcopy
hub / github.com/vuejs/devtools-v6 / writeZip

Function writeZip

extension-zips.js:36–141  ·  view source on GitHub ↗
(fileName, packageDir)

Source from the content-addressed store, hash-verified

34 await writeZip('devtools-firefox.zip', 'shell-firefox')
35
36 async function writeZip(fileName, packageDir) {
37 // create a file to stream archive data to.
38 const output = fs.createWriteStream(path.join(__dirname, 'dist', fileName))
39 const archive = archiver('zip', {
40 zlib: { level: 9 }, // Sets the compression level.
41 })
42
43 if (!IS_CI) {
44 const status = {
45 total: 0,
46 cFile: '...',
47 cSize: '0 Bytes',
48 tBytes: 0,
49 tSize: '0 Bytes',
50 }
51
52 async function parseFileStats() {
53 return new Promise((resolve, reject) => {
54 const globber = readDirGlob(path.join('packages', packageDir), { pattern: INCLUDE_GLOBS, skip: SKIP_DIR_GLOBS, mark: true, stat: true })
55 globber.on('match', (match) => {
56 if (!match.stat.isDirectory()) {
57 status.total++
58 }
59 })
60 globber.on('error', (err) => {
61 reject(err)
62 })
63 globber.on('end', () => {
64 resolve()
65 })
66 })
67 }
68 await parseFileStats().catch((err) => {
69 console.error(err)
70 process.exit(1)
71 })
72
73 const bar = new ProgressBar(`${fileName} @ :tSize [:bar] :current/:total :percent +:cFile@:cSize`, {
74 width: 18,
75 incomplete: ' ',
76 total: status.total,
77 })
78 bar.tick(0, status)
79
80 archive.on('entry', (entry) => {
81 if (!entry.stats.isDirectory()) {
82 const n = entry.name
83 status.written++
84 status.cFile = n.length > 14
85 ? `...${n.slice(n.length - 11)}`
86 : n
87 status.cSize = bytesToSize(entry.stats.size)
88 status.tBytes += entry.stats.size
89 status.tSize = bytesToSize(status.tBytes)
90 bar.tick(1, status)
91 }
92 })
93 }

Callers 1

extension-zips.jsFile · 0.85

Calls 3

parseFileStatsFunction · 0.85
bytesToSizeFunction · 0.85
onMethod · 0.80

Tested by

no test coverage detected