1
const path = require('node:path')
2
const fse = require('fs-extra')
3
const zlib = require('zlib')
4
const { green, blue, red, magenta, grey, underline } = require('chalk')
6
const kebabRegex = /[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g
9
const { version } = require('../package.json')
11
process.on('exit', code => {
12
if (code === 0 && tableData.length > 0) {
13
const { table } = require('table')
15
tableData.sort((a, b) => {
16
return a[ 0 ] === b[ 0 ]
17
? a[ 1 ] < b[ 1 ] ? -1 : 1
18
: a[ 0 ] < b[ 0 ] ? -1 : 1
23
underline('Filename'),
28
const output = table(tableData, {
30
0: { alignment: 'right' },
31
1: { alignment: 'left' },
32
2: { alignment: 'right' },
33
3: { alignment: 'right' }
38
console.log(` Summary of Quasar v${ version }:`)
43
function getSize (code) {
44
return (code.length / 1024).toFixed(2) + 'kb'
47
module.exports.createFolder = function (folder) {
48
const dir = path.join(__dirname, '..', folder)
49
fse.ensureDirSync(dir)
52
function getDestinationInfo (dest) {
53
if (dest.endsWith('.json')) {
55
banner: grey('[json]'),
56
tableEntryType: grey('json'),
61
if (dest.endsWith('.js') || dest.endsWith('.mjs')) {
63
banner: green('[js] '),
64
tableEntryType: green('js'),
65
toTable: dest.indexOf('dist/quasar') > -1
69
if (dest.endsWith('.css') || dest.endsWith('.styl') || dest.endsWith('.sass')) {
71
banner: blue('[css] '),
72
tableEntryType: blue('css'),
77
if (dest.endsWith('.ts')) {
79
banner: magenta('[ts] '),
80
tableEntryType: magenta('ts'),
85
logError(`Unknown file type using buildUtils.writeFile: ${ dest }`)
89
module.exports.writeFile = function (dest, code, zip) {
90
const { banner, tableEntryType, toTable } = getDestinationInfo(dest)
92
const fileSize = getSize(code)
93
const filePath = path.relative(process.cwd(), dest)
95
return new Promise((resolve, reject) => {
96
function report (gzippedString, gzippedSize) {
97
console.log(`${ banner } ${ filePath.padEnd(49) } ${ fileSize.padStart(8) }${ gzippedString || '' }`)
111
fse.writeFile(dest, code, err => {
112
if (err) return reject(err)
114
zlib.gzip(code, (err, zipped) => {
115
if (err) return reject(err)
116
const size = getSize(zipped)
117
report(` (gzipped: ${ size.padStart(8) })`, size)
127
module.exports.readFile = function (file) {
128
return fse.readFileSync(file, 'utf-8')
131
module.exports.writeFileIfChanged = function (dest, newContent, zip) {
132
let currentContent = ''
134
currentContent = fse.readFileSync(dest, 'utf-8')
138
return newContent.split(/[\n\r]+/).join('\n') !== currentContent.split(/[\n\r]+/).join('\n')
139
? module.exports.writeFile(dest, newContent, zip)
143
module.exports.convertToCjs = function (content, banner = '') {
144
return banner + content
145
.replace(/export default {/, 'module.exports = {')
146
.replace(/import {/g, 'const {')
147
.replace(/} from '(.*)'/g, (_, pkg) => `} = require('${ pkg }')`)
150
function logError (err) {
151
console.error('\n' + red('[Error]'), err)
155
module.exports.logError = logError
157
module.exports.kebabCase = function (str) {
160
match => '-' + match.toLowerCase()
164
module.exports.clone = function clone (data) {
165
const str = JSON.stringify(data)
168
return JSON.parse(str)
172
const testFileRE = /test/
173
module.exports.filterTestFiles = file => testFileRE.test(file) === false