Skip to content

Commit d8a7149

Browse files
committed
Add icon publish workflow
1 parent 99435d2 commit d8a7149

File tree

5 files changed

+79
-79
lines changed

5 files changed

+79
-79
lines changed

Diff for: package-lock.json

+6-21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
},
3131
"dependencies": {
3232
"@skpm/fs": "^0.2.6",
33-
"lodash": "^4.17.15",
34-
"path": "^0.12.7"
33+
"lodash": "^4.17.15"
3534
}
3635
}

Diff for: src/dev-library/publish-new-icon-to-uikit.js

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
const sketch = require('sketch')
2+
3+
export default function() {
4+
const document = sketch.getSelectedDocument()
5+
const selection = document.selectedLayers.layers
6+
const Settings = sketch.Settings
7+
8+
const ciToken = Settings.documentSettingForKey(document, 'ci-token')
9+
const ciUrl = Settings.documentSettingForKey(document, 'ci-url')
10+
11+
function postIcon(iconCatalog, iconName, iconCode) {
12+
console.log(iconCatalog)
13+
console.log(iconName)
14+
console.log(iconCode)
15+
let requestOptions = {
16+
method: 'POST',
17+
headers: {
18+
"Authorization": `Basic ${ciToken}`,
19+
"Content-Type": "application/json"
20+
},
21+
body: JSON.stringify({
22+
"ref": "master",
23+
"envs": [
24+
{
25+
"name": "ICON_CATALOG",
26+
"value": iconCatalog,
27+
"sensitive": 0
28+
},
29+
{
30+
"name": "ICON_NAME",
31+
"value": iconName,
32+
"sensitive": 0
33+
},
34+
{
35+
"name": "ICON_CODE",
36+
"value": iconCode.replace(/\\"/g, '\\\\"'),
37+
"sensitive": 0
38+
}
39+
]
40+
})
41+
}
42+
fetch(ciUrl, requestOptions)
43+
.then(response => response.text())
44+
.then(result => console.log(result))
45+
.then(() => sketch.UI.alert('🎉 Well Done!', 'The Merge Requset for new icon will be created in 1min. Please check it in the CodingUIKit project. \n \nThanks for your contribution. 你是 CODING 的骄傲!'))
46+
.catch(error => console.log('error', error)
47+
)
48+
}
49+
50+
if (ciToken) {
51+
let iconCatalog = []
52+
let iconName = []
53+
let iconCode = []
54+
selection.map(layer => {
55+
console.log(layer.name)
56+
const options = { formats: 'svg', output: false, compact: true}
57+
const sketchSVG = sketch.export(layer, options)
58+
console.log(sketchSVG.toString())
59+
iconCatalog.push(layer.name.split('/')[0])
60+
iconName.push(layer.name.split('/')[1])
61+
iconCode.push(sketchSVG.toString())
62+
})
63+
postIcon(JSON.stringify(iconCatalog).toString(), JSON.stringify(iconName).toString(), JSON.stringify(iconCode).toString())
64+
} else {
65+
console.log('The ci-token setting not found in this document! Make sure your current docmuent is Coding-Icons Library.')
66+
sketch.UI.alert('⛔️ Wrong File!', 'The ci-token setting not found in this document! \nPlease make sure current docmuent is the Coding-Icons Library.')
67+
}
68+
}

Diff for: src/dev-library/push-new-icon-to-uikit.js

-52
This file was deleted.

Diff for: src/manifest.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
"script": "./dev-library/create-symbol-instance.js"
2020
},
2121
{
22-
"name": "Push New Icon To UIKit",
23-
"identifier": "coding-toolkit.push-new-icon-to-uikit",
24-
"script": "./dev-library/push-new-icon-to-uikit.js"
22+
"name": "Publish New Icon To UIKit",
23+
"identifier": "coding-toolkit.publish-new-icon-to-uikit",
24+
"script": "./dev-library/publish-new-icon-to-uikit.js"
2525
},
2626
{
2727
"script": "data-supplier.js",
@@ -47,7 +47,7 @@
4747
"items": [
4848
"coding-toolkit.generate-icons-collection",
4949
"coding-toolkit.create-symbol-instance",
50-
"coding-toolkit.push-new-icon-to-uikit"
50+
"coding-toolkit.publish-new-icon-to-uikit"
5151
]
5252
}
5353
]

0 commit comments

Comments
 (0)