@charcoal-ui/icons-cli 2.0.0 → 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 CHANGED
@@ -1,546 +1,273 @@
1
1
  #!/usr/bin/env node
2
- var yargs = require('yargs');
3
- var path = require('path');
4
- var camelCase = require('camelcase');
5
- var Figma = require('figma-js');
6
- var fs = require('fs-extra');
7
- var got = require('got');
8
- var pathToRegexp = require('path-to-regexp');
9
- var PQueue = require('p-queue');
10
- var rest = require('@octokit/rest');
11
- var fs$1 = require('fs');
12
- var child_process = require('child_process');
13
- var node = require('@gitbeaker/node');
14
- var jsdom = require('jsdom');
15
- var polished = require('polished');
16
- var Svgo = require('svgo');
17
- var glob = require('fast-glob');
18
-
19
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
20
-
21
- var yargs__default = /*#__PURE__*/_interopDefaultLegacy(yargs);
22
- var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
23
- var camelCase__default = /*#__PURE__*/_interopDefaultLegacy(camelCase);
24
- var Figma__default = /*#__PURE__*/_interopDefaultLegacy(Figma);
25
- var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
26
- var got__default = /*#__PURE__*/_interopDefaultLegacy(got);
27
- var PQueue__default = /*#__PURE__*/_interopDefaultLegacy(PQueue);
28
- var Svgo__default = /*#__PURE__*/_interopDefaultLegacy(Svgo);
29
- var glob__default = /*#__PURE__*/_interopDefaultLegacy(glob);
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 PQueue__default["default"]({
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
- const matchPath = pathToRegexp.match('/file/:fileId/:name');
45
-
44
+ // src/figma/FigmaFileClient.ts
45
+ var matchPath = (0, import_path_to_regexp.match)("/file/:fileId/:name");
46
46
  function extractParams(url) {
47
- var _searchParams$get;
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('No fileId found in url');
50
+ throw new Error("No fileId found in url");
57
51
  }
58
-
59
52
  return {
60
53
  fileId: result.params.fileId,
61
- nodeId: (_searchParams$get = searchParams.get('node-id')) != null ? _searchParams$get : undefined
54
+ nodeId: searchParams.get("node-id") ?? void 0
62
55
  };
63
56
  }
64
-
65
57
  function filenamify(name) {
66
- return camelCase__default["default"](name, {
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
- class FigmaFileClient {
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 = path__default["default"].join(process.cwd(), outputRootDir, exportFormat); // eslint-disable-next-line no-console
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); // eslint-disable-next-line no-console
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.fileId = void 0;
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 fs.remove(outputDir);
108
- await fs.ensureDir(outputDir);
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
- document
117
- } = await this.getFile(); // nodeIdが指定されている場合は、IDが一致するノードのみを探索対象にする
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('No components found!');
98
+ throw new Error("No components found!");
126
99
  }
127
100
  }
128
-
129
101
  async loadImageUrls() {
130
- // eslint-disable-next-line no-console
131
- console.log('Getting export urls');
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(Object.values(this.components).map(component => async () => {
147
- if (component.image === undefined) {
148
- return;
149
- }
150
-
151
- const svg = await got__default["default"](component.image).text();
152
- const filename = `${filenamify(component.name)}.${this.exportFormat}`;
153
- const fullname = path__default["default"].join(outputDir, filename);
154
- const dirname = path__default["default"].dirname(fullname);
155
- await fs.ensureDir(dirname); // eslint-disable-next-line no-console
156
-
157
- console.log(`found: ${filename} => ✅ writing...`);
158
- await fs.writeFile(fullname, svg, 'utf8');
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
- // eslint-disable-next-line no-console
164
- console.log('Processing response');
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 === 'COMPONENT') {
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 ('children' in child) {
185
- child.children.forEach(grandChild => this.findComponentsRecursively(grandChild));
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
- _AsyncGenerator.prototype.next = function (arg) {
328
- return this._invoke("next", arg);
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
- _AsyncGenerator.prototype.return = function (arg) {
336
- return this._invoke("return", arg);
337
- };
154
+ // src/getChangedFiles.ts
155
+ var import_fs = require("fs");
156
+ var import_path2 = __toESM(require("path"), 1);
338
157
 
339
- function _wrapAsyncGenerator(fn) {
340
- return function () {
341
- return new _AsyncGenerator(fn.apply(this, arguments));
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 === 'undefined') {
169
+ if (typeof value === "undefined") {
382
170
  throw new TypeError(`${name} must be defined.`);
383
171
  }
384
172
  }
385
173
 
386
- /**
387
- * dir 内で変更があったファイル情報を for await で回せるようにするやつ
388
- */
389
-
390
- function getChangedFiles(_x) {
391
- return _getChangedFiles.apply(this, arguments);
392
- }
393
-
394
- function _getChangedFiles() {
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
- return _getChangedFiles.apply(this, arguments);
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
- * @see https://git-scm.com/docs/git-status#_porcelain_format_version_1
424
- */
425
- (await execp(`git status --porcelain`)).split('\n').map(s => {
426
- return [s.slice(3), s.startsWith(' M') ? 'modified' : s.startsWith('??') ? 'untracked' : s.startsWith(' D') ? 'deleted' : null];
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
- class GithubClient {
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 = path__default["default"].resolve(process.cwd(), outputDir);
434
- const diff = await client.createTreeFromDiff(outputDirFullPath); // eslint-disable-next-line no-console
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
- // eslint-disable-next-line no-console
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
- var _iteratorAbruptCompletion = false;
479
- var _didIteratorError = false;
480
-
481
- var _iteratorError;
482
-
483
- try {
484
- for (var _iterator = _asyncIterator(getChangedFiles(outputDir)), _step; _iteratorAbruptCompletion = !(_step = await _iterator.next()).done; _iteratorAbruptCompletion = false) {
485
- const file = _step.value;
486
- const item = {
487
- path: file.relativePath,
488
- // 100 はファイル 644 は実行不可なファイルであるという意味
489
- // @see https://octokit.github.io/rest.js/v18#git-create-tree
490
- mode: '100644',
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
- }); // ref を更新することで、commit が targetBranch に属するようになる
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
- class GitlabClient {
586
- static async runFromCli(host, projectId, privateToken, defaultBranch, outputDir) {
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 node.Gitlab({
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
- var _iteratorAbruptCompletion = false;
634
- var _didIteratorError = false;
635
-
636
- var _iteratorError;
637
-
638
- try {
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(this.projectId, this.branch, this.message, diff, {
667
- // eslint-disable-next-line @typescript-eslint/naming-convention
668
- start_branch: this.defaultBranch
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(this.projectId, this.branch, this.defaultBranch, this.message);
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
- const DEFAULT_CURRENT_COLOR_TARGET = '#858585';
679
- const svgo = new Svgo__default["default"]({
680
- plugins: [// NOTICE: SVGO は「svg 内のすべての fill を currentColor に変える」機能しかない
681
- // icons-cli に必要なのは「特定の黒っぽい色だけ currentColor に変える」機能
682
- // なので、convertColors plugin は使わない
683
- // { convertColors: { currentColor: true } },
684
- {
685
- removeViewBox: false
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
- document
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('optimizeSvg: input string seems not to have <svg>');
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
- const TARGET_ATTRS = ['fill', 'stroke'];
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 polished.parseToRgb(value);
746
- } catch (_unused) {
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
- if ('alpha' in self) {
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
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
777
- const width = svg.getAttribute('width'); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
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
- /* eslint-disable no-console */
784
-
785
- const optimizeSvgInDirectory = async (outputDir, replaceColor, ignoreFile) => {
786
- const rootDir = path__default["default"].join(outputDir, 'svg');
787
- const ignorePatterns = ignoreFile !== undefined ? (await fs__default["default"].readFile(ignoreFile, 'utf8')).trim().split(/\r?\n/u) : [];
788
- const files = await glob__default["default"]('**/*.svg', {
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(files.map(file => async () => {
792
- console.log(`Optimizing ${file}...`);
793
- const fullPath = path__default["default"].join(rootDir, file);
794
- const originalSvg = await fs__default["default"].readFile(fullPath, 'utf8');
795
- const optimizedSvg = await optimizeSvg(originalSvg, {
796
- convertedColor: replaceColor,
797
- withoutOptimizeBySVGO: ignorePatterns.includes(file)
798
- });
799
- await fs__default["default"].writeFile(fullPath, optimizedSvg);
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
- const generateIconSvgEmbededSource = svgString => {
804
- const str = svgString.replace(/\r?\n/g, '');
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(',\n')}
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(',\n')}
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(';\n')}
503
+ ${icons.map((it) => ` '${it}': () => Promise<string>`).join(";\n")}
828
504
  };
829
505
  export default _default;
830
506
  `;
831
-
832
- const generateEntrypoint = async (outputDir, icons) => {
833
- const srcRoot = path__default["default"].join(outputDir, 'src');
834
- const mjsPath = path__default["default"].join(srcRoot, 'index.js');
835
- await fs__default["default"].ensureFile(mjsPath);
836
- await fs__default["default"].writeFile(mjsPath, generateMjsEntrypoint(icons));
837
- const cjsPath = path__default["default"].join(srcRoot, 'index.cjs');
838
- await fs__default["default"].ensureFile(cjsPath);
839
- await fs__default["default"].writeFile(cjsPath, generateCjsEntrypoint(icons));
840
- const dtsPath = path__default["default"].join(srcRoot, 'index.d.ts');
841
- await fs__default["default"].ensureFile(dtsPath);
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
- const generateIconSource = async outputDir => {
845
- const svgRoot = path__default["default"].join(outputDir, 'svg');
846
- const srcRoot = path__default["default"].join(outputDir, 'src');
847
- const icons = (await glob__default["default"]('**/*.svg', {
848
- cwd: svgRoot
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 fs__default["default"].readFile(path__default["default"].join(svgRoot, `${it}.svg`));
854
- const outputPath = path__default["default"].join(srcRoot, `${it}.js`);
855
- await fs__default["default"].ensureFile(outputPath);
856
- await fs__default["default"].writeFile(outputPath, generateIconSvgEmbededSource(data.toString()));
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
- * Figma
864
- */
865
-
866
- const FIGMA_TOKEN = process.env.FIGMA_TOKEN;
867
- const FIGMA_FILE_URL = process.env.FIGMA_FILE_URL;
868
- const OUTPUT_ROOT_DIR = process.env.OUTPUT_ROOT_DIR;
869
- /**
870
- * GitLab
871
- */
872
-
873
- const GITLAB_ACCESS_TOKEN = process.env.GITLAB_ACCESS_TOKEN;
874
- const GITLAB_DEFAULT_BRANCH = process.env.GITLAB_DEFAULT_BRANCH;
875
- const GITLAB_HOST = process.env.GITLAB_HOST;
876
- const GITLAB_PROJECT_ID = process.env.GITLAB_PROJECT_ID;
877
- /**
878
- * GitHub
879
- */
880
-
881
- const GITHUB_ACCESS_TOKEN = process.env.GITHUB_ACCESS_TOKEN;
882
- const GITHUB_REPO_OWNER = process.env.GITHUB_REPO_OWNER;
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
- ignoreFile: {
905
- type: 'string',
906
- describe: 'A file that contains the list of path to SVG files that should not be optimized'
907
- }
908
- }, async ({
909
- color,
910
- ignoreFile
911
- }) => {
912
- mustBeDefined(OUTPUT_ROOT_DIR, 'OUTPUT_ROOT_DIR');
913
- await optimizeSvgInDirectory(OUTPUT_ROOT_DIR, color, ignoreFile);
914
- }).command('files:generate', 'Enumerate svg files in output directory and generate icon files', {}, () => {
915
- mustBeDefined(OUTPUT_ROOT_DIR, 'OUTPUT_ROOT_DIR');
916
- void generateIconSource(OUTPUT_ROOT_DIR).catch(e => {
917
- // eslint-disable-next-line no-console
918
- console.error(e);
919
- process.exit(1);
920
- });
921
- }).command('gitlab:mr', 'Create a merge request in the name of icons-cli', {}, async () => {
922
- mustBeDefined(GITLAB_PROJECT_ID, 'GITLAB_PROJECT_ID');
923
- mustBeDefined(GITLAB_ACCESS_TOKEN, 'GITLAB_ACCESS_TOKEN');
924
- mustBeDefined(OUTPUT_ROOT_DIR, 'OUTPUT_ROOT_DIR');
925
- await GitlabClient.runFromCli(GITLAB_HOST != null ? GITLAB_HOST : 'https://gitlab.com', Number(GITLAB_PROJECT_ID), GITLAB_ACCESS_TOKEN, GITLAB_DEFAULT_BRANCH != null ? GITLAB_DEFAULT_BRANCH : 'main', OUTPUT_ROOT_DIR);
926
- }).command('github:pr', 'Create a pull request in the name of icons-cli', {}, async () => {
927
- mustBeDefined(GITHUB_ACCESS_TOKEN, 'GITHUB_ACCESS_TOKEN');
928
- mustBeDefined(OUTPUT_ROOT_DIR, 'OUTPUT_ROOT_DIR');
929
- await GithubClient.runFromCli(GITHUB_REPO_OWNER != null ? GITHUB_REPO_OWNER : 'pixiv', GITHUB_REPO_NAME != null ? GITHUB_REPO_NAME : 'charcoal', GITHUB_ACCESS_TOKEN, GITHUB_DEFAULT_BRANCH != null ? GITHUB_DEFAULT_BRANCH : 'main', OUTPUT_ROOT_DIR);
930
- }).demandCommand().strict().help().parse();
931
- //# sourceMappingURL=index.cjs.map
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