@atls-ui-generators/icons 0.0.2

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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const standalone_1 = require("@babel/standalone");
7
+ const assert_1 = __importDefault(require("assert"));
8
+ const commander_1 = require("commander");
9
+ const fs_1 = require("fs");
10
+ const fs_2 = require("fs");
11
+ const fs_3 = require("fs");
12
+ const fs_4 = require("fs");
13
+ const path_1 = require("path");
14
+ const svgr_1 = require("./svgr");
15
+ const command = new commander_1.Command()
16
+ .name('Icons generator')
17
+ .argument('path <string>', 'Path to save icons')
18
+ .option('-i, --icons path <string>', 'Path to icons dir')
19
+ .option('-r, --replacements path <string>', 'Path to replacements file')
20
+ .action(async (path, options) => {
21
+ assert_1.default.ok(options.icons, 'Icons dir path is required');
22
+ const iconsPath = (0, path_1.join)(process.cwd(), options.icons);
23
+ const genPath = (0, path_1.join)(process.cwd(), path);
24
+ if (!(0, fs_3.existsSync)(genPath)) {
25
+ (0, fs_4.mkdirSync)(genPath);
26
+ }
27
+ assert_1.default.ok((0, fs_2.lstatSync)(genPath).isDirectory(), 'Path to save icons should point to a directory');
28
+ assert_1.default.ok((0, fs_2.lstatSync)(iconsPath).isDirectory(), 'Icons path should point to a directory');
29
+ let replacements = {};
30
+ if (options.replacements) {
31
+ const replacementsFile = (0, fs_1.readFileSync)((0, path_1.join)(process.cwd(), options.replacements)).toString('utf-8');
32
+ const { code } = (0, standalone_1.transform)(replacementsFile, { presets: ['env'] });
33
+ replacements = eval(code);
34
+ }
35
+ await (0, svgr_1.build)(iconsPath, genPath, replacements);
36
+ console.log(`Generated into ${genPath}`);
37
+ });
38
+ command.parse();
@@ -0,0 +1,7 @@
1
+ export interface GetColorReplacementOptions {
2
+ themePaths?: Array<string>;
3
+ color: string;
4
+ }
5
+ export declare const getColorReplacement: (options: GetColorReplacementOptions) => {
6
+ [x: string]: string;
7
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getColorReplacement = void 0;
4
+ const getColorReplacement = (options) => ({
5
+ [options.color]: `{(theme.colors${(options.themePaths || []).reduce((str, prop) => `${str}.${prop}`, '')}[props.color || 0] || props.color) || "${options.color}"}`,
6
+ });
7
+ exports.getColorReplacement = getColorReplacement;
@@ -0,0 +1,2 @@
1
+ export * from './get-color-replacement.util';
2
+ export * from './svgr';
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./get-color-replacement.util"), exports);
18
+ __exportStar(require("./svgr"), exports);
package/dist/svgr.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const build: (iconsPath: string, targetDir: string, replacements: object) => Promise<void>;
package/dist/svgr.js ADDED
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.build = void 0;
30
+ const prettierPlugin = __importStar(require("@atls/prettier-plugin"));
31
+ const config_prettier_1 = __importDefault(require("@atls/config-prettier"));
32
+ const core_1 = __importDefault(require("@svgr/core"));
33
+ const camelcase_1 = __importDefault(require("camelcase"));
34
+ const fs_extra_promise_1 = __importDefault(require("fs-extra-promise"));
35
+ const glob_promise_1 = __importDefault(require("glob-promise"));
36
+ const path_1 = __importDefault(require("path"));
37
+ const parser_babel_1 = __importDefault(require("prettier/parser-babel"));
38
+ const parser_typescript_1 = __importDefault(require("prettier/parser-typescript"));
39
+ const standalone_1 = require("prettier/standalone");
40
+ const svgrTemplate = ({ template }, opts, { componentName, jsx }) => {
41
+ const typeScriptTpl = template.smart({ plugins: ['typescript', 'prettier'] });
42
+ return typeScriptTpl.ast `
43
+ import React from 'react'
44
+ import { useTheme } from '@emotion/react'
45
+ import { IconProps } from '../icons.interfaces'
46
+
47
+ export const ${componentName} = (props: IconProps) => {
48
+ const theme: any = useTheme()
49
+
50
+ return ${jsx}
51
+ }
52
+ `;
53
+ };
54
+ const read = (files) => Promise.all(files.map(async (iconPath) => ({
55
+ name: `${(0, camelcase_1.default)(path_1.default.basename(iconPath, path_1.default.extname(iconPath)), {
56
+ pascalCase: true,
57
+ }).replace('50+', 'FiftyPlus')}Icon`,
58
+ source: (await fs_extra_promise_1.default.readFileAsync(iconPath)).toString(),
59
+ })));
60
+ const compile = (icons, replacements) => Promise.all(icons.map(async (icon) => ({
61
+ name: icon.name,
62
+ code: await (0, core_1.default)(icon.source.replace(/mask0/g, icon.name), {
63
+ icon: true,
64
+ template: svgrTemplate,
65
+ replaceAttrValues: replacements[icon.name] || {},
66
+ }, { componentName: icon.name.replace('50+', 'FiftyPlus') }),
67
+ })));
68
+ const save = async (sources, targetDir) => Promise.all(sources.map((source) => fs_extra_promise_1.default.writeFileAsync(path_1.default.join(targetDir, `${source.name}.tsx`), (0, standalone_1.format)(`/* eslint-disable */\n${source.code}`, {
69
+ ...config_prettier_1.default,
70
+ filepath: path_1.default.join(targetDir, `${source.name}.tsx`),
71
+ plugins: [parser_typescript_1.default, parser_babel_1.default, prettierPlugin],
72
+ }))));
73
+ const createIndex = (sources, targetDir) => fs_extra_promise_1.default.writeFileAsync(path_1.default.join(targetDir, 'index.ts'), `${sources.map((source) => `export * from './${source.name}'`).join('\n')}\n`);
74
+ const build = async (iconsPath, targetDir, replacements) => {
75
+ const prettifyIconsPath = () => {
76
+ const parts = iconsPath.split('');
77
+ if (parts[parts.length - 1] === '/') {
78
+ parts.pop();
79
+ return parts.join('');
80
+ }
81
+ return iconsPath;
82
+ };
83
+ const files = await (0, glob_promise_1.default)(`${prettifyIconsPath()}/*.svg`);
84
+ const icons = await read(files);
85
+ const sources = await compile(icons.filter((icon) => icon.source), replacements);
86
+ await fs_extra_promise_1.default.ensureDir(targetDir);
87
+ await save(sources, targetDir);
88
+ await createIndex(sources, targetDir);
89
+ };
90
+ exports.build = build;
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@atls-ui-generators/icons",
3
+ "version": "0.0.2",
4
+ "license": "BSD-3-Clause",
5
+ "main": "dist/index.js",
6
+ "bin": {
7
+ "generate-icons": "dist/generator.js"
8
+ },
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "scripts": {
13
+ "build": "yarn library build",
14
+ "prepack": "yarn run build",
15
+ "postpack": "rm -rf dist"
16
+ },
17
+ "dependencies": {
18
+ "@atls-ui-generators/utils": "0.0.4",
19
+ "@atls/config-prettier": "^0.0.5",
20
+ "@atls/prettier-plugin": "^0.0.5",
21
+ "@babel/standalone": "^7.19.5",
22
+ "@svgr/core": "5.5.0",
23
+ "camelcase": "^6.3.0",
24
+ "commander": "^9.4.1",
25
+ "fs-extra-promise": "^1.0.1",
26
+ "glob-promise": "^5.0.0",
27
+ "prettier": "^2.5.1"
28
+ },
29
+ "devDependencies": {
30
+ "@atls-ui-parts/button": "0.0.10",
31
+ "@types/babel__standalone": "^7",
32
+ "@types/fs-extra-promise": "^1",
33
+ "@types/prettier": "^2",
34
+ "styled-tools": "^1.7.2"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public",
38
+ "main": "dist/index.js",
39
+ "typings": "dist/index.d.ts"
40
+ },
41
+ "typings": "dist/index.d.ts"
42
+ }