Skip to content

Commit 0371851

Browse files
authored
Add support for separate TS and PHP typing paths in sync command (#3)
2 parents 44193b3 + 6408379 commit 0371851

File tree

5 files changed

+62
-21
lines changed

5 files changed

+62
-21
lines changed

README.md

+14-12
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,28 @@ EXAMPLES
6363
$ figex make:config
6464
```
6565

66-
_See code: [src/commands/make/config.ts](https://github.com/4746/figex/blob/v0.0.2/src/commands/make/config.ts)_
66+
_See code: [src/commands/make/config.ts](https://github.com/4746/figex/blob/v0.0.3/src/commands/make/config.ts)_
6767

6868
## `figex sync`
6969

7070
Sync svg icons
7171

7272
```
7373
USAGE
74-
$ figex sync [--fileId <value>] [--nameExportType <value>] [--page <value>] [--pathFileSprite <value>]
75-
[--pathFileType <value>] [--phpNamespace <value>] [--phpUse <value>] [--showResultTable] [--silent] [--token
76-
<value>]
74+
$ figex sync [--fileId <value>] [--nameExportType <value>] [--pathFileTypeTS <value>] [--pathFileTypePHP
75+
<value>] [--page <value>] [--pathFileSprite <value>] [--pathFileType <value>] [--phpNamespace <value>] [--phpUse
76+
<value>] [--showResultTable] [--silent] [--token <value>]
7777
7878
FLAGS
79-
--fileId=<value> Figma fileId or create env.FIGMA_FILE_ID
80-
--nameExportType=<value> Name enum .ts or .php
81-
--page=<value> ...
82-
--pathFileSprite=<value> Represents the path to a sprite svg file.
83-
--pathFileType=<value> Represents the file type of a given path.
84-
--phpNamespace=<value> The PHP namespace represents the namespace of a PHP enum file.
85-
--phpUse=<value> Extend enum via use OtherEnums
79+
--fileId=<value> Figma fileId or create env.FIGMA_FILE_ID
80+
--nameExportType=<value> Name enum .ts or .php
81+
--page=<value> ...
82+
--pathFileSprite=<value> Represents the path to a sprite svg file.
83+
--pathFileType=<value> Represents the file type of a given path.
84+
--pathFileTypePHP=<value> Name enum .php
85+
--pathFileTypeTS=<value> Name enum .ts
86+
--phpNamespace=<value> The PHP namespace represents the namespace of a PHP enum file.
87+
--phpUse=<value> Extend enum via use OtherEnums
8688
--showResultTable
8789
--silent
8890
--token=<value>
@@ -94,7 +96,7 @@ EXAMPLES
9496
$ figex sync --help
9597
```
9698

97-
_See code: [src/commands/sync.ts](https://github.com/4746/figex/blob/v0.0.2/src/commands/sync.ts)_
99+
_See code: [src/commands/sync.ts](https://github.com/4746/figex/blob/v0.0.3/src/commands/sync.ts)_
98100
<!-- commandsstop -->
99101

100102

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@cli107/figex",
33
"description": "Figma export svg",
4-
"version": "0.0.2",
4+
"version": "0.0.3",
55
"author": "Vadim",
66
"keywords": [
77
"figma-export",

src/commands/sync.ts

+36-8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export default class Sync extends Command {
2929
static flags = {
3030
fileId: Flags.string({description: 'Figma fileId or create env.FIGMA_FILE_ID', env: 'FIGMA_FILE_ID', requiredOrDefaulted: false}),
3131
nameExportType: Flags.string({description: 'Name enum .ts or .php', requiredOrDefaulted: false}),
32+
pathFileTypeTS: Flags.string({description: 'Name enum .ts', requiredOrDefaulted: false}),
33+
pathFileTypePHP: Flags.string({description: 'Name enum .php', requiredOrDefaulted: false}),
3234
page: Flags.string({description: '...', env: 'FIGMA_PAGE', requiredOrDefaulted: false}),
3335
pathFileSprite: Flags.string({description: 'Represents the path to a sprite svg file.', requiredOrDefaulted: false}),
3436
pathFileType: Flags.string({description: 'Represents the file type of a given path.', requiredOrDefaulted: false}),
@@ -42,6 +44,8 @@ export default class Sync extends Command {
4244
private conf: IFigmaDefaultConf;
4345
private fileId: string;
4446
private nameExportType: string;
47+
private pathFileTypeTS: string;
48+
private pathFileTypePHP: string;
4549
private page: string;
4650
private pathFileSprite: string;
4751
/**
@@ -54,16 +58,32 @@ export default class Sync extends Command {
5458
private silent: boolean;
5559

5660
private taskCreatingTypingFile = async (ctx: TakeSvgCtxTask)=> {
57-
const buildVersion = getBuildVersion(this.config.pjson.version);
58-
59-
await createSvgTypes({
60-
buildVersion,
61+
const p = {
62+
pathFileType: null,
63+
buildVersion: getBuildVersion(this.config.pjson.version),
6164
nameExportType: this.nameExportType,
6265
names: ctx.typeIcons.map(v => v.typeName).sort(),
63-
pathFileType: this.pathFileType,
6466
phpNamespace: this.phpNamespace,
65-
phpUse: this.phpUse
66-
});
67+
phpUse: this.phpUse,
68+
}
69+
if (this.pathFileType) {
70+
await createSvgTypes({
71+
...p,
72+
pathFileType: this.pathFileType,
73+
});
74+
}
75+
if (this.pathFileTypeTS) {
76+
await createSvgTypes({
77+
...p,
78+
pathFileType: this.pathFileTypeTS,
79+
});
80+
}
81+
if (this.pathFileTypePHP) {
82+
await createSvgTypes({
83+
...p,
84+
pathFileType: this.pathFileTypePHP,
85+
});
86+
}
6787
}
6888

6989
private taskDownloadAllSvg = async (ctx: TakeSvgCtxTask)=> {
@@ -124,7 +144,7 @@ export default class Sync extends Command {
124144
title: 'Download all svg'
125145
},
126146
{
127-
skip: (ctx) => !ctx?.typeIcons || !this.pathFileType,
147+
skip: (ctx) => !ctx?.typeIcons || (!this.pathFileType && !this.pathFileTypeTS && !this.pathFileTypePHP),
128148
task: this.taskCreatingTypingFile,
129149
title: 'Creating a typing file'
130150
},
@@ -213,6 +233,14 @@ export default class Sync extends Command {
213233
if (this.pathFileType) {
214234
this.pathFileType = path.join(process.cwd(), this.pathFileType);
215235
}
236+
this.pathFileTypeTS = flags?.pathFileTypeTS ?? this.conf.pathFileTypeTS;
237+
if (this.pathFileTypeTS) {
238+
this.pathFileTypeTS = path.join(process.cwd(), this.pathFileTypeTS);
239+
}
240+
this.pathFileTypePHP = flags?.pathFileTypePHP ?? this.conf.pathFileTypePHP;
241+
if (this.pathFileTypeTS) {
242+
this.pathFileTypePHP = path.join(process.cwd(), this.pathFileTypePHP);
243+
}
216244

217245
this.pathFileSprite = flags?.pathFileSprite ?? this.conf.pathFileSprite;
218246
if (this.pathFileSprite) {

src/lib/entities/conf.ts

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export interface IFigmaDefaultConf {
1717
* The path to the typing file
1818
*/
1919
pathFileType?: string;
20+
pathFileTypeTS?: string,
21+
pathFileTypePHP?: string,
2022
personalToken: string,
2123
/**
2224
* The PHP namespace represents the namespace of a PHP enum file.

src/lib/svg.ts

+9
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ function createEnumPHP(
7777
export async function createSvgTypes({buildVersion, nameExportType, names, pathFileType, phpNamespace, phpUse}: {buildVersion: string, nameExportType: string, names: string[], pathFileType: string, phpNamespace: string, phpUse: string}) {
7878
const PlatformPath = path.parse(pathFileType);
7979

80+
if (!fs.existsSync(PlatformPath.dir)) {
81+
await fs.promises.mkdir(PlatformPath.dir, {recursive: true})
82+
}
83+
8084
const stat = await fs.promises.stat(PlatformPath.dir);
8185
if (stat.isFile()) {
8286
throw new Error(`is not a folder: [${PlatformPath.dir}]`);
@@ -168,6 +172,11 @@ export async function createSvgSprite({pathFileSprite, typeIcons}: {pathFileSpri
168172

169173
const svgSymbols = await Promise.all(promiseSymbols);
170174

175+
const PlatformPath = path.parse(pathFileSprite);
176+
if (!fs.existsSync(PlatformPath.dir)) {
177+
await fs.promises.mkdir(PlatformPath.dir, {recursive: true})
178+
}
179+
171180
return saveSvgSprite({
172181
contentSymbol: svgSymbols.filter(Boolean).sort((a, b) => {
173182
if (a[0] < b[0])

0 commit comments

Comments
 (0)