1 | const
|
2 | fs = require('fs'),
|
3 | path = require('path'),
|
4 | fse = require('fs-extra')
|
5 |
|
6 | const
|
7 | appPaths = require('./app-paths'),
|
8 | filePath = appPaths.resolve.app('.quasar/artifacts.json'),
|
9 | log = require('./helpers/logger')('app:artifacts')
|
10 |
|
11 | function exists () {
|
12 | return fs.existsSync(filePath)
|
13 | }
|
14 |
|
15 | function getArtifacts () {
|
16 | return exists()
|
17 | ? require(filePath)
|
18 | : { folders: [] }
|
19 | }
|
20 |
|
21 | function save (content) {
|
22 | fse.mkdirp(path.dirname(filePath))
|
23 | fs.writeFileSync(filePath, JSON.stringify(content), 'utf-8')
|
24 | }
|
25 |
|
26 | module.exports.add = function (entry) {
|
27 | const content = getArtifacts()
|
28 |
|
29 | if (!content.folders.includes(entry)) {
|
30 | content.folders.push(entry)
|
31 | save(content)
|
32 | log(`Added build artifact "${entry}"`)
|
33 | }
|
34 | }
|
35 |
|
36 | module.exports.clean = function (folder) {
|
37 | if (folder.endsWith(path.join('src-cordova', 'www'))) {
|
38 | fse.emptyDirSync(folder)
|
39 | }
|
40 | else {
|
41 | fse.removeSync(folder)
|
42 | }
|
43 |
|
44 | log(`Cleaned build artifact: "${folder}"`)
|
45 | }
|
46 |
|
47 | module.exports.cleanAll = function () {
|
48 | getArtifacts().folders.forEach(folder => {
|
49 | if (folder.endsWith(path.join('src-cordova', 'www'))) {
|
50 | fse.emptyDirSync(folder)
|
51 | }
|
52 | else {
|
53 | fse.removeSync(folder)
|
54 | }
|
55 |
|
56 | log(`Cleaned build artifact: "${folder}"`)
|
57 | })
|
58 |
|
59 | let folder = appPaths.resolve.app('.quasar')
|
60 | fse.removeSync(folder)
|
61 | log(`Cleaned build artifact: "${folder}"`)
|
62 |
|
63 | fse.emptyDirSync(appPaths.resolve.app('dist'))
|
64 | log(`Emptied dist folder`)
|
65 | }
|