Skip to content

Commit

Permalink
feat: impl json format
Browse files Browse the repository at this point in the history
  • Loading branch information
yarastqt committed Apr 27, 2020
1 parent ccf19c8 commit 951109f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/core/formats.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cssTemplate, esmTemplate } from './templates'
import { cssTemplate, esmTemplate, jsonTemplate } from './templates'

function getFileNameWithPlatform(fileName: string, platform: string, extension: string): string {
if (platform === 'common') {
Expand Down Expand Up @@ -43,6 +43,20 @@ export const formats: Formats = {
}
return result
},
'json.whitepaper': (platforms) => {
const result = []
for (const platform in platforms) {
const layers = platforms[platform]
for (const layer in layers) {
const { name, tokens } = layers[layer]
result.push({
fileName: getFileNameWithPlatform(name, platform, 'json'),
content: jsonTemplate(tokens),
})
}
}
return result
},
'js.esm': (platforms, options) => {
const result = []
for (const platform in platforms) {
Expand Down
6 changes: 5 additions & 1 deletion src/core/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ export function esmTemplate(tokens: FlattenToken[]): string {
result += generateFileHeader()
for (const token of tokens) {
if (token.comment !== undefined) {
result += `// ${token.comment}\n`
result += `/** ${token.comment} */\n`
}
result += `export const ${token.name} = '${token.value}';\n`
}
return result
}

export function jsonTemplate(tokens: FlattenToken[]): string {
return JSON.stringify(tokens, null, 2)
}

0 comments on commit 951109f

Please sign in to comment.