Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
package-lock.json
*.lock
63 changes: 36 additions & 27 deletions cli/bin/glyphs-add
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env node

const parseArgs = require('minimist')
const { Client: figmaClient } = require('figma-js')
const inquirer = require('inquirer')
const { log, PRINT } = require('../utils/logger')
const { conf, localConfigs, hasConfig } = require('../utils/config')

const args = process.argv.slice(2)
const argv = parseArgs(args, {
Expand All @@ -20,18 +23,13 @@ if (argv.help) {
process.exit()
}

const { Client: figmaClient } = require('figma-js')
const inquirer = require('inquirer')
const { conf, configs, hasConfig } = require('../utils/config')
const { snakeCase } = require('lodash')

let { key, token, replace } = argv
let { key, token, replace, _: [query] } = argv

;(async () => {
// no key or token provided to console - give prompt
if (!key || !token) {
if (hasConfig) {
const firstSet = Object.values(configs)[0] || {}
const firstSet = Object.values(localConfigs)[0] || {}
token = firstSet.token
}

Expand All @@ -51,29 +49,40 @@ let { key, token, replace } = argv

if (!key || !token) {
PRINT.ADD.FAIL()
} else {
if (hasConfig) {
const [setEntries] = Object.entries(configs).filter(([name, { key: k }]) => k === key)
const name = setEntries && setEntries[0]
if (name && !replace) {
PRINT.ADD.CONFLICT({ name })
process.exit(1)
}
}
log()
process.exit(1)
}

const { client: figma } = figmaClient({ personalAccessToken: token })
const file = await figma.get(`files/${key}`).then(({ data }) => data).catch(err => {
const error = err.toJSON()
log()
log(error.message, 1)
log()
if (hasConfig) {
const [sets] = Object.entries(localConfigs).filter(([name, { key: k }]) => k === key)
const name = sets && sets[0]
if (name && !replace) {
PRINT.ADD.CONFLICT({ name })
process.exit(1)
})
const sets = file.document.children
.reduce((obj, { name }) => ({ ...obj, [name]: null }), {})
}
}

const { client: figma } = figmaClient({ personalAccessToken: token })
const file = await figma.get(`files/${key}`).then(({ data }) => data).catch(err => {
const error = err.toJSON()
log()
log(error.message, 1)
log()
process.exit(1)
})

const choices = file.document.children.map(({ id: value, name }) => ({ value, name }))
const pageQuestion = [{ type: 'list', name: 'name', message: 'Select the page containing your icons', choices }]
const { name: page } = await inquirer.prompt(pageQuestion)

conf.set(key, { token, key, name: file.name, sets: sets })
PRINT.ADD.SUCCESS(({ name: file.name }))
const saveConfig = {
name: file.name,
key,
token,
page,
updatedAt: null
}
conf.set(key, saveConfig)
PRINT.ADD.SUCCESS(({ name: file.name }))
log()
})()
15 changes: 5 additions & 10 deletions cli/bin/glyphs-generate
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env node

const parseArgs = require('minimist')
const path = require('path')
const inquirer = require('inquirer')
const { log, fatal, PRINT } = require('../utils/logger')

const args = process.argv.slice(2)
Expand All @@ -16,18 +18,11 @@ if (argv.help) {
process.exit()
}

const path = require('path')
const inquirer = require('inquirer')

;(async () => {
const glyphsConfig = require(path.join(process.cwd(), 'glyphs.config.js'))

if (!glyphsConfig || !glyphsConfig.generate) {
throw new Error(`A config file wasn't supplied.`)
}
const glyphsConfig = { generate: {} }

const { target } = glyphsConfig.generate
const targets = ['wc', 'vue', 'react']
const targets = ['json', 'font', 'symbols', 'components']

log()

Expand All @@ -46,7 +41,7 @@ const inquirer = require('inquirer')
]

const answers = await inquirer.prompt(questions)
key = answers.name
glyphsConfig.generate.target = answers.name
}

try {
Expand Down
10 changes: 5 additions & 5 deletions cli/bin/glyphs-get
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if (argv.help) {
}

const inquirer = require('inquirer')
const { configs, hasConfig } = require('../utils/config')
const { localConfigs, hasConfig } = require('../utils/config')

const { _: [query] } = argv

Expand All @@ -31,9 +31,9 @@ const { _: [query] } = argv

if (!query && hasConfig) {
let key
const choices = Object.entries(configs).map(([key, { name }]) => ({ value: key, name }))
const choices = Object.entries(localConfigs).map(([key, { name }]) => ({ value: key, name }))

if (Object.keys(configs).length === 1) {
if (Object.keys(localConfigs).length === 1) {
key = choices[0].value
} else {
const questions = [{
Expand All @@ -48,14 +48,14 @@ const { _: [query] } = argv
key = answers.name
}

const setConfig = configs[key]
const setConfig = localConfigs[key]
PRINT.GET.CONFIG({
name: setConfig.name,
key,
token: setConfig.token
})
} else if (query) {
const setConfig = query in configs ? configs[query] : Object.values(configs).find(({ name }) => name.toLowerCase().includes(query.toLowerCase()))
const setConfig = query in localConfigs ? localConfigs[query] : Object.values(localConfigs).find(({ name }) => name.toLowerCase().includes(query.toLowerCase()))
if (setConfig) {
PRINT.GET.CONFIG({
name: setConfig.name,
Expand Down
4 changes: 2 additions & 2 deletions cli/bin/glyphs-help
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ log(`
Commands
add, a Configure a new icon set
remove, r Remove an existing icon set config
get, g Get details on the icon set config
get Get details on the icon set config
list, l List configured icon sets
sync, s Sync an icon set to the current directory
preview, p Preview a local icon set in the browser
generate Generate a JS component set
generate, g Generate components, fonts, and more
help, h Display this message
`)
7 changes: 3 additions & 4 deletions cli/bin/glyphs-list
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const parseArgs = require('minimist')
const chalk = require('chalk')
const { log, PRINT } = require('../utils/logger')
const { localConfigs, hasConfig } = require('../utils/config')

const args = process.argv.slice(2)
const argv = parseArgs(args, {
Expand All @@ -17,16 +18,14 @@ if (argv.help) {
process.exit()
}

const { configs, hasConfig } = require('../utils/config')

log()

if (!hasConfig) {
log('No icon files have been configured', 1)
log('Run "glyphs add" to configure a new icon file', 1)
} else {
const max = Object.entries(configs).reduce((len, [key, { name }]) => Math.max(len, name.length), 0)
Object.entries(configs).forEach(([key, { name }]) => {
const max = Object.entries(localConfigs).reduce((len, [key, { name }]) => Math.max(len, name.length), 0)
Object.entries(localConfigs).forEach(([key, { name }]) => {
const padding = Array(max - name.length).fill(' ').join('')
log(`${chalk.cyan`${name}:`}${padding} https://figma.com/file/${key}`, 1)
})
Expand Down
11 changes: 5 additions & 6 deletions cli/bin/glyphs-remove
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env node

const parseArgs = require('minimist')
const inquirer = require('inquirer')
const { log, PRINT } = require('../utils/logger')
const { conf, localConfigs, hasConfig } = require('../utils/config')

const args = process.argv.slice(2)
const argv = parseArgs(args, {
Expand All @@ -16,9 +18,6 @@ if (argv.help) {
process.exit()
}

const inquirer = require('inquirer')
const { conf, configs, hasConfig } = require('../utils/config')

const { _: [key] } = argv

;(async () => {
Expand All @@ -28,7 +27,7 @@ const { _: [key] } = argv
log(`No icons files have been configured`, 1)
} else {
if (!key) {
const choices = Object.entries(configs)
const choices = Object.entries(localConfigs)
.map(([key, { name }]) => ({ value: key, name }))

const questions = [{
Expand All @@ -40,11 +39,11 @@ const { _: [key] } = argv

const answers = await inquirer.prompt(questions)
log()
remove(configs[answers.name])
remove(localConfigs[answers.name])
} else {
const exists = !!conf.get(key)
if (exists) {
remove(configs[key])
remove(localConfigs[key])
} else {
log(`No configuration with the key "${key}"`, 1)
}
Expand Down
Loading