@hh.ru/magritte-design-tokens-utils 2.2.0 → 3.0.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/package.json +3 -4
- package/cli/index.d.ts +0 -1
- package/cli/index.js +0 -40
- package/cli/index.js.map +0 -1
- package/cli/tokenize.d.ts +0 -2
- package/cli/tokenize.js +0 -48
- package/cli/tokenize.js.map +0 -1
- package/cli.js +0 -3
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hh.ru/magritte-design-tokens-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"bin": "cli.js",
|
|
8
7
|
"scripts": {
|
|
9
|
-
"build": "yarn root:build $(pwd)
|
|
8
|
+
"build": "yarn root:build $(pwd)",
|
|
10
9
|
"build-test-branch": "yarn root:build-test-branch $(pwd)",
|
|
11
10
|
"prepack": "yarn root:prepack $(pwd)",
|
|
12
11
|
"postpublish": "yarn root:postpublish $(pwd)",
|
|
@@ -26,5 +25,5 @@
|
|
|
26
25
|
"publishConfig": {
|
|
27
26
|
"access": "public"
|
|
28
27
|
},
|
|
29
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "a823b2d582e812bf99b5fdf32058a93eaa59076b"
|
|
30
29
|
}
|
package/cli/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/cli/index.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { tokenize } from './tokenize.js';
|
|
4
|
-
import { filterThemeSets, prepareThemesTokens } from '../prepare.js';
|
|
5
|
-
import { purify } from '../purify.js';
|
|
6
|
-
import 'style-dictionary';
|
|
7
|
-
import '../tokenize.js';
|
|
8
|
-
import 'change-case';
|
|
9
|
-
import 'spring-easing';
|
|
10
|
-
import 'token-transformer';
|
|
11
|
-
import '../constants.js';
|
|
12
|
-
|
|
13
|
-
const main = () => {
|
|
14
|
-
if (process.argv.length < 3) {
|
|
15
|
-
console.error('Missing required argument: file');
|
|
16
|
-
process.exit(1);
|
|
17
|
-
}
|
|
18
|
-
const inputFile = process.argv[2];
|
|
19
|
-
let tokens;
|
|
20
|
-
try {
|
|
21
|
-
tokens = fs.readFileSync(path.resolve(process.cwd(), inputFile), 'utf8');
|
|
22
|
-
tokens = JSON.parse(tokens);
|
|
23
|
-
}
|
|
24
|
-
catch (e) {
|
|
25
|
-
console.error('Error while reading tokens file');
|
|
26
|
-
console.error(e);
|
|
27
|
-
process.exit(1);
|
|
28
|
-
}
|
|
29
|
-
const purifiedTokens = purify(tokens);
|
|
30
|
-
const themes = filterThemeSets(purifiedTokens);
|
|
31
|
-
if (themes.length !== 1) {
|
|
32
|
-
console.error('Tokens must contain exactly one theme');
|
|
33
|
-
console.error(`Themes found: [${themes.join(', ')}}]`);
|
|
34
|
-
process.exit(1);
|
|
35
|
-
}
|
|
36
|
-
const prepareTheme = prepareThemesTokens(purifiedTokens)[0];
|
|
37
|
-
tokenize(prepareTheme);
|
|
38
|
-
};
|
|
39
|
-
main();
|
|
40
|
-
//# sourceMappingURL=index.js.map
|
package/cli/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/cli/index.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\n\nimport { tokenize } from '@hh.ru/magritte-design-tokens-utils/cli/tokenize';\nimport { filterThemeSets, prepareThemesTokens } from '@hh.ru/magritte-design-tokens-utils/prepare';\nimport { purify } from '@hh.ru/magritte-design-tokens-utils/purify';\nimport { Tokens } from '@hh.ru/magritte-design-tokens-utils/types';\n\nconst main = () => {\n if (process.argv.length < 3) {\n console.error('Missing required argument: file');\n process.exit(1);\n }\n const inputFile = process.argv[2];\n\n let tokens;\n try {\n tokens = fs.readFileSync(path.resolve(process.cwd(), inputFile), 'utf8');\n tokens = JSON.parse(tokens) as Tokens;\n } catch (e) {\n console.error('Error while reading tokens file');\n console.error(e);\n process.exit(1);\n }\n const purifiedTokens = purify(tokens);\n const themes = filterThemeSets(purifiedTokens);\n if (themes.length !== 1) {\n console.error('Tokens must contain exactly one theme');\n console.error(`Themes found: [${themes.join(', ')}}]`);\n process.exit(1);\n }\n const prepareTheme = prepareThemesTokens(purifiedTokens)[0];\n\n tokenize(prepareTheme);\n};\n\nmain();\n"],"names":[],"mappings":";;;;;;;;;;;;AAQA,MAAM,IAAI,GAAG,MAAK;IACd,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;AACzB,QAAA,OAAO,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;AACjD,QAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACnB;IACD,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAElC,IAAA,IAAI,MAAM,CAAC;AACX,IAAA,IAAI;AACA,QAAA,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,CAAC;AACzE,QAAA,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAW,CAAC;KACzC;IAAC,OAAO,CAAC,EAAE;AACR,QAAA,OAAO,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;AACjD,QAAA,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACjB,QAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACnB;AACD,IAAA,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;AACtC,IAAA,MAAM,MAAM,GAAG,eAAe,CAAC,cAAc,CAAC,CAAC;AAC/C,IAAA,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;AACrB,QAAA,OAAO,CAAC,KAAK,CAAC,uCAAuC,CAAC,CAAC;AACvD,QAAA,OAAO,CAAC,KAAK,CAAC,CAAA,eAAA,EAAkB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAI,EAAA,CAAA,CAAC,CAAC;AACvD,QAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACnB;IACD,MAAM,YAAY,GAAG,mBAAmB,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;IAE5D,QAAQ,CAAC,YAAY,CAAC,CAAC;AAC3B,CAAC,CAAC;AAEF,IAAI,EAAE"}
|
package/cli/tokenize.d.ts
DELETED
package/cli/tokenize.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import StyleDictionary from 'style-dictionary';
|
|
3
|
-
import { kebabWithUnderscoreTransformer, cssFormatter } from '../tokenize.js';
|
|
4
|
-
import 'change-case';
|
|
5
|
-
import 'spring-easing';
|
|
6
|
-
|
|
7
|
-
// eslint-disable-next-line no-template-curly-in-string
|
|
8
|
-
const versionPostfix = '-v${major}-${minor}-${patch}';
|
|
9
|
-
const tokenize = ({ themeTokens: tokens, themeName }) => {
|
|
10
|
-
const tmpFileName = `tokens.${Date.now()}.json`;
|
|
11
|
-
fs.writeFileSync(tmpFileName, JSON.stringify(tokens, null, 2));
|
|
12
|
-
const config = {
|
|
13
|
-
source: [tmpFileName],
|
|
14
|
-
platforms: {
|
|
15
|
-
ts: {
|
|
16
|
-
transformGroup: 'ts',
|
|
17
|
-
transforms: ['name/cti/kebabWithUnderscore'],
|
|
18
|
-
prefix: 'magritte-',
|
|
19
|
-
buildPath: './',
|
|
20
|
-
files: [
|
|
21
|
-
{
|
|
22
|
-
destination: `magritte${themeName.charAt(0).toUpperCase()}${themeName.slice(1)}Theme.ts`,
|
|
23
|
-
format: 'ts/variables',
|
|
24
|
-
},
|
|
25
|
-
],
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
const build = StyleDictionary.extend(config);
|
|
30
|
-
build.registerTransform(kebabWithUnderscoreTransformer);
|
|
31
|
-
build.registerFormat({
|
|
32
|
-
name: 'ts/variables',
|
|
33
|
-
formatter({ dictionary }) {
|
|
34
|
-
return `export default (tokensVersion: string): { tokensString: string; themeClassName: string } => {
|
|
35
|
-
const [major, minor, patch] = tokensVersion.split('.');
|
|
36
|
-
const tokensString = \`
|
|
37
|
-
.magritte-${themeName}-theme {\n${cssFormatter(dictionary, versionPostfix)}\n}\`;
|
|
38
|
-
|
|
39
|
-
return { tokensString, themeClassName: 'magritte-${themeName}-theme' };
|
|
40
|
-
};\n`;
|
|
41
|
-
},
|
|
42
|
-
});
|
|
43
|
-
build.buildAllPlatforms();
|
|
44
|
-
fs.unlinkSync(tmpFileName);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export { tokenize };
|
|
48
|
-
//# sourceMappingURL=tokenize.js.map
|
package/cli/tokenize.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tokenize.js","sources":["../../src/cli/tokenize.ts"],"sourcesContent":["import fs from 'fs';\nimport StyleDictionary, { Config } from 'style-dictionary';\n\nimport { kebabWithUnderscoreTransformer, cssFormatter } from '@hh.ru/magritte-design-tokens-utils/tokenize';\nimport { PreparedThemesTokens } from '@hh.ru/magritte-design-tokens-utils/types';\n\n// eslint-disable-next-line no-template-curly-in-string\nconst versionPostfix = '-v${major}-${minor}-${patch}';\n\nexport const tokenize = ({ themeTokens: tokens, themeName }: PreparedThemesTokens): void => {\n const tmpFileName = `tokens.${Date.now()}.json`;\n fs.writeFileSync(tmpFileName, JSON.stringify(tokens, null, 2));\n\n const config: Config = {\n source: [tmpFileName],\n platforms: {\n ts: {\n transformGroup: 'ts',\n transforms: ['name/cti/kebabWithUnderscore'],\n prefix: 'magritte-',\n buildPath: './',\n files: [\n {\n destination: `magritte${themeName.charAt(0).toUpperCase()}${themeName.slice(1)}Theme.ts`,\n format: 'ts/variables',\n },\n ],\n },\n },\n };\n\n const build = StyleDictionary.extend(config);\n\n build.registerTransform(kebabWithUnderscoreTransformer);\n\n build.registerFormat({\n name: 'ts/variables',\n formatter({ dictionary }) {\n return `export default (tokensVersion: string): { tokensString: string; themeClassName: string } => {\n const [major, minor, patch] = tokensVersion.split('.');\n const tokensString = \\`\n.magritte-${themeName}-theme {\\n${cssFormatter(dictionary, versionPostfix)}\\n}\\`;\n\n return { tokensString, themeClassName: 'magritte-${themeName}-theme' };\n};\\n`;\n },\n });\n\n build.buildAllPlatforms();\n fs.unlinkSync(tmpFileName);\n};\n"],"names":[],"mappings":";;;;;;AAMA;AACA,MAAM,cAAc,GAAG,8BAA8B,CAAC;AAE/C,MAAM,QAAQ,GAAG,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,EAAwB,KAAU;IACvF,MAAM,WAAW,GAAG,CAAU,OAAA,EAAA,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC;AAChD,IAAA,EAAE,CAAC,aAAa,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AAE/D,IAAA,MAAM,MAAM,GAAW;QACnB,MAAM,EAAE,CAAC,WAAW,CAAC;AACrB,QAAA,SAAS,EAAE;AACP,YAAA,EAAE,EAAE;AACA,gBAAA,cAAc,EAAE,IAAI;gBACpB,UAAU,EAAE,CAAC,8BAA8B,CAAC;AAC5C,gBAAA,MAAM,EAAE,WAAW;AACnB,gBAAA,SAAS,EAAE,IAAI;AACf,gBAAA,KAAK,EAAE;AACH,oBAAA;AACI,wBAAA,WAAW,EAAE,CAAW,QAAA,EAAA,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAU,QAAA,CAAA;AACxF,wBAAA,MAAM,EAAE,cAAc;AACzB,qBAAA;AACJ,iBAAA;AACJ,aAAA;AACJ,SAAA;KACJ,CAAC;IAEF,MAAM,KAAK,GAAG,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAE7C,IAAA,KAAK,CAAC,iBAAiB,CAAC,8BAA8B,CAAC,CAAC;IAExD,KAAK,CAAC,cAAc,CAAC;AACjB,QAAA,IAAI,EAAE,cAAc;QACpB,SAAS,CAAC,EAAE,UAAU,EAAE,EAAA;YACpB,OAAO,CAAA;;;AAGP,UAAA,EAAA,SAAS,aAAa,YAAY,CAAC,UAAU,EAAE,cAAc,CAAC,CAAA;;uDAEnB,SAAS,CAAA;KAC3D,CAAC;SACG;AACJ,KAAA,CAAC,CAAC;IAEH,KAAK,CAAC,iBAAiB,EAAE,CAAC;AAC1B,IAAA,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;AAC/B;;;;"}
|
package/cli.js
DELETED