-
Notifications
You must be signed in to change notification settings - Fork 47
/
build.js
91 lines (74 loc) · 2.35 KB
/
build.js
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
const fs = require('fs')
const archiver = require('archiver')
const styleDictionary = require('./src/configuration/styleDictionary')
/**
* Reads in our design token files and
* Exports them depending on the outputs from
* design-tokens.config.json
* @returns {void}
*/
function buildDesignTokens() {
const StyleDictionary = styleDictionary.prepareStyleDictionary()
// APPLY THE CONFIGURATION
// IMPORTANT: the registration of custom transforms
// needs to be done _before_ applying the configuration
StyleDictionaryExtended = StyleDictionary.extend(
`${__dirname}/design-tokens.config.json`
)
// FINALLY, BUILD ALL THE PLATFORMS
StyleDictionaryExtended.buildAllPlatforms()
}
/**
* Generates our settings-templates zip file
* @returns {void}
*/
function buildSettingsTemplatesArchive() {
// create a file to stream archive data to.
const output = fs.createWriteStream(
`${__dirname}/settings-templates/settings-templates.zip`
)
const archive = archiver('zip')
archive.pipe(output)
// listen for all archive data to be written
// 'close' event is fired only when a file descriptor is involved
output.on('close', () => {
console.log(`${archive.pointer()} total bytes`)
console.log(
'archiver has been finalized and the output file descriptor has closed.'
)
})
// good practice to catch warnings (ie stat failures and other non-blocking errors)
archive.on('warning', (err) => {
if (err.code === 'ENOENT') {
console.log(err)
} else {
// throw error
throw err
}
})
// good practice to catch this error explicitly
archive.on('error', (err) => {
throw err
})
// append a file
archive.file('settings-templates/_color-palette.scss', {
name: 'settings-templates/_color-palette.scss',
})
archive.file('settings-templates/_harmonium-settings.scss', {
name: 'settings-templates/_harmonium-settings.scss',
})
archive.file('settings-templates/_harmonium-component-settings.scss', {
name: 'settings-templates/_harmonium-component-settings.scss',
})
archive.file('settings-templates/harmonium-tokens.js', {
name: 'settings-templates/harmonium-tokens.js',
})
archive.finalize()
}
function build() {
console.log('Building design token output')
buildDesignTokens()
console.log('Building settings-templates.zip')
buildSettingsTemplatesArchive()
}
build()