@charcoal-ui/icons-cli 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +359 -659
- package/dist/index.cjs.map +1 -1
- package/package.json +6 -15
- package/dist/GitHubClient.d.ts +0 -1173
- package/dist/GitHubClient.d.ts.map +0 -1
- package/dist/GitlabClient.d.ts +0 -19
- package/dist/GitlabClient.d.ts.map +0 -1
- package/dist/concurrently.d.ts +0 -2
- package/dist/concurrently.d.ts.map +0 -1
- package/dist/figma/FigmaFileClient.d.ts +0 -18
- package/dist/figma/FigmaFileClient.d.ts.map +0 -1
- package/dist/generateSource.d.ts +0 -3
- package/dist/generateSource.d.ts.map +0 -1
- package/dist/getChangedFiles.d.ts +0 -9
- package/dist/getChangedFiles.d.ts.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.modern.js +0 -921
- package/dist/index.modern.js.map +0 -1
- package/dist/index.module.js +0 -919
- package/dist/index.module.js.map +0 -1
- package/dist/svg/optimizeSvg.d.ts +0 -17
- package/dist/svg/optimizeSvg.d.ts.map +0 -1
- package/dist/svg/optimizeSvgInDirectory.d.ts +0 -2
- package/dist/svg/optimizeSvgInDirectory.d.ts.map +0 -1
- package/dist/utils.d.ts +0 -6
- package/dist/utils.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,546 +1,273 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
var
|
|
30
|
-
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
19
|
+
mod
|
|
20
|
+
));
|
|
21
|
+
|
|
22
|
+
// src/index.ts
|
|
23
|
+
var import_yargs = __toESM(require("yargs"), 1);
|
|
24
|
+
|
|
25
|
+
// src/figma/FigmaFileClient.ts
|
|
26
|
+
var import_path = __toESM(require("path"), 1);
|
|
27
|
+
var import_camelcase = __toESM(require("camelcase"), 1);
|
|
28
|
+
var import_figma_js = __toESM(require("figma-js"), 1);
|
|
29
|
+
var import_fs_extra = require("fs-extra");
|
|
30
|
+
var import_got = __toESM(require("got"), 1);
|
|
31
|
+
var import_path_to_regexp = require("path-to-regexp");
|
|
32
|
+
|
|
33
|
+
// src/concurrently.ts
|
|
34
|
+
var import_p_queue = __toESM(require("p-queue"), 1);
|
|
31
35
|
function concurrently(tasks) {
|
|
32
|
-
const queue = new
|
|
33
|
-
concurrency: 3
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
+
const queue = new import_p_queue.default({ concurrency: 3 });
|
|
36
37
|
for (const task of tasks) {
|
|
37
38
|
void queue.add(task);
|
|
38
39
|
}
|
|
39
|
-
|
|
40
40
|
queue.start();
|
|
41
41
|
return queue.onIdle();
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
// src/figma/FigmaFileClient.ts
|
|
45
|
+
var matchPath = (0, import_path_to_regexp.match)("/file/:fileId/:name");
|
|
46
46
|
function extractParams(url) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const {
|
|
50
|
-
pathname,
|
|
51
|
-
searchParams
|
|
52
|
-
} = new URL(url);
|
|
47
|
+
const { pathname, searchParams } = new URL(url);
|
|
53
48
|
const result = matchPath(pathname);
|
|
54
|
-
|
|
55
49
|
if (result === false) {
|
|
56
|
-
throw new Error(
|
|
50
|
+
throw new Error("No fileId found in url");
|
|
57
51
|
}
|
|
58
|
-
|
|
59
52
|
return {
|
|
60
53
|
fileId: result.params.fileId,
|
|
61
|
-
nodeId:
|
|
54
|
+
nodeId: searchParams.get("node-id") ?? void 0
|
|
62
55
|
};
|
|
63
56
|
}
|
|
64
|
-
|
|
65
57
|
function filenamify(name) {
|
|
66
|
-
return
|
|
67
|
-
pascalCase: true
|
|
68
|
-
}).replace(' ', '');
|
|
58
|
+
return (0, import_camelcase.default)(name, { pascalCase: true }).replace(" ", "");
|
|
69
59
|
}
|
|
70
|
-
|
|
71
|
-
const iconName = /^(?:\d+|Inline)\s*\//u;
|
|
72
|
-
|
|
60
|
+
var iconName = /^(?:\d+|Inline)\s*\//u;
|
|
73
61
|
function isIconNode(node) {
|
|
74
62
|
return iconName.test(node.name);
|
|
75
63
|
}
|
|
76
|
-
|
|
77
|
-
|
|
64
|
+
var FigmaFileClient = class {
|
|
65
|
+
fileId;
|
|
66
|
+
nodeId;
|
|
67
|
+
exportFormat;
|
|
68
|
+
client;
|
|
69
|
+
components = {};
|
|
78
70
|
static async runFromCli(url, token, outputRootDir, exportFormat) {
|
|
79
71
|
const client = new this(url, token, exportFormat);
|
|
80
|
-
const outputDir =
|
|
81
|
-
|
|
72
|
+
const outputDir = import_path.default.join(process.cwd(), outputRootDir, exportFormat);
|
|
82
73
|
console.log(`Exporting components from ${url}`);
|
|
83
|
-
await client.loadSvg(outputDir);
|
|
84
|
-
|
|
85
|
-
console.log('success!');
|
|
74
|
+
await client.loadSvg(outputDir);
|
|
75
|
+
console.log("success!");
|
|
86
76
|
}
|
|
87
|
-
|
|
88
77
|
constructor(url, personalAccessToken, exportFormat) {
|
|
89
|
-
this.
|
|
90
|
-
this.nodeId = void 0;
|
|
91
|
-
this.exportFormat = void 0;
|
|
92
|
-
this.client = void 0;
|
|
93
|
-
this.components = {};
|
|
94
|
-
this.client = Figma__default["default"].Client({
|
|
78
|
+
this.client = import_figma_js.default.Client({
|
|
95
79
|
personalAccessToken
|
|
96
80
|
});
|
|
97
|
-
const {
|
|
98
|
-
fileId,
|
|
99
|
-
nodeId
|
|
100
|
-
} = extractParams(url);
|
|
81
|
+
const { fileId, nodeId } = extractParams(url);
|
|
101
82
|
this.fileId = fileId;
|
|
102
83
|
this.nodeId = nodeId;
|
|
103
84
|
this.exportFormat = exportFormat;
|
|
104
85
|
}
|
|
105
|
-
|
|
106
86
|
async loadSvg(outputDir) {
|
|
107
|
-
await
|
|
108
|
-
await
|
|
87
|
+
await (0, import_fs_extra.remove)(outputDir);
|
|
88
|
+
await (0, import_fs_extra.ensureDir)(outputDir);
|
|
109
89
|
await this.loadComponents();
|
|
110
90
|
await this.loadImageUrls();
|
|
111
91
|
await this.downloadImages(outputDir);
|
|
112
92
|
}
|
|
113
|
-
|
|
114
93
|
async loadComponents() {
|
|
115
|
-
const {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
// 指定されていない場合はドキュメント全体が探索対象
|
|
119
|
-
|
|
120
|
-
const targets = this.nodeId !== undefined ? document.children.filter(node => node.id === this.nodeId) : document.children; // 対象ノードの子孫を探索してアイコンのコンポーネントを見つける
|
|
121
|
-
|
|
122
|
-
targets.forEach(child => this.findComponentsRecursively(child));
|
|
123
|
-
|
|
94
|
+
const { document } = await this.getFile();
|
|
95
|
+
const targets = this.nodeId !== void 0 ? document.children.filter((node) => node.id === this.nodeId) : document.children;
|
|
96
|
+
targets.forEach((child) => this.findComponentsRecursively(child));
|
|
124
97
|
if (Object.keys(this.components).length === 0) {
|
|
125
|
-
throw new Error(
|
|
98
|
+
throw new Error("No components found!");
|
|
126
99
|
}
|
|
127
100
|
}
|
|
128
|
-
|
|
129
101
|
async loadImageUrls() {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const {
|
|
133
|
-
data
|
|
134
|
-
} = await this.client.fileImages(this.fileId, {
|
|
102
|
+
console.log("Getting export urls");
|
|
103
|
+
const { data } = await this.client.fileImages(this.fileId, {
|
|
135
104
|
format: this.exportFormat,
|
|
136
105
|
ids: Object.keys(this.components),
|
|
137
106
|
scale: 1
|
|
138
107
|
});
|
|
139
|
-
|
|
140
108
|
for (const [id, image] of Object.entries(data.images)) {
|
|
141
109
|
this.components[id].image = image;
|
|
142
110
|
}
|
|
143
111
|
}
|
|
144
|
-
|
|
145
112
|
async downloadImages(outputDir) {
|
|
146
|
-
return concurrently(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
113
|
+
return concurrently(
|
|
114
|
+
Object.values(this.components).map((component) => async () => {
|
|
115
|
+
if (component.image === void 0) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const svg = await (0, import_got.default)(component.image).text();
|
|
119
|
+
const filename = `${filenamify(component.name)}.${this.exportFormat}`;
|
|
120
|
+
const fullname = import_path.default.join(outputDir, filename);
|
|
121
|
+
const dirname = import_path.default.dirname(fullname);
|
|
122
|
+
await (0, import_fs_extra.ensureDir)(dirname);
|
|
123
|
+
console.log(`found: ${filename} => \u2705 writing...`);
|
|
124
|
+
await (0, import_fs_extra.writeFile)(fullname, svg, "utf8");
|
|
125
|
+
})
|
|
126
|
+
);
|
|
160
127
|
}
|
|
161
|
-
|
|
162
128
|
async getFile() {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const {
|
|
166
|
-
data
|
|
167
|
-
} = await this.client.file(this.fileId.toString());
|
|
129
|
+
console.log("Processing response");
|
|
130
|
+
const { data } = await this.client.file(this.fileId.toString());
|
|
168
131
|
return data;
|
|
169
132
|
}
|
|
170
|
-
|
|
171
133
|
findComponentsRecursively(child) {
|
|
172
|
-
if (child.type ===
|
|
173
|
-
const {
|
|
174
|
-
name,
|
|
175
|
-
id
|
|
176
|
-
} = child;
|
|
177
|
-
|
|
134
|
+
if (child.type === "COMPONENT") {
|
|
135
|
+
const { name, id } = child;
|
|
178
136
|
if (isIconNode(child)) {
|
|
179
137
|
this.components[id] = {
|
|
180
138
|
name,
|
|
181
139
|
id
|
|
182
140
|
};
|
|
183
141
|
}
|
|
184
|
-
} else if (
|
|
185
|
-
child.children.forEach(
|
|
142
|
+
} else if ("children" in child) {
|
|
143
|
+
child.children.forEach(
|
|
144
|
+
(grandChild) => this.findComponentsRecursively(grandChild)
|
|
145
|
+
);
|
|
186
146
|
}
|
|
187
147
|
}
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function _asyncIterator(iterable) {
|
|
192
|
-
var method,
|
|
193
|
-
async,
|
|
194
|
-
sync,
|
|
195
|
-
retry = 2;
|
|
196
|
-
|
|
197
|
-
for ("undefined" != typeof Symbol && (async = Symbol.asyncIterator, sync = Symbol.iterator); retry--;) {
|
|
198
|
-
if (async && null != (method = iterable[async])) return method.call(iterable);
|
|
199
|
-
if (sync && null != (method = iterable[sync])) return new AsyncFromSyncIterator(method.call(iterable));
|
|
200
|
-
async = "@@asyncIterator", sync = "@@iterator";
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
throw new TypeError("Object is not async iterable");
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
function AsyncFromSyncIterator(s) {
|
|
207
|
-
function AsyncFromSyncIteratorContinuation(r) {
|
|
208
|
-
if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object."));
|
|
209
|
-
var done = r.done;
|
|
210
|
-
return Promise.resolve(r.value).then(function (value) {
|
|
211
|
-
return {
|
|
212
|
-
value: value,
|
|
213
|
-
done: done
|
|
214
|
-
};
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return AsyncFromSyncIterator = function (s) {
|
|
219
|
-
this.s = s, this.n = s.next;
|
|
220
|
-
}, AsyncFromSyncIterator.prototype = {
|
|
221
|
-
s: null,
|
|
222
|
-
n: null,
|
|
223
|
-
next: function () {
|
|
224
|
-
return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
|
|
225
|
-
},
|
|
226
|
-
return: function (value) {
|
|
227
|
-
var ret = this.s.return;
|
|
228
|
-
return void 0 === ret ? Promise.resolve({
|
|
229
|
-
value: value,
|
|
230
|
-
done: !0
|
|
231
|
-
}) : AsyncFromSyncIteratorContinuation(ret.apply(this.s, arguments));
|
|
232
|
-
},
|
|
233
|
-
throw: function (value) {
|
|
234
|
-
var thr = this.s.return;
|
|
235
|
-
return void 0 === thr ? Promise.reject(value) : AsyncFromSyncIteratorContinuation(thr.apply(this.s, arguments));
|
|
236
|
-
}
|
|
237
|
-
}, new AsyncFromSyncIterator(s);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
function _AwaitValue(value) {
|
|
241
|
-
this.wrapped = value;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
function _AsyncGenerator(gen) {
|
|
245
|
-
var front, back;
|
|
246
|
-
|
|
247
|
-
function send(key, arg) {
|
|
248
|
-
return new Promise(function (resolve, reject) {
|
|
249
|
-
var request = {
|
|
250
|
-
key: key,
|
|
251
|
-
arg: arg,
|
|
252
|
-
resolve: resolve,
|
|
253
|
-
reject: reject,
|
|
254
|
-
next: null
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
if (back) {
|
|
258
|
-
back = back.next = request;
|
|
259
|
-
} else {
|
|
260
|
-
front = back = request;
|
|
261
|
-
resume(key, arg);
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
function resume(key, arg) {
|
|
267
|
-
try {
|
|
268
|
-
var result = gen[key](arg);
|
|
269
|
-
var value = result.value;
|
|
270
|
-
var wrappedAwait = value instanceof _AwaitValue;
|
|
271
|
-
Promise.resolve(wrappedAwait ? value.wrapped : value).then(function (arg) {
|
|
272
|
-
if (wrappedAwait) {
|
|
273
|
-
resume(key === "return" ? "return" : "next", arg);
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
settle(result.done ? "return" : "normal", arg);
|
|
278
|
-
}, function (err) {
|
|
279
|
-
resume("throw", err);
|
|
280
|
-
});
|
|
281
|
-
} catch (err) {
|
|
282
|
-
settle("throw", err);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
function settle(type, value) {
|
|
287
|
-
switch (type) {
|
|
288
|
-
case "return":
|
|
289
|
-
front.resolve({
|
|
290
|
-
value: value,
|
|
291
|
-
done: true
|
|
292
|
-
});
|
|
293
|
-
break;
|
|
294
|
-
|
|
295
|
-
case "throw":
|
|
296
|
-
front.reject(value);
|
|
297
|
-
break;
|
|
298
|
-
|
|
299
|
-
default:
|
|
300
|
-
front.resolve({
|
|
301
|
-
value: value,
|
|
302
|
-
done: false
|
|
303
|
-
});
|
|
304
|
-
break;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
front = front.next;
|
|
308
|
-
|
|
309
|
-
if (front) {
|
|
310
|
-
resume(front.key, front.arg);
|
|
311
|
-
} else {
|
|
312
|
-
back = null;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
this._invoke = send;
|
|
317
|
-
|
|
318
|
-
if (typeof gen.return !== "function") {
|
|
319
|
-
this.return = undefined;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
_AsyncGenerator.prototype[typeof Symbol === "function" && Symbol.asyncIterator || "@@asyncIterator"] = function () {
|
|
324
|
-
return this;
|
|
325
148
|
};
|
|
326
149
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
_AsyncGenerator.prototype.throw = function (arg) {
|
|
332
|
-
return this._invoke("throw", arg);
|
|
333
|
-
};
|
|
150
|
+
// src/GitHubClient.ts
|
|
151
|
+
var import_rest = require("@octokit/rest");
|
|
152
|
+
var import_path3 = __toESM(require("path"), 1);
|
|
334
153
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
154
|
+
// src/getChangedFiles.ts
|
|
155
|
+
var import_fs = require("fs");
|
|
156
|
+
var import_path2 = __toESM(require("path"), 1);
|
|
338
157
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
function _awaitAsyncGenerator(value) {
|
|
346
|
-
return new _AwaitValue(value);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
function _extends() {
|
|
350
|
-
_extends = Object.assign || function (target) {
|
|
351
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
352
|
-
var source = arguments[i];
|
|
353
|
-
|
|
354
|
-
for (var key in source) {
|
|
355
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
356
|
-
target[key] = source[key];
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
return target;
|
|
362
|
-
};
|
|
363
|
-
|
|
364
|
-
return _extends.apply(this, arguments);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* FIXME: util.promisify を使うと node-libs-browser に入っている方が使われてしまい、壊れる
|
|
369
|
-
*/
|
|
370
|
-
|
|
371
|
-
const execp = command => new Promise((resolve, reject) => {
|
|
372
|
-
child_process.exec(command, (err, stdout) => {
|
|
158
|
+
// src/utils.ts
|
|
159
|
+
var import_child_process = require("child_process");
|
|
160
|
+
var execp = (command) => new Promise((resolve, reject) => {
|
|
161
|
+
(0, import_child_process.exec)(command, (err, stdout) => {
|
|
373
162
|
if (err) {
|
|
374
163
|
return reject(err);
|
|
375
164
|
}
|
|
376
|
-
|
|
377
165
|
return resolve(stdout);
|
|
378
166
|
});
|
|
379
167
|
});
|
|
380
168
|
function mustBeDefined(value, name) {
|
|
381
|
-
if (typeof value ===
|
|
169
|
+
if (typeof value === "undefined") {
|
|
382
170
|
throw new TypeError(`${name} must be defined.`);
|
|
383
171
|
}
|
|
384
172
|
}
|
|
385
173
|
|
|
386
|
-
|
|
387
|
-
* dir
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
_getChangedFiles = _wrapAsyncGenerator(function* (dir) {
|
|
396
|
-
if (!fs$1.existsSync(dir)) throw new Error(`icons-cli: target directory not found (${dir})`);
|
|
397
|
-
const gitStatus = yield _awaitAsyncGenerator(collectGitStatus());
|
|
398
|
-
|
|
399
|
-
for (const [relativePath, status] of gitStatus) {
|
|
400
|
-
const fullpath = path__default["default"].resolve(process.cwd(), relativePath);
|
|
401
|
-
|
|
402
|
-
if (!fullpath.startsWith(`${dir}/`)) {
|
|
403
|
-
continue;
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
if (!fs$1.existsSync(fullpath)) throw new Error(`icons-cli: could not load svg (${fullpath})`);
|
|
407
|
-
const content = yield _awaitAsyncGenerator(fs$1.promises.readFile(fullpath, {
|
|
408
|
-
encoding: 'utf-8'
|
|
409
|
-
}));
|
|
410
|
-
yield {
|
|
411
|
-
relativePath,
|
|
412
|
-
content,
|
|
413
|
-
status
|
|
414
|
-
};
|
|
174
|
+
// src/getChangedFiles.ts
|
|
175
|
+
async function* getChangedFiles(dir) {
|
|
176
|
+
if (!(0, import_fs.existsSync)(dir))
|
|
177
|
+
throw new Error(`icons-cli: target directory not found (${dir})`);
|
|
178
|
+
const gitStatus = await collectGitStatus();
|
|
179
|
+
for (const [relativePath, status] of gitStatus) {
|
|
180
|
+
const fullpath = import_path2.default.resolve(process.cwd(), relativePath);
|
|
181
|
+
if (!fullpath.startsWith(`${dir}/`)) {
|
|
182
|
+
continue;
|
|
415
183
|
}
|
|
416
|
-
|
|
417
|
-
|
|
184
|
+
if (!(0, import_fs.existsSync)(fullpath))
|
|
185
|
+
throw new Error(`icons-cli: could not load svg (${fullpath})`);
|
|
186
|
+
const content = await import_fs.promises.readFile(fullpath, { encoding: "utf-8" });
|
|
187
|
+
yield { relativePath, content, status };
|
|
188
|
+
}
|
|
418
189
|
}
|
|
419
|
-
|
|
420
190
|
async function collectGitStatus() {
|
|
421
191
|
return new Map(
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
192
|
+
(await execp(`git status --porcelain`)).split("\n").map((s) => {
|
|
193
|
+
return [
|
|
194
|
+
s.slice(3),
|
|
195
|
+
s.startsWith(" M") ? "modified" : s.startsWith("??") ? "untracked" : s.startsWith(" D") ? "deleted" : null
|
|
196
|
+
];
|
|
197
|
+
})
|
|
198
|
+
);
|
|
428
199
|
}
|
|
429
200
|
|
|
430
|
-
|
|
201
|
+
// src/GitHubClient.ts
|
|
202
|
+
var GithubClient = class {
|
|
203
|
+
constructor(repoOwner, repoName, token, defaultBranch, now = new Date()) {
|
|
204
|
+
this.repoOwner = repoOwner;
|
|
205
|
+
this.repoName = repoName;
|
|
206
|
+
this.defaultBranch = defaultBranch;
|
|
207
|
+
this.api = new import_rest.Octokit({
|
|
208
|
+
auth: token
|
|
209
|
+
});
|
|
210
|
+
this.now = now;
|
|
211
|
+
}
|
|
212
|
+
api;
|
|
213
|
+
now;
|
|
431
214
|
static async runFromCli(repoOwner, repoName, token, defaultBranch, outputDir) {
|
|
432
215
|
const client = new this(repoOwner, repoName, token, defaultBranch);
|
|
433
|
-
const outputDirFullPath =
|
|
434
|
-
const diff = await client.createTreeFromDiff(outputDirFullPath);
|
|
435
|
-
|
|
216
|
+
const outputDirFullPath = import_path3.default.resolve(process.cwd(), outputDir);
|
|
217
|
+
const diff = await client.createTreeFromDiff(outputDirFullPath);
|
|
436
218
|
console.log(`${diff.length} files are changed`);
|
|
437
|
-
|
|
438
219
|
if (diff.length === 0) {
|
|
439
|
-
|
|
440
|
-
console.log('no changes. aborting');
|
|
220
|
+
console.log("no changes. aborting");
|
|
441
221
|
return;
|
|
442
222
|
}
|
|
443
|
-
|
|
444
223
|
const newBranch = await client.createBranch();
|
|
445
224
|
await client.createCommit(diff, newBranch);
|
|
446
225
|
return client.createPullRequest(newBranch);
|
|
447
226
|
}
|
|
448
|
-
|
|
449
|
-
constructor(repoOwner, repoName, token, defaultBranch, now = new Date()) {
|
|
450
|
-
this.repoOwner = void 0;
|
|
451
|
-
this.repoName = void 0;
|
|
452
|
-
this.defaultBranch = void 0;
|
|
453
|
-
this.api = void 0;
|
|
454
|
-
this.now = void 0;
|
|
455
|
-
this.repoOwner = repoOwner;
|
|
456
|
-
this.repoName = repoName;
|
|
457
|
-
this.defaultBranch = defaultBranch;
|
|
458
|
-
this.api = new rest.Octokit({
|
|
459
|
-
auth: token
|
|
460
|
-
});
|
|
461
|
-
this.now = now;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
227
|
get branch() {
|
|
465
228
|
return `icons/update/${this.now.getTime()}`;
|
|
466
229
|
}
|
|
467
|
-
/**
|
|
468
|
-
* both used for commit message or pull request title
|
|
469
|
-
*/
|
|
470
|
-
|
|
471
|
-
|
|
472
230
|
get message() {
|
|
473
231
|
return `[icons-cli] Update icons ${this.now.toDateString()}`;
|
|
474
232
|
}
|
|
475
|
-
|
|
476
233
|
async createTreeFromDiff(outputDir) {
|
|
477
234
|
const tree = [];
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
content: file.content
|
|
492
|
-
};
|
|
493
|
-
|
|
494
|
-
if (file.status === 'deleted') {
|
|
495
|
-
// https://stackoverflow.com/questions/23637961/how-do-i-mark-a-file-as-deleted-in-a-tree-using-the-github-api
|
|
496
|
-
tree.push(_extends({}, item, {
|
|
497
|
-
sha: null
|
|
498
|
-
}));
|
|
499
|
-
} else {
|
|
500
|
-
tree.push(item);
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
} catch (err) {
|
|
504
|
-
_didIteratorError = true;
|
|
505
|
-
_iteratorError = err;
|
|
506
|
-
} finally {
|
|
507
|
-
try {
|
|
508
|
-
if (_iteratorAbruptCompletion && _iterator.return != null) {
|
|
509
|
-
await _iterator.return();
|
|
510
|
-
}
|
|
511
|
-
} finally {
|
|
512
|
-
if (_didIteratorError) {
|
|
513
|
-
throw _iteratorError;
|
|
514
|
-
}
|
|
235
|
+
for await (const file of getChangedFiles(outputDir)) {
|
|
236
|
+
const item = {
|
|
237
|
+
path: file.relativePath,
|
|
238
|
+
mode: "100644",
|
|
239
|
+
content: file.content
|
|
240
|
+
};
|
|
241
|
+
if (file.status === "deleted") {
|
|
242
|
+
tree.push({
|
|
243
|
+
...item,
|
|
244
|
+
sha: null
|
|
245
|
+
});
|
|
246
|
+
} else {
|
|
247
|
+
tree.push(item);
|
|
515
248
|
}
|
|
516
249
|
}
|
|
517
|
-
|
|
518
250
|
return tree;
|
|
519
251
|
}
|
|
520
|
-
|
|
521
252
|
async createCommit(tree, targetBranch) {
|
|
522
253
|
const parentCommit = await this.api.git.getCommit({
|
|
523
254
|
owner: this.repoOwner,
|
|
524
255
|
repo: this.repoName,
|
|
525
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
526
256
|
commit_sha: targetBranch.data.object.sha
|
|
527
257
|
});
|
|
528
258
|
const newTree = await this.api.git.createTree({
|
|
529
259
|
owner: this.repoOwner,
|
|
530
260
|
repo: this.repoName,
|
|
531
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
532
261
|
base_tree: parentCommit.data.tree.sha,
|
|
533
262
|
tree
|
|
534
|
-
});
|
|
535
|
-
|
|
263
|
+
});
|
|
536
264
|
const commit = await this.api.git.createCommit({
|
|
537
265
|
owner: this.repoOwner,
|
|
538
266
|
repo: this.repoName,
|
|
539
267
|
message: this.message,
|
|
540
268
|
tree: newTree.data.sha,
|
|
541
269
|
parents: [parentCommit.data.sha]
|
|
542
|
-
});
|
|
543
|
-
|
|
270
|
+
});
|
|
544
271
|
await this.api.git.updateRef({
|
|
545
272
|
owner: this.repoOwner,
|
|
546
273
|
repo: this.repoName,
|
|
@@ -549,7 +276,6 @@ class GithubClient {
|
|
|
549
276
|
});
|
|
550
277
|
return commit;
|
|
551
278
|
}
|
|
552
|
-
|
|
553
279
|
async createPullRequest(targetBranch) {
|
|
554
280
|
const defaultBranch = await this.getDefaultBranchRef();
|
|
555
281
|
return this.api.pulls.create({
|
|
@@ -558,10 +284,9 @@ class GithubClient {
|
|
|
558
284
|
head: targetBranch.data.ref,
|
|
559
285
|
base: defaultBranch.data.ref,
|
|
560
286
|
title: this.message,
|
|
561
|
-
body:
|
|
287
|
+
body: ""
|
|
562
288
|
});
|
|
563
289
|
}
|
|
564
|
-
|
|
565
290
|
getDefaultBranchRef() {
|
|
566
291
|
return this.api.git.getRef({
|
|
567
292
|
owner: this.repoOwner,
|
|
@@ -569,7 +294,6 @@ class GithubClient {
|
|
|
569
294
|
ref: `heads/${this.defaultBranch}`
|
|
570
295
|
});
|
|
571
296
|
}
|
|
572
|
-
|
|
573
297
|
async createBranch() {
|
|
574
298
|
const defaultBranch = await this.getDefaultBranchRef();
|
|
575
299
|
return this.api.git.createRef({
|
|
@@ -579,353 +303,329 @@ class GithubClient {
|
|
|
579
303
|
sha: defaultBranch.data.object.sha
|
|
580
304
|
});
|
|
581
305
|
}
|
|
306
|
+
};
|
|
582
307
|
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
const client = new this(host, projectId, privateToken, defaultBranch);
|
|
588
|
-
const outputDirFullPath = path__default["default"].resolve(process.cwd(), outputDir);
|
|
589
|
-
const diff = await client.createActionsFromDiff(outputDirFullPath); // eslint-disable-next-line no-console
|
|
590
|
-
|
|
591
|
-
console.log(`${diff.length} files are changed`);
|
|
592
|
-
|
|
593
|
-
if (diff.length === 0) {
|
|
594
|
-
// eslint-disable-next-line no-console
|
|
595
|
-
console.log('no changes. aborting');
|
|
596
|
-
return;
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
await client.createCommit(diff);
|
|
600
|
-
return client.createMergeRequest();
|
|
601
|
-
}
|
|
602
|
-
|
|
308
|
+
// src/GitlabClient.ts
|
|
309
|
+
var import_node = require("@gitbeaker/node");
|
|
310
|
+
var import_path4 = __toESM(require("path"), 1);
|
|
311
|
+
var GitlabClient = class {
|
|
603
312
|
constructor(host, projectId, privateToken, defaultBranch, now = new Date()) {
|
|
604
|
-
this.host = void 0;
|
|
605
|
-
this.projectId = void 0;
|
|
606
|
-
this.defaultBranch = void 0;
|
|
607
|
-
this.api = void 0;
|
|
608
|
-
this.now = void 0;
|
|
609
313
|
this.host = host;
|
|
610
314
|
this.projectId = projectId;
|
|
611
315
|
this.defaultBranch = defaultBranch;
|
|
612
|
-
this.api = new
|
|
316
|
+
this.api = new import_node.Gitlab({
|
|
613
317
|
host: this.host,
|
|
614
318
|
token: privateToken
|
|
615
319
|
});
|
|
616
320
|
this.now = now;
|
|
617
321
|
}
|
|
618
|
-
|
|
322
|
+
api;
|
|
323
|
+
now;
|
|
324
|
+
static async runFromCli(host, projectId, privateToken, defaultBranch, outputDir) {
|
|
325
|
+
const client = new this(host, projectId, privateToken, defaultBranch);
|
|
326
|
+
const outputDirFullPath = import_path4.default.resolve(process.cwd(), outputDir);
|
|
327
|
+
const diff = await client.createActionsFromDiff(outputDirFullPath);
|
|
328
|
+
console.log(`${diff.length} files are changed`);
|
|
329
|
+
if (diff.length === 0) {
|
|
330
|
+
console.log("no changes. aborting");
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
await client.createCommit(diff);
|
|
334
|
+
return client.createMergeRequest();
|
|
335
|
+
}
|
|
619
336
|
get branch() {
|
|
620
337
|
return `icons/update/${this.now.getTime()}`;
|
|
621
338
|
}
|
|
622
|
-
/**
|
|
623
|
-
* both used for commit message or merge request title
|
|
624
|
-
*/
|
|
625
|
-
|
|
626
|
-
|
|
627
339
|
get message() {
|
|
628
340
|
return `[icons-cli] Update icons ${this.now.toDateString()}`;
|
|
629
341
|
}
|
|
630
|
-
|
|
631
342
|
async createActionsFromDiff(outputDir) {
|
|
632
343
|
const actions = [];
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
for (var _iterator = _asyncIterator(getChangedFiles(outputDir)), _step; _iteratorAbruptCompletion = !(_step = await _iterator.next()).done; _iteratorAbruptCompletion = false) {
|
|
640
|
-
const file = _step.value;
|
|
641
|
-
actions.push({
|
|
642
|
-
action: file.status === 'untracked' ? 'create' : file.status === 'deleted' ? 'delete' : 'update',
|
|
643
|
-
filePath: file.relativePath,
|
|
644
|
-
content: file.content
|
|
645
|
-
});
|
|
646
|
-
}
|
|
647
|
-
} catch (err) {
|
|
648
|
-
_didIteratorError = true;
|
|
649
|
-
_iteratorError = err;
|
|
650
|
-
} finally {
|
|
651
|
-
try {
|
|
652
|
-
if (_iteratorAbruptCompletion && _iterator.return != null) {
|
|
653
|
-
await _iterator.return();
|
|
654
|
-
}
|
|
655
|
-
} finally {
|
|
656
|
-
if (_didIteratorError) {
|
|
657
|
-
throw _iteratorError;
|
|
658
|
-
}
|
|
659
|
-
}
|
|
344
|
+
for await (const file of getChangedFiles(outputDir)) {
|
|
345
|
+
actions.push({
|
|
346
|
+
action: file.status === "untracked" ? "create" : file.status === "deleted" ? "delete" : "update",
|
|
347
|
+
filePath: file.relativePath,
|
|
348
|
+
content: file.content
|
|
349
|
+
});
|
|
660
350
|
}
|
|
661
|
-
|
|
662
351
|
return actions;
|
|
663
352
|
}
|
|
664
|
-
|
|
665
353
|
async createCommit(diff) {
|
|
666
|
-
return this.api.Commits.create(
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
354
|
+
return this.api.Commits.create(
|
|
355
|
+
this.projectId,
|
|
356
|
+
this.branch,
|
|
357
|
+
this.message,
|
|
358
|
+
diff,
|
|
359
|
+
{
|
|
360
|
+
start_branch: this.defaultBranch
|
|
361
|
+
}
|
|
362
|
+
);
|
|
670
363
|
}
|
|
671
|
-
|
|
672
364
|
createMergeRequest() {
|
|
673
|
-
return this.api.MergeRequests.create(
|
|
365
|
+
return this.api.MergeRequests.create(
|
|
366
|
+
this.projectId,
|
|
367
|
+
this.branch,
|
|
368
|
+
this.defaultBranch,
|
|
369
|
+
this.message
|
|
370
|
+
);
|
|
674
371
|
}
|
|
372
|
+
};
|
|
675
373
|
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
}, {
|
|
687
|
-
removeAttrs: {
|
|
688
|
-
attrs: ['stroke-opacity', 'fill-opacity']
|
|
689
|
-
}
|
|
690
|
-
}]
|
|
374
|
+
// src/svg/optimizeSvg.ts
|
|
375
|
+
var import_jsdom = require("jsdom");
|
|
376
|
+
var import_polished = require("polished");
|
|
377
|
+
var import_svgo = __toESM(require("svgo"), 1);
|
|
378
|
+
var DEFAULT_CURRENT_COLOR_TARGET = "#858585";
|
|
379
|
+
var svgo = new import_svgo.default({
|
|
380
|
+
plugins: [
|
|
381
|
+
{ removeViewBox: false },
|
|
382
|
+
{ removeAttrs: { attrs: ["stroke-opacity", "fill-opacity"] } }
|
|
383
|
+
]
|
|
691
384
|
});
|
|
692
385
|
async function optimizeSvg(input, options) {
|
|
693
|
-
const {
|
|
694
|
-
|
|
695
|
-
} = new jsdom.JSDOM(input).window;
|
|
696
|
-
const svg = document.querySelector('svg');
|
|
697
|
-
|
|
386
|
+
const { document } = new import_jsdom.JSDOM(input).window;
|
|
387
|
+
const svg = document.querySelector("svg");
|
|
698
388
|
if (!svg) {
|
|
699
|
-
throw new Error(
|
|
389
|
+
throw new Error("optimizeSvg: input string seems not to have <svg>");
|
|
700
390
|
}
|
|
701
|
-
|
|
702
391
|
addViewboxToRootSvg(svg);
|
|
703
392
|
convertToCurrentColor(svg, options.convertedColor);
|
|
704
|
-
|
|
705
393
|
if (options.withoutOptimizeBySVGO === true) {
|
|
706
394
|
return svg.outerHTML;
|
|
707
395
|
} else {
|
|
708
396
|
return (await svgo.optimize(svg.outerHTML)).data;
|
|
709
397
|
}
|
|
710
398
|
}
|
|
711
|
-
|
|
712
|
-
|
|
399
|
+
var TARGET_ATTRS = ["fill", "stroke"];
|
|
713
400
|
function convertToCurrentColor(svg, convertedColor) {
|
|
714
401
|
const targetColor = parseColor(convertedColor);
|
|
715
|
-
|
|
716
402
|
if (!targetColor) {
|
|
717
403
|
throw new Error(`${convertedColor} is not a valid color`);
|
|
718
404
|
}
|
|
719
|
-
|
|
720
405
|
for (const attr of TARGET_ATTRS) {
|
|
721
406
|
const targets = Array.from(svg.querySelectorAll(`[${attr}]`));
|
|
722
|
-
|
|
723
407
|
for (const el of targets) {
|
|
724
408
|
const value = parseColor(el.getAttribute(attr));
|
|
725
|
-
|
|
726
409
|
if (!value) {
|
|
727
410
|
continue;
|
|
728
411
|
}
|
|
729
|
-
|
|
730
412
|
if (!colorEquals(value, targetColor)) {
|
|
731
413
|
continue;
|
|
732
414
|
}
|
|
733
|
-
|
|
734
|
-
el.setAttribute(attr, 'currentColor');
|
|
415
|
+
el.setAttribute(attr, "currentColor");
|
|
735
416
|
}
|
|
736
417
|
}
|
|
737
418
|
}
|
|
738
|
-
|
|
739
419
|
function parseColor(value) {
|
|
740
420
|
if (value == null) {
|
|
741
421
|
return null;
|
|
742
422
|
}
|
|
743
|
-
|
|
744
423
|
try {
|
|
745
|
-
return
|
|
746
|
-
} catch
|
|
424
|
+
return (0, import_polished.parseToRgb)(value);
|
|
425
|
+
} catch {
|
|
747
426
|
return null;
|
|
748
427
|
}
|
|
749
428
|
}
|
|
750
|
-
|
|
751
429
|
function colorEquals(self, other) {
|
|
752
430
|
if (self.red !== other.red) {
|
|
753
431
|
return false;
|
|
754
432
|
}
|
|
755
|
-
|
|
756
433
|
if (self.blue !== other.blue) {
|
|
757
434
|
return false;
|
|
758
435
|
}
|
|
759
|
-
|
|
760
436
|
if (self.green !== other.green) {
|
|
761
437
|
return false;
|
|
762
438
|
}
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
if ('alpha' in other) {
|
|
439
|
+
if ("alpha" in self) {
|
|
440
|
+
if ("alpha" in other) {
|
|
766
441
|
if (self.alpha !== other.alpha) {
|
|
767
442
|
return false;
|
|
768
443
|
}
|
|
769
444
|
}
|
|
770
445
|
}
|
|
771
|
-
|
|
772
446
|
return true;
|
|
773
447
|
}
|
|
774
|
-
|
|
775
448
|
function addViewboxToRootSvg(svg) {
|
|
776
|
-
|
|
777
|
-
const
|
|
778
|
-
|
|
779
|
-
const height = svg.getAttribute('height');
|
|
780
|
-
svg.setAttribute('viewBox', `0 0 ${width} ${height}`);
|
|
449
|
+
const width = svg.getAttribute("width");
|
|
450
|
+
const height = svg.getAttribute("height");
|
|
451
|
+
svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
|
|
781
452
|
}
|
|
782
453
|
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
const
|
|
454
|
+
// src/svg/optimizeSvgInDirectory.ts
|
|
455
|
+
var import_path5 = __toESM(require("path"), 1);
|
|
456
|
+
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
457
|
+
var import_fs_extra2 = __toESM(require("fs-extra"), 1);
|
|
458
|
+
var optimizeSvgInDirectory = async (outputDir, replaceColor, ignoreFile) => {
|
|
459
|
+
const rootDir = import_path5.default.join(outputDir, "svg");
|
|
460
|
+
const ignorePatterns = ignoreFile !== void 0 ? (await import_fs_extra2.default.readFile(ignoreFile, "utf8")).trim().split(/\r?\n/u) : [];
|
|
461
|
+
const files = await (0, import_fast_glob.default)("**/*.svg", {
|
|
789
462
|
cwd: rootDir
|
|
790
463
|
});
|
|
791
|
-
await concurrently(
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
464
|
+
await concurrently(
|
|
465
|
+
files.map((file) => async () => {
|
|
466
|
+
console.log(`Optimizing ${file}...`);
|
|
467
|
+
const fullPath = import_path5.default.join(rootDir, file);
|
|
468
|
+
const originalSvg = await import_fs_extra2.default.readFile(fullPath, "utf8");
|
|
469
|
+
const optimizedSvg = await optimizeSvg(originalSvg, {
|
|
470
|
+
convertedColor: replaceColor,
|
|
471
|
+
withoutOptimizeBySVGO: ignorePatterns.includes(file)
|
|
472
|
+
});
|
|
473
|
+
await import_fs_extra2.default.writeFile(fullPath, optimizedSvg);
|
|
474
|
+
})
|
|
475
|
+
);
|
|
801
476
|
};
|
|
802
477
|
|
|
803
|
-
|
|
804
|
-
|
|
478
|
+
// src/generateSource.ts
|
|
479
|
+
var import_path6 = __toESM(require("path"), 1);
|
|
480
|
+
var import_fast_glob2 = __toESM(require("fast-glob"), 1);
|
|
481
|
+
var import_fs_extra3 = __toESM(require("fs-extra"), 1);
|
|
482
|
+
var generateIconSvgEmbededSource = (svgString) => {
|
|
483
|
+
const str = svgString.replace(/\r?\n/g, "");
|
|
805
484
|
return `/** This file is auto generated. DO NOT EDIT BY HAND. */
|
|
806
485
|
export default '${str}'
|
|
807
486
|
`;
|
|
808
487
|
};
|
|
809
|
-
|
|
810
|
-
const generateMjsEntrypoint = icons => `/** This file is auto generated. DO NOT EDIT BY HAND. */
|
|
488
|
+
var generateMjsEntrypoint = (icons) => `/** This file is auto generated. DO NOT EDIT BY HAND. */
|
|
811
489
|
|
|
812
490
|
export default {
|
|
813
|
-
${icons.map(it => ` '${it}': () => import('./${it}.js').then(m => m.default)`).join(
|
|
491
|
+
${icons.map((it) => ` '${it}': () => import('./${it}.js').then(m => m.default)`).join(",\n")}
|
|
814
492
|
}
|
|
815
493
|
`;
|
|
816
|
-
|
|
817
|
-
const generateCjsEntrypoint = icons => `/** This file is auto generated. DO NOT EDIT BY HAND. */
|
|
494
|
+
var generateCjsEntrypoint = (icons) => `/** This file is auto generated. DO NOT EDIT BY HAND. */
|
|
818
495
|
|
|
819
496
|
module.exports = {
|
|
820
|
-
${icons.map(it => ` '${it}': () => import('./${it}.js').then(m => m.default)`).join(
|
|
497
|
+
${icons.map((it) => ` '${it}': () => import('./${it}.js').then(m => m.default)`).join(",\n")}
|
|
821
498
|
}
|
|
822
499
|
`;
|
|
823
|
-
|
|
824
|
-
const generateTypeDefinitionEntrypoint = icons => `/** This file is auto generated. DO NOt EDIT BY HAND. */
|
|
500
|
+
var generateTypeDefinitionEntrypoint = (icons) => `/** This file is auto generated. DO NOt EDIT BY HAND. */
|
|
825
501
|
|
|
826
502
|
declare var _default: {
|
|
827
|
-
${icons.map(it => ` '${it}': () => Promise<string>`).join(
|
|
503
|
+
${icons.map((it) => ` '${it}': () => Promise<string>`).join(";\n")}
|
|
828
504
|
};
|
|
829
505
|
export default _default;
|
|
830
506
|
`;
|
|
831
|
-
|
|
832
|
-
const
|
|
833
|
-
const
|
|
834
|
-
|
|
835
|
-
await
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
await
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
await
|
|
842
|
-
await fs__default["default"].writeFile(dtsPath, generateTypeDefinitionEntrypoint(icons));
|
|
507
|
+
var generateEntrypoint = async (outputDir, icons) => {
|
|
508
|
+
const srcRoot = import_path6.default.join(outputDir, "src");
|
|
509
|
+
const mjsPath = import_path6.default.join(srcRoot, "index.js");
|
|
510
|
+
await import_fs_extra3.default.ensureFile(mjsPath);
|
|
511
|
+
await import_fs_extra3.default.writeFile(mjsPath, generateMjsEntrypoint(icons));
|
|
512
|
+
const cjsPath = import_path6.default.join(srcRoot, "index.cjs");
|
|
513
|
+
await import_fs_extra3.default.ensureFile(cjsPath);
|
|
514
|
+
await import_fs_extra3.default.writeFile(cjsPath, generateCjsEntrypoint(icons));
|
|
515
|
+
const dtsPath = import_path6.default.join(srcRoot, "index.d.ts");
|
|
516
|
+
await import_fs_extra3.default.ensureFile(dtsPath);
|
|
517
|
+
await import_fs_extra3.default.writeFile(dtsPath, generateTypeDefinitionEntrypoint(icons));
|
|
843
518
|
};
|
|
844
|
-
|
|
845
|
-
const svgRoot =
|
|
846
|
-
const srcRoot =
|
|
847
|
-
const icons = (await
|
|
848
|
-
|
|
849
|
-
})).map(path => path.slice(0, -4) // e.g. '16/Add.svg' -> '16/Add'
|
|
519
|
+
var generateIconSource = async (outputDir) => {
|
|
520
|
+
const svgRoot = import_path6.default.join(outputDir, "svg");
|
|
521
|
+
const srcRoot = import_path6.default.join(outputDir, "src");
|
|
522
|
+
const icons = (await (0, import_fast_glob2.default)("**/*.svg", { cwd: svgRoot })).map(
|
|
523
|
+
(path7) => path7.slice(0, -4)
|
|
850
524
|
).sort();
|
|
851
|
-
|
|
852
525
|
for (const it of icons) {
|
|
853
|
-
const data = await
|
|
854
|
-
const outputPath =
|
|
855
|
-
await
|
|
856
|
-
await
|
|
526
|
+
const data = await import_fs_extra3.default.readFile(import_path6.default.join(svgRoot, `${it}.svg`));
|
|
527
|
+
const outputPath = import_path6.default.join(srcRoot, `${it}.js`);
|
|
528
|
+
await import_fs_extra3.default.ensureFile(outputPath);
|
|
529
|
+
await import_fs_extra3.default.writeFile(
|
|
530
|
+
outputPath,
|
|
531
|
+
generateIconSvgEmbededSource(data.toString())
|
|
532
|
+
);
|
|
857
533
|
}
|
|
858
|
-
|
|
859
534
|
await generateEntrypoint(outputDir, icons);
|
|
860
535
|
};
|
|
861
536
|
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
const GITHUB_REPO_NAME = process.env.GITHUB_REPO_NAME;
|
|
884
|
-
const GITHUB_DEFAULT_BRANCH = process.env.GITHUB_DEFAULT_BRANCH;
|
|
885
|
-
void yargs__default["default"].scriptName('icons-cli').command('figma:export', 'Load all icons from Figma and save to files', {
|
|
886
|
-
format: {
|
|
887
|
-
default: 'svg',
|
|
888
|
-
choices: ['svg', 'pdf'],
|
|
889
|
-
describe: 'Output format'
|
|
890
|
-
}
|
|
891
|
-
}, async ({
|
|
892
|
-
format
|
|
893
|
-
}) => {
|
|
894
|
-
mustBeDefined(FIGMA_FILE_URL, 'FIGMA_FILE_URL');
|
|
895
|
-
mustBeDefined(FIGMA_TOKEN, 'FIGMA_TOKEN');
|
|
896
|
-
mustBeDefined(OUTPUT_ROOT_DIR, 'OUTPUT_ROOT_DIR');
|
|
897
|
-
await FigmaFileClient.runFromCli(FIGMA_FILE_URL, FIGMA_TOKEN, OUTPUT_ROOT_DIR, format);
|
|
898
|
-
}).command('svg:optimize', 'Optimize svg files in output directory', {
|
|
899
|
-
color: {
|
|
900
|
-
default: DEFAULT_CURRENT_COLOR_TARGET,
|
|
901
|
-
type: 'string',
|
|
902
|
-
describe: 'Color code that should be converted into `currentColor`'
|
|
537
|
+
// src/index.ts
|
|
538
|
+
var FIGMA_TOKEN = process.env.FIGMA_TOKEN;
|
|
539
|
+
var FIGMA_FILE_URL = process.env.FIGMA_FILE_URL;
|
|
540
|
+
var OUTPUT_ROOT_DIR = process.env.OUTPUT_ROOT_DIR;
|
|
541
|
+
var GITLAB_ACCESS_TOKEN = process.env.GITLAB_ACCESS_TOKEN;
|
|
542
|
+
var GITLAB_DEFAULT_BRANCH = process.env.GITLAB_DEFAULT_BRANCH;
|
|
543
|
+
var GITLAB_HOST = process.env.GITLAB_HOST;
|
|
544
|
+
var GITLAB_PROJECT_ID = process.env.GITLAB_PROJECT_ID;
|
|
545
|
+
var GITHUB_ACCESS_TOKEN = process.env.GITHUB_ACCESS_TOKEN;
|
|
546
|
+
var GITHUB_REPO_OWNER = process.env.GITHUB_REPO_OWNER;
|
|
547
|
+
var GITHUB_REPO_NAME = process.env.GITHUB_REPO_NAME;
|
|
548
|
+
var GITHUB_DEFAULT_BRANCH = process.env.GITHUB_DEFAULT_BRANCH;
|
|
549
|
+
void import_yargs.default.scriptName("icons-cli").command(
|
|
550
|
+
"figma:export",
|
|
551
|
+
"Load all icons from Figma and save to files",
|
|
552
|
+
{
|
|
553
|
+
format: {
|
|
554
|
+
default: "svg",
|
|
555
|
+
choices: ["svg", "pdf"],
|
|
556
|
+
describe: "Output format"
|
|
557
|
+
}
|
|
903
558
|
},
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
}
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
559
|
+
async ({ format }) => {
|
|
560
|
+
mustBeDefined(FIGMA_FILE_URL, "FIGMA_FILE_URL");
|
|
561
|
+
mustBeDefined(FIGMA_TOKEN, "FIGMA_TOKEN");
|
|
562
|
+
mustBeDefined(OUTPUT_ROOT_DIR, "OUTPUT_ROOT_DIR");
|
|
563
|
+
await FigmaFileClient.runFromCli(
|
|
564
|
+
FIGMA_FILE_URL,
|
|
565
|
+
FIGMA_TOKEN,
|
|
566
|
+
OUTPUT_ROOT_DIR,
|
|
567
|
+
format
|
|
568
|
+
);
|
|
569
|
+
}
|
|
570
|
+
).command(
|
|
571
|
+
"svg:optimize",
|
|
572
|
+
"Optimize svg files in output directory",
|
|
573
|
+
{
|
|
574
|
+
color: {
|
|
575
|
+
default: DEFAULT_CURRENT_COLOR_TARGET,
|
|
576
|
+
type: "string",
|
|
577
|
+
describe: "Color code that should be converted into `currentColor`"
|
|
578
|
+
},
|
|
579
|
+
ignoreFile: {
|
|
580
|
+
type: "string",
|
|
581
|
+
describe: "A file that contains the list of path to SVG files that should not be optimized"
|
|
582
|
+
}
|
|
583
|
+
},
|
|
584
|
+
async ({ color, ignoreFile }) => {
|
|
585
|
+
mustBeDefined(OUTPUT_ROOT_DIR, "OUTPUT_ROOT_DIR");
|
|
586
|
+
await optimizeSvgInDirectory(OUTPUT_ROOT_DIR, color, ignoreFile);
|
|
587
|
+
}
|
|
588
|
+
).command(
|
|
589
|
+
"files:generate",
|
|
590
|
+
"Enumerate svg files in output directory and generate icon files",
|
|
591
|
+
{},
|
|
592
|
+
() => {
|
|
593
|
+
mustBeDefined(OUTPUT_ROOT_DIR, "OUTPUT_ROOT_DIR");
|
|
594
|
+
void generateIconSource(OUTPUT_ROOT_DIR).catch((e) => {
|
|
595
|
+
console.error(e);
|
|
596
|
+
process.exit(1);
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
).command(
|
|
600
|
+
"gitlab:mr",
|
|
601
|
+
"Create a merge request in the name of icons-cli",
|
|
602
|
+
{},
|
|
603
|
+
async () => {
|
|
604
|
+
mustBeDefined(GITLAB_PROJECT_ID, "GITLAB_PROJECT_ID");
|
|
605
|
+
mustBeDefined(GITLAB_ACCESS_TOKEN, "GITLAB_ACCESS_TOKEN");
|
|
606
|
+
mustBeDefined(OUTPUT_ROOT_DIR, "OUTPUT_ROOT_DIR");
|
|
607
|
+
await GitlabClient.runFromCli(
|
|
608
|
+
GITLAB_HOST ?? "https://gitlab.com",
|
|
609
|
+
Number(GITLAB_PROJECT_ID),
|
|
610
|
+
GITLAB_ACCESS_TOKEN,
|
|
611
|
+
GITLAB_DEFAULT_BRANCH ?? "main",
|
|
612
|
+
OUTPUT_ROOT_DIR
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
).command(
|
|
616
|
+
"github:pr",
|
|
617
|
+
"Create a pull request in the name of icons-cli",
|
|
618
|
+
{},
|
|
619
|
+
async () => {
|
|
620
|
+
mustBeDefined(GITHUB_ACCESS_TOKEN, "GITHUB_ACCESS_TOKEN");
|
|
621
|
+
mustBeDefined(OUTPUT_ROOT_DIR, "OUTPUT_ROOT_DIR");
|
|
622
|
+
await GithubClient.runFromCli(
|
|
623
|
+
GITHUB_REPO_OWNER ?? "pixiv",
|
|
624
|
+
GITHUB_REPO_NAME ?? "charcoal",
|
|
625
|
+
GITHUB_ACCESS_TOKEN,
|
|
626
|
+
GITHUB_DEFAULT_BRANCH ?? "main",
|
|
627
|
+
OUTPUT_ROOT_DIR
|
|
628
|
+
);
|
|
629
|
+
}
|
|
630
|
+
).demandCommand().strict().help().parse();
|
|
631
|
+
//# sourceMappingURL=index.cjs.map
|