@greensight/gts 1.0.0-alpha.4
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/LICENSE.md +21 -0
- package/README.md +68 -0
- package/bin/generate.js +6 -0
- package/bin/init.js +4 -0
- package/classes/Config/index.d.ts +12 -0
- package/classes/Config/index.d.ts.map +1 -0
- package/classes/FigmaApi/index.d.ts +16 -0
- package/classes/FigmaApi/index.d.ts.map +1 -0
- package/classes/FigmaApi/types.d.ts +7 -0
- package/classes/FigmaApi/types.d.ts.map +1 -0
- package/classes/FigmaApi/utils.d.ts +3 -0
- package/classes/FigmaApi/utils.d.ts.map +1 -0
- package/classes/FileStorage/index.d.ts +19 -0
- package/classes/FileStorage/index.d.ts.map +1 -0
- package/commands/generate/index.d.ts +2 -0
- package/commands/generate/index.d.ts.map +1 -0
- package/commands/init/index.d.ts +2 -0
- package/commands/init/index.d.ts.map +1 -0
- package/common/console.d.ts +3 -0
- package/common/console.d.ts.map +1 -0
- package/common/types.d.ts +29 -0
- package/common/types.d.ts.map +1 -0
- package/index.d.ts +3 -0
- package/index.d.ts.map +1 -0
- package/index.js +186 -0
- package/modules/colors/colorsFromStyles.d.ts +16 -0
- package/modules/colors/colorsFromStyles.d.ts.map +1 -0
- package/modules/colors/colorsFromVariables.d.ts +16 -0
- package/modules/colors/colorsFromVariables.d.ts.map +1 -0
- package/modules/colors/index.d.ts +3 -0
- package/modules/colors/index.d.ts.map +1 -0
- package/modules/colors/types.d.ts +5 -0
- package/modules/colors/types.d.ts.map +1 -0
- package/modules/colors/utils.d.ts +45 -0
- package/modules/colors/utils.d.ts.map +1 -0
- package/modules/types.d.ts +8 -0
- package/modules/types.d.ts.map +1 -0
- package/package.json +37 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Greensight
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# @greensight/gts
|
|
2
|
+
|
|
3
|
+
Generate design tokens from Figma.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install as a development dependency:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install --save-dev @greensight/gts
|
|
11
|
+
# or
|
|
12
|
+
pnpm add -D @greensight/gts
|
|
13
|
+
# or
|
|
14
|
+
yarn add --dev @greensight/gts
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Initialize configuration
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npx gts-init
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
This will create a `gts.config.ts` file in your project root.
|
|
26
|
+
|
|
27
|
+
### Generate tokens
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npx gts-generate
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Configuration
|
|
34
|
+
|
|
35
|
+
Create a `gts.config.ts` file in your project root:
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { colorsFromStyles, colorsFromVariables } from '@greensight/gts';
|
|
39
|
+
|
|
40
|
+
export default {
|
|
41
|
+
figmaToken: 'your-figma-token',
|
|
42
|
+
fileId: 'your-figma-file-id',
|
|
43
|
+
modules: [
|
|
44
|
+
colorsFromStyles({
|
|
45
|
+
input: { variablePaths: ['./dark.tokens.json', './light.tokens.json'] },
|
|
46
|
+
output: { jsonDir: './dist', stylesDir: './dist' },
|
|
47
|
+
}),
|
|
48
|
+
colorsFromVariables({
|
|
49
|
+
input: { variablePaths: ['./dark.tokens.json', './light.tokens.json'] },
|
|
50
|
+
output: { jsonDir: './dist', stylesDir: './dist' },
|
|
51
|
+
}),
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Modules
|
|
57
|
+
|
|
58
|
+
### colorsFromStyles
|
|
59
|
+
|
|
60
|
+
Generates color tokens from Figma styles. Fetches styles from Figma API and processes them.
|
|
61
|
+
|
|
62
|
+
### colorsFromVariables
|
|
63
|
+
|
|
64
|
+
Generates color tokens directly from variable files (JSON format).
|
|
65
|
+
|
|
66
|
+
## License
|
|
67
|
+
|
|
68
|
+
MIT
|
package/bin/generate.js
ADDED
package/bin/init.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IModule } from '../../modules/types';
|
|
2
|
+
export interface IGtsConfig {
|
|
3
|
+
figmaToken: string;
|
|
4
|
+
fileId: string;
|
|
5
|
+
modules: IModule[];
|
|
6
|
+
}
|
|
7
|
+
export declare class Config {
|
|
8
|
+
private static readonly configFileName;
|
|
9
|
+
static create(): Promise<void>;
|
|
10
|
+
load(): Promise<IGtsConfig | undefined>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/classes/Config/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEnD,MAAM,WAAW,UAAU;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,EAAE,CAAC;CACtB;AAED,qBAAa,MAAM;IACf,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAmB;WAE5C,MAAM;IAQN,IAAI,IAAI,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;CAUvD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { GetFileComponentsResponse, GetFileNodesResponse, GetFileStylesResponse } from '@figma/rest-api-spec';
|
|
2
|
+
import { OnTimeMeasureHandlerType } from './types';
|
|
3
|
+
export declare class FigmaAPI {
|
|
4
|
+
figmaToken: string;
|
|
5
|
+
fileId: string;
|
|
6
|
+
constructor(figmaToken: string, fileId: string);
|
|
7
|
+
private onTimeMeasureHandler?;
|
|
8
|
+
setOnTimeMeasureHandler(handler: OnTimeMeasureHandlerType): void;
|
|
9
|
+
static returnJSON<T = unknown>(response: Response): Promise<T>;
|
|
10
|
+
private performControlledRequest;
|
|
11
|
+
private request;
|
|
12
|
+
getComponents(): Promise<GetFileComponentsResponse>;
|
|
13
|
+
getStyles(): Promise<GetFileStylesResponse>;
|
|
14
|
+
getNodes(ids: string[]): Promise<GetFileNodesResponse>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/classes/FigmaApi/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAEnH,OAAO,KAAK,EAAW,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAGjE,qBAAa,QAAQ;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;gBACH,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAK9C,OAAO,CAAC,oBAAoB,CAAC,CAA2B;IAExD,uBAAuB,CAAC,OAAO,EAAE,wBAAwB;WAI5C,UAAU,CAAC,CAAC,GAAG,OAAO,EAAE,QAAQ,EAAE,QAAQ;YAYzC,wBAAwB;YAkCxB,OAAO;IAUR,aAAa;IAIb,SAAS;IAIT,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE;CActC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface IConfig<TParams = any> {
|
|
2
|
+
params?: TParams;
|
|
3
|
+
timeout?: number;
|
|
4
|
+
abortController?: AbortController;
|
|
5
|
+
}
|
|
6
|
+
export type OnTimeMeasureHandlerType = (endpoint: string, headers: Record<string, unknown>, deltaTimeMs: number) => void;
|
|
7
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/classes/FigmaApi/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO,CAAC,OAAO,GAAG,GAAG;IAClC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,eAAe,CAAC;CACrC;AAED,MAAM,MAAM,wBAAwB,GAAG,CACnC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChC,WAAW,EAAE,MAAM,KAClB,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/classes/FigmaApi/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,GAAI,QAAQ,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,oBAYzD,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,KAAK,MAAM,EAAE,EAAE,aAAS,eAQhD,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
interface IWriteOptions {
|
|
2
|
+
directory?: string;
|
|
3
|
+
overwrite?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare class FileStorage {
|
|
6
|
+
private static readonly baseDir;
|
|
7
|
+
private static resolveReadPath;
|
|
8
|
+
private static resolveWritePath;
|
|
9
|
+
private static handleReadError;
|
|
10
|
+
static read(filePath: string, encoding?: BufferEncoding): Promise<string>;
|
|
11
|
+
static readBuffer(filePath: string): Promise<Buffer<ArrayBufferLike>>;
|
|
12
|
+
static readJson<T = unknown>(filePath: string): Promise<T>;
|
|
13
|
+
static write(fileName: string, content?: string, options?: IWriteOptions): Promise<string>;
|
|
14
|
+
static writeWithExtension(name: string, extension: string, content?: string, options?: IWriteOptions): Promise<string>;
|
|
15
|
+
static exists(filePath: string): boolean;
|
|
16
|
+
static delete(fileName: string, directory?: string): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/classes/FileStorage/index.ts"],"names":[],"mappings":"AAIA,UAAU,aAAa;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,qBAAa,WAAW;IACpB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAyB;IAExD,OAAO,CAAC,MAAM,CAAC,eAAe;IAQ9B,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAQ/B,OAAO,CAAC,MAAM,CAAC,eAAe;WAUjB,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,GAAE,cAAuB;WAUxD,UAAU,CAAC,QAAQ,EAAE,MAAM;WAU3B,QAAQ,CAAC,CAAC,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;WAgBnD,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,SAAK,EAAE,OAAO,GAAE,aAAkB;WAcjE,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,SAAK,EAAE,OAAO,CAAC,EAAE,aAAa;IAOtG,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;WAK3B,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;CAS3D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/generate/index.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,QAAQ,qBAyBpB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/init/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI,qBAIhB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../src/common/console.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,YAAY,GAAI,SAAS,MAAM,SAA8C,CAAC;AAC3F,eAAO,MAAM,WAAW,GAAI,SAAS,MAAM,SAA6C,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare enum ExtensionEnum {
|
|
2
|
+
CSS = "css",
|
|
3
|
+
SCSS = "scss",
|
|
4
|
+
SASS = "sass"
|
|
5
|
+
}
|
|
6
|
+
export interface IColorComponents {
|
|
7
|
+
colorSpace: string;
|
|
8
|
+
components: [number, number, number];
|
|
9
|
+
alpha: number;
|
|
10
|
+
hex: string;
|
|
11
|
+
}
|
|
12
|
+
export interface IFigmaVariable<T = unknown> {
|
|
13
|
+
$type: string;
|
|
14
|
+
$value: T;
|
|
15
|
+
$extensions: {
|
|
16
|
+
'com.figma.variableId': string;
|
|
17
|
+
'com.figma.scopes': string[];
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface IFigmaVariablesBase {
|
|
21
|
+
$extensions: {
|
|
22
|
+
'com.figma.modeName': string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export interface IFigmaVariablesMap {
|
|
26
|
+
[key: string]: IFigmaVariable<IColorComponents>;
|
|
27
|
+
}
|
|
28
|
+
export type IFigmaColorVariables = IFigmaVariablesBase & IFigmaVariablesMap;
|
|
29
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/common/types.ts"],"names":[],"mappings":"AAAA,oBAAY,aAAa;IACrB,GAAG,QAAQ;IACX,IAAI,SAAS;IACb,IAAI,SAAS;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,OAAO;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,CAAC,CAAC;IACV,WAAW,EAAE;QACT,sBAAsB,EAAE,MAAM,CAAC;QAC/B,kBAAkB,EAAE,MAAM,EAAE,CAAC;KAChC,CAAC;CACL;AAED,MAAM,WAAW,mBAAmB;IAChC,WAAW,EAAE;QACT,oBAAoB,EAAE,MAAM,CAAC;KAChC,CAAC;CACL;AAED,MAAM,WAAW,kBAAkB;IAC/B,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAAC,gBAAgB,CAAC,CAAC;CACnD;AAED,MAAM,MAAM,oBAAoB,GAAG,mBAAmB,GAAG,kBAAkB,CAAC"}
|
package/index.d.ts
ADDED
package/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC"}
|
package/index.js
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
var k = Object.defineProperty;
|
|
2
|
+
var x = (n, e, t) => e in n ? k(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
|
+
var l = (n, e, t) => x(n, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { tsImport as F } from "ts-import";
|
|
5
|
+
import { existsSync as h } from "node:fs";
|
|
6
|
+
import { readFile as u, mkdir as O, writeFile as b, rm as j } from "node:fs/promises";
|
|
7
|
+
import { resolve as w } from "node:path";
|
|
8
|
+
const a = class a {
|
|
9
|
+
static resolveReadPath(e) {
|
|
10
|
+
if (!e || !e.trim())
|
|
11
|
+
throw new Error("File path must be a non-empty string");
|
|
12
|
+
return w(a.baseDir, e);
|
|
13
|
+
}
|
|
14
|
+
static resolveWritePath(e, t) {
|
|
15
|
+
const r = w(a.baseDir, t ?? "");
|
|
16
|
+
return {
|
|
17
|
+
targetDir: r,
|
|
18
|
+
targetPath: w(r, e)
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
static handleReadError(e, t) {
|
|
22
|
+
throw e.code === "ENOENT" ? new Error(`File not found: ${t}`) : new Error(
|
|
23
|
+
`Failed to read file "${t}": ${e.message ?? String(e)}`
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
static async read(e, t = "utf8") {
|
|
27
|
+
const r = a.resolveReadPath(e);
|
|
28
|
+
try {
|
|
29
|
+
return await u(r, { encoding: t });
|
|
30
|
+
} catch (s) {
|
|
31
|
+
a.handleReadError(s, r);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
static async readBuffer(e) {
|
|
35
|
+
const t = a.resolveReadPath(e);
|
|
36
|
+
try {
|
|
37
|
+
return await u(t);
|
|
38
|
+
} catch (r) {
|
|
39
|
+
a.handleReadError(r, t);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
static async readJson(e) {
|
|
43
|
+
const t = a.resolveReadPath(e);
|
|
44
|
+
try {
|
|
45
|
+
const r = await u(t, { encoding: "utf8" });
|
|
46
|
+
try {
|
|
47
|
+
return JSON.parse(r);
|
|
48
|
+
} catch (s) {
|
|
49
|
+
throw new Error(`Failed to parse JSON from "${t}": ${s.message}`);
|
|
50
|
+
}
|
|
51
|
+
} catch (r) {
|
|
52
|
+
a.handleReadError(r, t);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
static async write(e, t = "", r = {}) {
|
|
56
|
+
const { directory: s, overwrite: o = !0 } = r, { targetDir: i, targetPath: c } = a.resolveWritePath(e, s);
|
|
57
|
+
if (!o && h(c))
|
|
58
|
+
throw new Error(`File ${c} already exists`);
|
|
59
|
+
return await O(i, { recursive: !0 }), await b(c, t, { encoding: "utf8" }), c;
|
|
60
|
+
}
|
|
61
|
+
static async writeWithExtension(e, t, r = "", s) {
|
|
62
|
+
const o = t.startsWith(".") ? t : `.${t}`, i = `${e}${o}`;
|
|
63
|
+
return a.write(i, r, s);
|
|
64
|
+
}
|
|
65
|
+
static exists(e) {
|
|
66
|
+
const t = a.resolveReadPath(e);
|
|
67
|
+
return h(t);
|
|
68
|
+
}
|
|
69
|
+
static async delete(e, t) {
|
|
70
|
+
const { targetPath: r } = a.resolveWritePath(e, t);
|
|
71
|
+
h(r) && await j(r, { force: !0 });
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
l(a, "baseDir", process.cwd());
|
|
75
|
+
let f = a;
|
|
76
|
+
const d = class d {
|
|
77
|
+
static async create() {
|
|
78
|
+
if (f.exists(d.configFileName))
|
|
79
|
+
throw new Error("The file already exists");
|
|
80
|
+
await f.write(d.configFileName, "", { overwrite: !1 });
|
|
81
|
+
}
|
|
82
|
+
async load() {
|
|
83
|
+
try {
|
|
84
|
+
const e = await F.compile(d.configFileName);
|
|
85
|
+
if (!e) throw new Error();
|
|
86
|
+
return e.default;
|
|
87
|
+
} catch (e) {
|
|
88
|
+
console.error("Cannot find module gts.config.ts", e);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
l(d, "configFileName", "gts.config.ts");
|
|
93
|
+
let m = d;
|
|
94
|
+
const I = (n) => {
|
|
95
|
+
const e = new URLSearchParams();
|
|
96
|
+
return Object.keys(n).forEach((t) => {
|
|
97
|
+
Array.isArray(n[t]) ? n[t].forEach((r) => e.append(`${t}[]`, r)) : e.append(t, n[t]);
|
|
98
|
+
}), e;
|
|
99
|
+
}, q = (n, e = 50) => {
|
|
100
|
+
const t = [];
|
|
101
|
+
for (let r = 0; r < n.length; r += e)
|
|
102
|
+
t.push(n.slice(r, r + e));
|
|
103
|
+
return t;
|
|
104
|
+
};
|
|
105
|
+
class g {
|
|
106
|
+
constructor(e, t) {
|
|
107
|
+
l(this, "figmaToken");
|
|
108
|
+
l(this, "fileId");
|
|
109
|
+
l(this, "onTimeMeasureHandler");
|
|
110
|
+
this.figmaToken = e, this.fileId = t;
|
|
111
|
+
}
|
|
112
|
+
setOnTimeMeasureHandler(e) {
|
|
113
|
+
this.onTimeMeasureHandler = e;
|
|
114
|
+
}
|
|
115
|
+
static async returnJSON(e) {
|
|
116
|
+
const t = await e.json();
|
|
117
|
+
if (!e.ok) {
|
|
118
|
+
let r = "Request failed";
|
|
119
|
+
throw new Error(r);
|
|
120
|
+
}
|
|
121
|
+
return t;
|
|
122
|
+
}
|
|
123
|
+
async performControlledRequest(e, { params: t = {}, timeout: r = 3e4, abortController: s = new AbortController() } = {}) {
|
|
124
|
+
var y;
|
|
125
|
+
const o = Object.entries(t).reduce((E, [N, P]) => typeof P < "u" ? { ...E, [N]: P } : E, {}), i = `https://api.figma.com/v1${e}${o && Object.keys(o).length ? `?${I(o)}` : ""}`;
|
|
126
|
+
console.log("endpoinWithParams=", i);
|
|
127
|
+
const c = setTimeout(() => s.abort(), r), p = {
|
|
128
|
+
"Content-Type": "application/json",
|
|
129
|
+
...this.figmaToken && { "X-Figma-Token": this.figmaToken }
|
|
130
|
+
}, $ = {
|
|
131
|
+
method: "GET",
|
|
132
|
+
headers: p,
|
|
133
|
+
signal: s.signal
|
|
134
|
+
}, T = performance.now(), R = await fetch(`${i}`, $);
|
|
135
|
+
clearTimeout(c);
|
|
136
|
+
const v = performance.now() - T;
|
|
137
|
+
return (y = this.onTimeMeasureHandler) == null || y.call(this, i, p, v), R;
|
|
138
|
+
}
|
|
139
|
+
async request(e, t) {
|
|
140
|
+
var s;
|
|
141
|
+
const r = await this.performControlledRequest(e, {
|
|
142
|
+
...t
|
|
143
|
+
});
|
|
144
|
+
return (s = r.headers.get("content-type")) != null && s.includes("application/json") ? g.returnJSON(r) : r;
|
|
145
|
+
}
|
|
146
|
+
async getComponents() {
|
|
147
|
+
return this.request(`/files/${this.fileId}/components`);
|
|
148
|
+
}
|
|
149
|
+
async getStyles() {
|
|
150
|
+
return this.request(`/files/${this.fileId}/styles`);
|
|
151
|
+
}
|
|
152
|
+
async getNodes(e) {
|
|
153
|
+
const t = q(e).map(
|
|
154
|
+
(o) => this.request(`/files/${this.fileId}/nodes`, { params: { ids: o.join(",") } })
|
|
155
|
+
), r = await Promise.all(t);
|
|
156
|
+
return {
|
|
157
|
+
...r[0],
|
|
158
|
+
nodes: r.reduce((o, i) => ({ ...o, ...i.nodes }), {})
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const J = async () => {
|
|
163
|
+
const e = await new m().load();
|
|
164
|
+
if (!e)
|
|
165
|
+
throw new Error("Заполнить ошибку через нейронку");
|
|
166
|
+
const { figmaToken: t, fileId: r, modules: s } = e, o = new g(t, r);
|
|
167
|
+
await Promise.all(
|
|
168
|
+
// [
|
|
169
|
+
// colorsFromStyles({
|
|
170
|
+
// input: { variablePaths: ['./dark.tokens.json', './light.tokens.json'] },
|
|
171
|
+
// output: { jsonDir: './fromStyles', stylesDir: './fromStyles' },
|
|
172
|
+
// }),
|
|
173
|
+
// colorsFromVariables({
|
|
174
|
+
// input: { variablePaths: ['./dark.tokens.json', './light.tokens.json'] },
|
|
175
|
+
// output: { jsonDir: './fromVariables', stylesDir: './fromVariables' },
|
|
176
|
+
// }),
|
|
177
|
+
// ]
|
|
178
|
+
s.map((i) => i.executor({ figmaApiClient: o }))
|
|
179
|
+
);
|
|
180
|
+
}, A = async () => {
|
|
181
|
+
await m.create(), console.log("\x1B[32m%s\x1B[0m", "✔️ Configuration file created gts.config.ts");
|
|
182
|
+
};
|
|
183
|
+
export {
|
|
184
|
+
J as generate,
|
|
185
|
+
A as init
|
|
186
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IModule } from '../types';
|
|
2
|
+
export interface IColorsFromStylesInput {
|
|
3
|
+
variablePaths?: string[];
|
|
4
|
+
}
|
|
5
|
+
export interface IColorsFromStylesOutput {
|
|
6
|
+
jsonDir: string;
|
|
7
|
+
stylesDir: string;
|
|
8
|
+
jsonFileName?: string;
|
|
9
|
+
cssFileName?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface IColorsFromStylesParams {
|
|
12
|
+
input?: IColorsFromStylesInput;
|
|
13
|
+
output: IColorsFromStylesOutput;
|
|
14
|
+
}
|
|
15
|
+
export declare const colorsFromStyles: ({ input, output: { jsonDir, stylesDir, jsonFileName, cssFileName }, }: IColorsFromStylesParams) => IModule;
|
|
16
|
+
//# sourceMappingURL=colorsFromStyles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colorsFromStyles.d.ts","sourceRoot":"","sources":["../../../src/modules/colors/colorsFromStyles.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAKxC,MAAM,WAAW,sBAAsB;IACnC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED,MAAM,WAAW,uBAAuB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,uBAAuB;IACpC,KAAK,CAAC,EAAE,sBAAsB,CAAC;IAC/B,MAAM,EAAE,uBAAuB,CAAC;CACnC;AAED,eAAO,MAAM,gBAAgB,GAAI,uEAG9B,uBAAuB,KAAG,OA4H3B,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IModule } from '../types';
|
|
2
|
+
export interface IColorsFromVariablesInput {
|
|
3
|
+
variablePaths: string[];
|
|
4
|
+
}
|
|
5
|
+
export interface IColorsFromVariablesOutput {
|
|
6
|
+
jsonDir: string;
|
|
7
|
+
stylesDir: string;
|
|
8
|
+
jsonFileName?: string;
|
|
9
|
+
cssFileName?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface IColorsFromVariablesParams {
|
|
12
|
+
input: IColorsFromVariablesInput;
|
|
13
|
+
output: IColorsFromVariablesOutput;
|
|
14
|
+
}
|
|
15
|
+
export declare const colorsFromVariables: ({ input: { variablePaths }, output: { jsonDir, stylesDir, jsonFileName, cssFileName }, }: IColorsFromVariablesParams) => IModule;
|
|
16
|
+
//# sourceMappingURL=colorsFromVariables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colorsFromVariables.d.ts","sourceRoot":"","sources":["../../../src/modules/colors/colorsFromVariables.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAIxC,MAAM,WAAW,yBAAyB;IACtC,aAAa,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,0BAA0B;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,0BAA0B;IACvC,KAAK,EAAE,yBAAyB,CAAC;IACjC,MAAM,EAAE,0BAA0B,CAAC;CACtC;AAED,eAAO,MAAM,mBAAmB,GAAI,0FAGjC,0BAA0B,KAAG,OA2G9B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/colors/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/modules/colors/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1C"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ColorStop, GradientPaint, Paint, Vector } from '@figma/rest-api-spec';
|
|
2
|
+
import { IColorToken } from './types';
|
|
3
|
+
export declare const rgbToHex: ({ r, g, b }: {
|
|
4
|
+
r: number;
|
|
5
|
+
g: number;
|
|
6
|
+
b: number;
|
|
7
|
+
}) => string;
|
|
8
|
+
export declare const getSolidColor: ({ opacity, r, g, b }: {
|
|
9
|
+
opacity: number;
|
|
10
|
+
r: number;
|
|
11
|
+
g: number;
|
|
12
|
+
b: number;
|
|
13
|
+
}) => string;
|
|
14
|
+
export declare const getAngelDeg: (gradientHandlePositions: Vector[], adjustemntDeg?: number) => number;
|
|
15
|
+
export declare const getMappedColors: (gradientStops: ColorStop[]) => string;
|
|
16
|
+
export declare const getGradientCenterCoordinates: (gradientHandlePositions: Vector[]) => {
|
|
17
|
+
centerX: string;
|
|
18
|
+
centerY: string;
|
|
19
|
+
};
|
|
20
|
+
export declare const getGradientLinerColor: (paint: GradientPaint) => string;
|
|
21
|
+
export declare const getGradientRadius: (gradientHandlePositions: Vector[]) => {
|
|
22
|
+
radiusX: string;
|
|
23
|
+
radiusY: string;
|
|
24
|
+
};
|
|
25
|
+
export declare const getGradientRadial: (paint: GradientPaint) => string;
|
|
26
|
+
export declare const getGradientAnugular: (paint: GradientPaint) => string;
|
|
27
|
+
export declare const paintToColorToken: (paint: Paint) => string;
|
|
28
|
+
export declare const formatCSSBlock: (selector: string, variables: string[]) => string;
|
|
29
|
+
export declare const formatModeClassName: (modeName: string) => string;
|
|
30
|
+
export declare const getVariableName: (name: string) => string;
|
|
31
|
+
export declare const getCSSVariableName: (name: string) => string;
|
|
32
|
+
export declare const buildCSSVariables: (colorTokens: IColorToken[]) => Record<string, string[]>;
|
|
33
|
+
export declare const buildCSSContent: (cssVariables: Record<string, string[]>) => string;
|
|
34
|
+
export declare const buildJSONContent: (colorTokens: IColorToken[]) => string;
|
|
35
|
+
export declare const writeColorFiles: (jsonContent: string, cssContent: string, jsonDir: string, stylesDir: string, jsonFileName: string, cssFileName: string) => Promise<void>;
|
|
36
|
+
interface IGenerateFilesParams {
|
|
37
|
+
colorTokens: IColorToken[];
|
|
38
|
+
jsonDir: string;
|
|
39
|
+
stylesDir: string;
|
|
40
|
+
jsonFileName: string;
|
|
41
|
+
cssFileName: string;
|
|
42
|
+
}
|
|
43
|
+
export declare const generateColorFiles: ({ colorTokens, jsonDir, stylesDir, jsonFileName, cssFileName, }: IGenerateFilesParams) => Promise<void>;
|
|
44
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|
|
2
|
+
"name": "@greensight/gts",
|
|
3
|
+
"version": "1.0.0-alpha.4",
|
|
4
|
+
"description": "Generate design tokens from Figma",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"figma",
|
|
7
|
+
"design-tokens",
|
|
8
|
+
"tokens",
|
|
9
|
+
"figma-api",
|
|
10
|
+
"design-system",
|
|
11
|
+
"css-variables",
|
|
12
|
+
"typescript"
|
|
13
|
+
],
|
|
14
|
+
"private": false,
|
|
15
|
+
"type": "module",
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=16.0.0"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/greensight/gts"
|
|
22
|
+
},
|
|
23
|
+
"bugs": "https://github.com/greensight/gts/issues",
|
|
24
|
+
"homepage": "https://github.com/greensight/gts",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"rimraf": "^6.0.1",
|
|
28
|
+
"ts-import": "2.0.40"
|
|
29
|
+
},
|
|
30
|
+
"types": "./index.d.ts",
|
|
31
|
+
"module": "./index.js",
|
|
32
|
+
"main": "./index.js",
|
|
33
|
+
"bin": {
|
|
34
|
+
"gts-init": "./bin/init.js",
|
|
35
|
+
"gts-generate": "./bin/generate.js"
|
|
36
|
+
}
|
|
37
|
+
}
|