kist 0.0.0 → 0.1.30
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 +21 -0
- package/README.md +298 -3
- package/js/actions/CoreActions.d.ts +6 -0
- package/js/actions/CoreActions.js +47 -0
- package/js/actions/DirectoryCleanAction/DirectoryCleanAction.d.ts +36 -0
- package/js/actions/DirectoryCleanAction/DirectoryCleanAction.js +123 -0
- package/js/actions/DirectoryCleanAction/index.d.ts +2 -0
- package/js/actions/DirectoryCleanAction/index.js +8 -0
- package/js/actions/DirectoryCopyAction/DirectoryCopyAction.d.ts +42 -0
- package/js/actions/DirectoryCopyAction/DirectoryCopyAction.js +118 -0
- package/js/actions/DirectoryCopyAction/index.d.ts +2 -0
- package/js/actions/DirectoryCopyAction/index.js +8 -0
- package/js/actions/DirectoryCreateAction/DirectoryCreateAction.d.ts +30 -0
- package/js/actions/DirectoryCreateAction/DirectoryCreateAction.js +85 -0
- package/js/actions/DirectoryCreateAction/index.d.ts +2 -0
- package/js/actions/DirectoryCreateAction/index.js +8 -0
- package/js/actions/DocumentationAction/DocumentationAction.d.ts +23 -0
- package/js/actions/DocumentationAction/DocumentationAction.js +88 -0
- package/js/actions/DocumentationAction/index.d.ts +2 -0
- package/js/actions/DocumentationAction/index.js +8 -0
- package/js/actions/FileCopyAction/FileCopyAction.d.ts +42 -0
- package/js/actions/FileCopyAction/FileCopyAction.js +127 -0
- package/js/actions/FileCopyAction/index.d.ts +2 -0
- package/js/actions/FileCopyAction/index.js +8 -0
- package/js/actions/FileRenameAction/FileRenameAction.d.ts +30 -0
- package/js/actions/FileRenameAction/FileRenameAction.js +84 -0
- package/js/actions/FileRenameAction/index.d.ts +2 -0
- package/js/actions/FileRenameAction/index.js +8 -0
- package/js/actions/JavaScriptMinifyAction/JavaScriptMinifyAction.d.ts +31 -0
- package/js/actions/JavaScriptMinifyAction/JavaScriptMinifyAction.js +98 -0
- package/js/actions/JavaScriptMinifyAction/index.d.ts +2 -0
- package/js/actions/JavaScriptMinifyAction/index.js +8 -0
- package/js/actions/JavaScriptMinifyAction/terser.config.d.ts +27 -0
- package/js/actions/JavaScriptMinifyAction/terser.config.js +119 -0
- package/js/actions/LintAction/LintAction.d.ts +17 -0
- package/js/actions/LintAction/LintAction.js +63 -0
- package/js/actions/LintAction/index.d.ts +2 -0
- package/js/actions/LintAction/index.js +8 -0
- package/js/actions/PackageManagerAction/PackageManagerAction.d.ts +57 -0
- package/js/actions/PackageManagerAction/PackageManagerAction.js +161 -0
- package/js/actions/PackageManagerAction/index.d.ts +2 -0
- package/js/actions/PackageManagerAction/index.js +8 -0
- package/js/actions/PackageManagerAction/package.config.d.ts +16 -0
- package/js/actions/PackageManagerAction/package.config.js +91 -0
- package/js/actions/StyleProcessingAction/StyleProcessingAction.d.ts +34 -0
- package/js/actions/StyleProcessingAction/StyleProcessingAction.js +164 -0
- package/js/actions/StyleProcessingAction/index.d.ts +2 -0
- package/js/actions/StyleProcessingAction/index.js +8 -0
- package/js/actions/StyleProcessingAction/postcss.config.compressed.d.ts +10 -0
- package/js/actions/StyleProcessingAction/postcss.config.compressed.js +31 -0
- package/js/actions/StyleProcessingAction/postcss.config.expanded.d.ts +16 -0
- package/js/actions/StyleProcessingAction/postcss.config.expanded.js +45 -0
- package/js/actions/SvgPackagerAction/SvgPackagerAction.d.ts +68 -0
- package/js/actions/SvgPackagerAction/SvgPackagerAction.js +186 -0
- package/js/actions/SvgPackagerAction/index.d.ts +2 -0
- package/js/actions/SvgPackagerAction/index.js +8 -0
- package/js/actions/SvgReaderAction/SvgReaderAction.d.ts +32 -0
- package/js/actions/SvgReaderAction/SvgReaderAction.js +87 -0
- package/js/actions/SvgReaderAction/index.d.ts +2 -0
- package/js/actions/SvgReaderAction/index.js +8 -0
- package/js/actions/SvgSpriteAction/SvgSpriteAction.d.ts +37 -0
- package/js/actions/SvgSpriteAction/SvgSpriteAction.js +114 -0
- package/js/actions/SvgSpriteAction/index.d.ts +2 -0
- package/js/actions/SvgSpriteAction/index.js +8 -0
- package/js/actions/SvgSpriteAction/svgsprite.config.d.ts +3 -0
- package/js/actions/SvgSpriteAction/svgsprite.config.js +117 -0
- package/js/actions/SvgToPngAction/SvgToPngAction.d.ts +28 -0
- package/js/actions/SvgToPngAction/SvgToPngAction.js +108 -0
- package/js/actions/SvgToPngAction/index.d.ts +2 -0
- package/js/actions/SvgToPngAction/index.js +8 -0
- package/js/actions/TypeScriptCompilerAction/TypeScriptCompilerAction.d.ts +28 -0
- package/js/actions/TypeScriptCompilerAction/TypeScriptCompilerAction.js +96 -0
- package/js/actions/TypeScriptCompilerAction/index.d.ts +2 -0
- package/js/actions/TypeScriptCompilerAction/index.js +8 -0
- package/js/actions/VersionWriteAction/VersionWriteAction.d.ts +45 -0
- package/js/actions/VersionWriteAction/VersionWriteAction.js +147 -0
- package/js/actions/VersionWriteAction/index.d.ts +2 -0
- package/js/actions/VersionWriteAction/index.js +8 -0
- package/js/cli/ArgumentParser.d.ts +62 -0
- package/js/cli/ArgumentParser.js +118 -0
- package/js/cli.d.ts +6 -0
- package/js/cli.js +58 -0
- package/js/core/abstract/AbstractProcess.d.ts +62 -0
- package/js/core/abstract/AbstractProcess.js +96 -0
- package/js/core/abstract/AbstractValidator.d.ts +72 -0
- package/js/core/abstract/AbstractValidator.js +128 -0
- package/js/core/config/ConfigLoader.d.ts +47 -0
- package/js/core/config/ConfigLoader.js +130 -0
- package/js/core/config/ConfigStore.d.ts +69 -0
- package/js/core/config/ConfigStore.js +168 -0
- package/js/core/config/defaultConfig.d.ts +5 -0
- package/js/core/config/defaultConfig.js +131 -0
- package/js/core/pipeline/Action.d.ts +60 -0
- package/js/core/pipeline/Action.js +77 -0
- package/js/core/pipeline/ActionRegistry.d.ts +80 -0
- package/js/core/pipeline/ActionRegistry.js +180 -0
- package/js/core/pipeline/Pipeline.d.ts +42 -0
- package/js/core/pipeline/Pipeline.js +107 -0
- package/js/core/pipeline/PipelineManager.d.ts +55 -0
- package/js/core/pipeline/PipelineManager.js +164 -0
- package/js/core/pipeline/Stage.d.ts +45 -0
- package/js/core/pipeline/Stage.js +110 -0
- package/js/core/pipeline/Step.d.ts +26 -0
- package/js/core/pipeline/Step.js +85 -0
- package/js/core/validation/OptionsValidator.d.ts +43 -0
- package/js/core/validation/OptionsValidator.js +123 -0
- package/js/index.d.ts +3 -0
- package/js/index.js +36 -0
- package/js/interface/ActionInterface.d.ts +57 -0
- package/js/interface/ActionInterface.js +5 -0
- package/js/interface/ActionPlugin.d.ts +4 -0
- package/js/interface/ActionPlugin.js +5 -0
- package/js/interface/ConfigInterface.d.ts +43 -0
- package/js/interface/ConfigInterface.js +5 -0
- package/js/interface/LiveOptionsInterface.d.ts +42 -0
- package/js/interface/LiveOptionsInterface.js +2 -0
- package/js/interface/MetadataInterface.d.ts +95 -0
- package/js/interface/MetadataInterface.js +2 -0
- package/js/interface/OptionsInterface.d.ts +45 -0
- package/js/interface/OptionsInterface.js +5 -0
- package/js/interface/PipelineOptionsInterface.d.ts +66 -0
- package/js/interface/PipelineOptionsInterface.js +5 -0
- package/js/interface/StageInterface.d.ts +79 -0
- package/js/interface/StageInterface.js +5 -0
- package/js/interface/StepInterface.d.ts +66 -0
- package/js/interface/StepInterface.js +5 -0
- package/js/interface/StepOptionsInterface.d.ts +38 -0
- package/js/interface/StepOptionsInterface.js +21 -0
- package/js/interface/index.d.ts +7 -0
- package/js/interface/index.js +3 -0
- package/js/kist.d.ts +58 -0
- package/js/kist.js +145 -0
- package/js/live/LiveServer.d.ts +95 -0
- package/js/live/LiveServer.js +233 -0
- package/js/live/LiveWatcher.d.ts +45 -0
- package/js/live/LiveWatcher.js +140 -0
- package/js/logger/Logger.d.ts +94 -0
- package/js/logger/Logger.js +151 -0
- package/js/logger/LoggerStyles.d.ts +23 -0
- package/js/logger/LoggerStyles.js +30 -0
- package/js/types/ActionOptionsType.d.ts +8 -0
- package/js/types/ActionOptionsType.js +2 -0
- package/js/types/index.d.ts +1 -0
- package/js/types/index.js +3 -0
- package/package.json +93 -7
- package/ts/actions/CoreActions.ts +64 -0
- package/ts/actions/DirectoryCleanAction/DirectoryCleanAction.ts +121 -0
- package/ts/actions/DirectoryCleanAction/index.ts +11 -0
- package/ts/actions/DirectoryCopyAction/DirectoryCopyAction.ts +118 -0
- package/ts/actions/DirectoryCopyAction/index.ts +11 -0
- package/ts/actions/DirectoryCreateAction/DirectoryCreateAction.ts +81 -0
- package/ts/actions/DirectoryCreateAction/index.ts +11 -0
- package/ts/actions/DocumentationAction/DocumentationAction.ts +100 -0
- package/ts/actions/DocumentationAction/index.ts +11 -0
- package/ts/actions/FileCopyAction/FileCopyAction.ts +125 -0
- package/ts/actions/FileCopyAction/index.ts +11 -0
- package/ts/actions/FileRenameAction/FileRenameAction.ts +82 -0
- package/ts/actions/FileRenameAction/index.ts +11 -0
- package/ts/actions/JavaScriptMinifyAction/JavaScriptMinifyAction.ts +109 -0
- package/ts/actions/JavaScriptMinifyAction/index.ts +11 -0
- package/ts/actions/JavaScriptMinifyAction/terser.config.ts +177 -0
- package/ts/actions/LintAction/LintAction.ts +67 -0
- package/ts/actions/LintAction/index.ts +11 -0
- package/ts/actions/PackageManagerAction/PackageManagerAction.ts +176 -0
- package/ts/actions/PackageManagerAction/index.ts +11 -0
- package/ts/actions/PackageManagerAction/package.config.ts +94 -0
- package/ts/actions/SassDocAction/SassDocAction.ts +66 -0
- package/ts/actions/SassDocAction/index.ts +11 -0
- package/ts/actions/StyleProcessingAction/StyleProcessingAction.ts +142 -0
- package/ts/actions/StyleProcessingAction/index.ts +11 -0
- package/ts/actions/StyleProcessingAction/postcss.config.compressed.ts +31 -0
- package/ts/actions/StyleProcessingAction/postcss.config.expanded.ts +47 -0
- package/ts/actions/SvgPackagerAction/SvgPackagerAction.ts +187 -0
- package/ts/actions/SvgPackagerAction/index.ts +11 -0
- package/ts/actions/SvgReaderAction/SvgReaderAction.ts +77 -0
- package/ts/actions/SvgReaderAction/index.ts +11 -0
- package/ts/actions/SvgSpriteAction/SvgSpriteAction.ts +127 -0
- package/ts/actions/SvgSpriteAction/index.ts +11 -0
- package/ts/actions/SvgSpriteAction/svgsprite.config.ts +123 -0
- package/ts/actions/SvgToPngAction/SvgToPngAction.ts +113 -0
- package/ts/actions/SvgToPngAction/index.ts +11 -0
- package/ts/actions/TypeScriptCompilerAction/TypeScriptCompilerAction.ts +117 -0
- package/ts/actions/TypeScriptCompilerAction/index.ts +11 -0
- package/ts/actions/VersionWriteAction/VersionWriteAction.ts +174 -0
- package/ts/actions/VersionWriteAction/index.ts +11 -0
- package/ts/actions/index.ts +0 -0
- package/ts/cli/ArgumentParser.ts +150 -0
- package/ts/cli/index.ts +1 -0
- package/ts/cli.ts +56 -0
- package/ts/core/abstract/AbstractProcess.ts +109 -0
- package/ts/core/abstract/AbstractSingleton.ts +46 -0
- package/ts/core/abstract/AbstractValidator.ts +167 -0
- package/ts/core/abstract/index.ts +0 -0
- package/ts/core/config/ConfigLoader.ts +141 -0
- package/ts/core/config/ConfigStore.ts +201 -0
- package/ts/core/config/defaultConfig.ts +154 -0
- package/ts/core/config/index.ts +0 -0
- package/ts/core/index.ts +34 -0
- package/ts/core/pipeline/Action.ts +101 -0
- package/ts/core/pipeline/ActionRegistry.ts +216 -0
- package/ts/core/pipeline/Pipeline.ts +121 -0
- package/ts/core/pipeline/PipelineManager.ts +170 -0
- package/ts/core/pipeline/Stage.ts +131 -0
- package/ts/core/pipeline/Step.ts +96 -0
- package/ts/core/pipeline/index.ts +0 -0
- package/ts/core/validation/ActionValidator.ts +97 -0
- package/ts/core/validation/ConfigValidator.ts +103 -0
- package/ts/core/validation/OptionsValidator.ts +179 -0
- package/ts/core/validation/StageValidator.ts +175 -0
- package/ts/core/validation/StepValidator.ts +203 -0
- package/ts/core/validation/index.ts +0 -0
- package/ts/index.ts +26 -0
- package/ts/interface/ActionInterface.ts +70 -0
- package/ts/interface/ActionPlugin.ts +14 -0
- package/ts/interface/ConfigInterface.ts +55 -0
- package/ts/interface/File.ts +24 -0
- package/ts/interface/LiveOptionsInterface.ts +46 -0
- package/ts/interface/MetadataInterface.ts +105 -0
- package/ts/interface/OptionsInterface.ts +58 -0
- package/ts/interface/PackageJson.ts +171 -0
- package/ts/interface/PipelineOptionsInterface.ts +74 -0
- package/ts/interface/SVG.ts +84 -0
- package/ts/interface/StageInterface.ts +96 -0
- package/ts/interface/StepInterface.ts +83 -0
- package/ts/interface/StepOptionsInterface.ts +57 -0
- package/ts/interface/index.ts +9 -0
- package/ts/kist.ts +161 -0
- package/ts/live/LiveServer.ts +311 -0
- package/ts/live/LiveWatcher.ts +150 -0
- package/ts/live/index.ts +11 -0
- package/ts/logger/Logger.ts +187 -0
- package/ts/logger/LoggerStyles.ts +28 -0
- package/ts/logger/index.ts +0 -0
- package/ts/types/ActionOptionsType.ts +10 -0
- package/ts/types/index.ts +3 -0
- package/index.js +0 -3
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Action } from "../../core/pipeline/Action";
|
|
2
|
+
import { ActionOptionsType } from "../../types/ActionOptionsType";
|
|
3
|
+
/**
|
|
4
|
+
* SvgPackagerAction is responsible for optimizing and packaging SVG files.
|
|
5
|
+
* It reads SVG files from a specified directory, optimizes them using SVGO,
|
|
6
|
+
* and then outputs them as TypeScript files and JSON indexes.
|
|
7
|
+
*/
|
|
8
|
+
export declare class SvgPackagerAction extends Action {
|
|
9
|
+
/**
|
|
10
|
+
* Executes the SVG processing action.
|
|
11
|
+
* @param options - The options specifying input and output directories.
|
|
12
|
+
* @returns A Promise that resolves when the action completes successfully.
|
|
13
|
+
*/
|
|
14
|
+
execute(options: ActionOptionsType): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Reads the content of an SVG file.
|
|
17
|
+
* @param filePath The path to the SVG file.
|
|
18
|
+
* @returns The content of the SVG file.
|
|
19
|
+
*/
|
|
20
|
+
private readSvgFile;
|
|
21
|
+
/**
|
|
22
|
+
* Sanitizes a file name to be a valid TypeScript identifier.
|
|
23
|
+
* @param fileName The original file name.
|
|
24
|
+
* @returns A sanitized version of the file name.
|
|
25
|
+
*/
|
|
26
|
+
private sanitizeFileName;
|
|
27
|
+
/**
|
|
28
|
+
* Optimizes SVG content using SVGO.
|
|
29
|
+
* @param svgoConfigPath Path to the SVGO configuration file.
|
|
30
|
+
* @param svgContent The raw SVG content.
|
|
31
|
+
* @returns The optimized SVG content.
|
|
32
|
+
*/
|
|
33
|
+
private optimizeSvg;
|
|
34
|
+
/**
|
|
35
|
+
* Writes optimized SVG content to files (SVG & TypeScript).
|
|
36
|
+
* @param iconName The name of the icon.
|
|
37
|
+
* @param svgContent The optimized SVG content.
|
|
38
|
+
* @param outputDirectory The directory for SVG output.
|
|
39
|
+
* @param tsOutputDirectory The directory for TypeScript output.
|
|
40
|
+
*/
|
|
41
|
+
private writeFiles;
|
|
42
|
+
/**
|
|
43
|
+
* Writes the optimized SVG content to an output file.
|
|
44
|
+
* @param iconName The name of the icon.
|
|
45
|
+
* @param svgContent The SVG content to be written.
|
|
46
|
+
* @param outputDirectory The directory to output the SVG file.
|
|
47
|
+
*/
|
|
48
|
+
private writeSvgFile;
|
|
49
|
+
/**
|
|
50
|
+
* Creates a TypeScript file from the optimized SVG content.
|
|
51
|
+
* @param iconName The name of the icon.
|
|
52
|
+
* @param svgContent The optimized SVG content.
|
|
53
|
+
* @param tsOutputDirectory The directory for TypeScript output.
|
|
54
|
+
*/
|
|
55
|
+
private writeTypeScriptFile;
|
|
56
|
+
/**
|
|
57
|
+
* Writes a JSON file containing the names of processed icons.
|
|
58
|
+
* @param iconNames An array of processed icon names.
|
|
59
|
+
* @param jsonOutputDirectory The directory to output the JSON file.
|
|
60
|
+
*/
|
|
61
|
+
private writeIconsJson;
|
|
62
|
+
/**
|
|
63
|
+
* Provides a description of the action.
|
|
64
|
+
* @returns A string description of the action.
|
|
65
|
+
*/
|
|
66
|
+
describe(): string;
|
|
67
|
+
}
|
|
68
|
+
export default SvgPackagerAction;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================================
|
|
3
|
+
// Imports
|
|
4
|
+
// ============================================================================
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
17
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
18
|
+
}) : function(o, v) {
|
|
19
|
+
o["default"] = v;
|
|
20
|
+
});
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
39
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
40
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
41
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
42
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
43
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
44
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.SvgPackagerAction = void 0;
|
|
49
|
+
const fs = __importStar(require("fs/promises"));
|
|
50
|
+
const glob = __importStar(require("glob"));
|
|
51
|
+
const path = __importStar(require("path"));
|
|
52
|
+
const svgo_1 = __importStar(require("svgo"));
|
|
53
|
+
const Action_1 = require("../../core/pipeline/Action");
|
|
54
|
+
// ============================================================================
|
|
55
|
+
// Classes
|
|
56
|
+
// ============================================================================
|
|
57
|
+
/**
|
|
58
|
+
* SvgPackagerAction is responsible for optimizing and packaging SVG files.
|
|
59
|
+
* It reads SVG files from a specified directory, optimizes them using SVGO,
|
|
60
|
+
* and then outputs them as TypeScript files and JSON indexes.
|
|
61
|
+
*/
|
|
62
|
+
class SvgPackagerAction extends Action_1.Action {
|
|
63
|
+
// Methods
|
|
64
|
+
// ========================================================================
|
|
65
|
+
/**
|
|
66
|
+
* Executes the SVG processing action.
|
|
67
|
+
* @param options - The options specifying input and output directories.
|
|
68
|
+
* @returns A Promise that resolves when the action completes successfully.
|
|
69
|
+
*/
|
|
70
|
+
execute(options) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
const { svgoConfigPath = "./config/svgo.config.js", inputDirectory = "src/icons", outputDirectory = "dist/icons", tsOutputDirectory = "dist/ts", jsonOutputDirectory = "dist", } = options;
|
|
73
|
+
this.logInfo(`Processing SVG files from ${inputDirectory}...`);
|
|
74
|
+
const iconNames = [];
|
|
75
|
+
try {
|
|
76
|
+
const svgFiles = glob.sync(`${inputDirectory}/**/*.svg`);
|
|
77
|
+
for (const file of svgFiles) {
|
|
78
|
+
const iconName = this.sanitizeFileName(path.basename(file, ".svg"));
|
|
79
|
+
iconNames.push(iconName);
|
|
80
|
+
const svgContent = yield this.readSvgFile(file);
|
|
81
|
+
const optimizedSvg = yield this.optimizeSvg(svgoConfigPath, svgContent);
|
|
82
|
+
yield this.writeFiles(iconName, optimizedSvg, outputDirectory, tsOutputDirectory);
|
|
83
|
+
}
|
|
84
|
+
yield this.writeIconsJson(iconNames, jsonOutputDirectory);
|
|
85
|
+
this.logInfo(`Successfully processed ${svgFiles.length} SVG files.`);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
this.logError("Error processing SVG files.", error);
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Reads the content of an SVG file.
|
|
95
|
+
* @param filePath The path to the SVG file.
|
|
96
|
+
* @returns The content of the SVG file.
|
|
97
|
+
*/
|
|
98
|
+
readSvgFile(filePath) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
return fs.readFile(filePath, "utf8");
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Sanitizes a file name to be a valid TypeScript identifier.
|
|
105
|
+
* @param fileName The original file name.
|
|
106
|
+
* @returns A sanitized version of the file name.
|
|
107
|
+
*/
|
|
108
|
+
sanitizeFileName(fileName) {
|
|
109
|
+
return fileName.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Optimizes SVG content using SVGO.
|
|
113
|
+
* @param svgoConfigPath Path to the SVGO configuration file.
|
|
114
|
+
* @param svgContent The raw SVG content.
|
|
115
|
+
* @returns The optimized SVG content.
|
|
116
|
+
*/
|
|
117
|
+
optimizeSvg(svgoConfigPath, svgContent) {
|
|
118
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
119
|
+
const config = yield (0, svgo_1.loadConfig)(svgoConfigPath);
|
|
120
|
+
const result = yield svgo_1.default.optimize(svgContent, Object.assign({}, config));
|
|
121
|
+
return result.data.trim();
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Writes optimized SVG content to files (SVG & TypeScript).
|
|
126
|
+
* @param iconName The name of the icon.
|
|
127
|
+
* @param svgContent The optimized SVG content.
|
|
128
|
+
* @param outputDirectory The directory for SVG output.
|
|
129
|
+
* @param tsOutputDirectory The directory for TypeScript output.
|
|
130
|
+
*/
|
|
131
|
+
writeFiles(iconName, svgContent, outputDirectory, tsOutputDirectory) {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
yield this.writeSvgFile(iconName, svgContent, outputDirectory);
|
|
134
|
+
yield this.writeTypeScriptFile(iconName, svgContent, tsOutputDirectory);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Writes the optimized SVG content to an output file.
|
|
139
|
+
* @param iconName The name of the icon.
|
|
140
|
+
* @param svgContent The SVG content to be written.
|
|
141
|
+
* @param outputDirectory The directory to output the SVG file.
|
|
142
|
+
*/
|
|
143
|
+
writeSvgFile(iconName, svgContent, outputDirectory) {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
+
const outputPath = path.join(outputDirectory, `${iconName}.svg`);
|
|
146
|
+
yield fs.writeFile(outputPath, svgContent);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Creates a TypeScript file from the optimized SVG content.
|
|
151
|
+
* @param iconName The name of the icon.
|
|
152
|
+
* @param svgContent The optimized SVG content.
|
|
153
|
+
* @param tsOutputDirectory The directory for TypeScript output.
|
|
154
|
+
*/
|
|
155
|
+
writeTypeScriptFile(iconName, svgContent, tsOutputDirectory) {
|
|
156
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
157
|
+
const tsContent = `export const icon_${iconName} = \`${svgContent}\`;\n`;
|
|
158
|
+
const outputPath = path.join(tsOutputDirectory, `${iconName}.ts`);
|
|
159
|
+
yield fs.writeFile(outputPath, tsContent);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Writes a JSON file containing the names of processed icons.
|
|
164
|
+
* @param iconNames An array of processed icon names.
|
|
165
|
+
* @param jsonOutputDirectory The directory to output the JSON file.
|
|
166
|
+
*/
|
|
167
|
+
writeIconsJson(iconNames, jsonOutputDirectory) {
|
|
168
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
169
|
+
const jsonContent = JSON.stringify(iconNames, null, 2);
|
|
170
|
+
const outputPath = path.join(jsonOutputDirectory, "icons.json");
|
|
171
|
+
yield fs.writeFile(outputPath, jsonContent);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Provides a description of the action.
|
|
176
|
+
* @returns A string description of the action.
|
|
177
|
+
*/
|
|
178
|
+
describe() {
|
|
179
|
+
return "Optimizes and packages SVG files into multiple formats (SVG, TypeScript, JSON).";
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
exports.SvgPackagerAction = SvgPackagerAction;
|
|
183
|
+
// ============================================================================
|
|
184
|
+
// Export
|
|
185
|
+
// ============================================================================
|
|
186
|
+
exports.default = SvgPackagerAction;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================================
|
|
3
|
+
// Import
|
|
4
|
+
// ============================================================================
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SvgPackagerAction = void 0;
|
|
7
|
+
const SvgPackagerAction_1 = require("./SvgPackagerAction");
|
|
8
|
+
Object.defineProperty(exports, "SvgPackagerAction", { enumerable: true, get: function () { return SvgPackagerAction_1.SvgPackagerAction; } });
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Action } from "../../core/pipeline/Action";
|
|
2
|
+
import { ActionOptionsType } from "../../types/ActionOptionsType";
|
|
3
|
+
/**
|
|
4
|
+
* SvgReaderAction is responsible for reading SVG file contents and
|
|
5
|
+
* making them available for further processing in the pipeline.
|
|
6
|
+
*/
|
|
7
|
+
export declare class SvgReaderAction extends Action {
|
|
8
|
+
private svgContent;
|
|
9
|
+
/**
|
|
10
|
+
* Executes the SVG reading action.
|
|
11
|
+
* @param options - The options specifying the SVG file path.
|
|
12
|
+
* @returns A Promise that resolves when the SVG file is successfully read.
|
|
13
|
+
*/
|
|
14
|
+
execute(options: ActionOptionsType): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Reads the content of an SVG file asynchronously.
|
|
17
|
+
* @param filePath The path to the SVG file.
|
|
18
|
+
* @returns A promise that resolves to the SVG file content.
|
|
19
|
+
*/
|
|
20
|
+
private readSvg;
|
|
21
|
+
/**
|
|
22
|
+
* Retrieves the last read SVG content.
|
|
23
|
+
* @returns The last read SVG content.
|
|
24
|
+
*/
|
|
25
|
+
getSvgContent(): string;
|
|
26
|
+
/**
|
|
27
|
+
* Provides a description of the action.
|
|
28
|
+
* @returns A string description of the action.
|
|
29
|
+
*/
|
|
30
|
+
describe(): string;
|
|
31
|
+
}
|
|
32
|
+
export default SvgReaderAction;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================================
|
|
3
|
+
// Imports
|
|
4
|
+
// ============================================================================
|
|
5
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.SvgReaderAction = void 0;
|
|
19
|
+
const fs_1 = require("fs");
|
|
20
|
+
const path_1 = __importDefault(require("path"));
|
|
21
|
+
const Action_1 = require("../../core/pipeline/Action");
|
|
22
|
+
// ============================================================================
|
|
23
|
+
// Classes
|
|
24
|
+
// ============================================================================
|
|
25
|
+
/**
|
|
26
|
+
* SvgReaderAction is responsible for reading SVG file contents and
|
|
27
|
+
* making them available for further processing in the pipeline.
|
|
28
|
+
*/
|
|
29
|
+
class SvgReaderAction extends Action_1.Action {
|
|
30
|
+
constructor() {
|
|
31
|
+
super(...arguments);
|
|
32
|
+
this.svgContent = "";
|
|
33
|
+
}
|
|
34
|
+
// Methods
|
|
35
|
+
// ========================================================================
|
|
36
|
+
/**
|
|
37
|
+
* Executes the SVG reading action.
|
|
38
|
+
* @param options - The options specifying the SVG file path.
|
|
39
|
+
* @returns A Promise that resolves when the SVG file is successfully read.
|
|
40
|
+
*/
|
|
41
|
+
execute(options) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const { filePath } = options;
|
|
44
|
+
if (!filePath) {
|
|
45
|
+
throw new Error("Missing required option: 'filePath'.");
|
|
46
|
+
}
|
|
47
|
+
this.logInfo(`Reading SVG file: ${filePath}`);
|
|
48
|
+
try {
|
|
49
|
+
this.svgContent = yield this.readSvg(filePath);
|
|
50
|
+
this.logInfo(`Successfully read SVG file: ${filePath}`);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
this.logError(`Error reading SVG file: ${filePath}`, error);
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Reads the content of an SVG file asynchronously.
|
|
60
|
+
* @param filePath The path to the SVG file.
|
|
61
|
+
* @returns A promise that resolves to the SVG file content.
|
|
62
|
+
*/
|
|
63
|
+
readSvg(filePath) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
return fs_1.promises.readFile(path_1.default.resolve(filePath), "utf-8");
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Retrieves the last read SVG content.
|
|
70
|
+
* @returns The last read SVG content.
|
|
71
|
+
*/
|
|
72
|
+
getSvgContent() {
|
|
73
|
+
return this.svgContent;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Provides a description of the action.
|
|
77
|
+
* @returns A string description of the action.
|
|
78
|
+
*/
|
|
79
|
+
describe() {
|
|
80
|
+
return "Reads an SVG file and stores its content for further processing.";
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.SvgReaderAction = SvgReaderAction;
|
|
84
|
+
// ============================================================================
|
|
85
|
+
// Export
|
|
86
|
+
// ============================================================================
|
|
87
|
+
exports.default = SvgReaderAction;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================================
|
|
3
|
+
// Import
|
|
4
|
+
// ============================================================================
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SvgReaderAction = void 0;
|
|
7
|
+
const SvgReaderAction_1 = require("./SvgReaderAction");
|
|
8
|
+
Object.defineProperty(exports, "SvgReaderAction", { enumerable: true, get: function () { return SvgReaderAction_1.SvgReaderAction; } });
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import svgSprite from "svg-sprite";
|
|
2
|
+
import { Action } from "../../core/pipeline/Action";
|
|
3
|
+
import { ActionOptionsType } from "../../types/ActionOptionsType";
|
|
4
|
+
/**
|
|
5
|
+
* SvgSpriteAction compiles multiple SVG files into a single sprite sheet,
|
|
6
|
+
* making it more efficient to manage and use SVG assets in web applications.
|
|
7
|
+
*/
|
|
8
|
+
export declare class SvgSpriteAction extends Action {
|
|
9
|
+
private config;
|
|
10
|
+
/**
|
|
11
|
+
* Default configuration for SVG sprite generation.
|
|
12
|
+
*/
|
|
13
|
+
private static defaultConfig;
|
|
14
|
+
/**
|
|
15
|
+
* Constructs an instance with merged default and custom configurations.
|
|
16
|
+
* @param {svgSprite.Config} customConfig - Optional custom configuration
|
|
17
|
+
* for svg-sprite.
|
|
18
|
+
*/
|
|
19
|
+
constructor(customConfig?: svgSprite.Config);
|
|
20
|
+
/**
|
|
21
|
+
* Executes the SVG sprite generation process.
|
|
22
|
+
* @param options - Options including source directory and output directory.
|
|
23
|
+
*/
|
|
24
|
+
execute(options: ActionOptionsType): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Generates an SVG sprite from all SVG files in the specified directory.
|
|
27
|
+
* @param sourceDir - Directory containing source SVG files.
|
|
28
|
+
* @param outputDir - Directory where the generated sprite will be saved.
|
|
29
|
+
*/
|
|
30
|
+
private generateSprite;
|
|
31
|
+
/**
|
|
32
|
+
* Provides a description of the action.
|
|
33
|
+
* @returns A string description of the action.
|
|
34
|
+
*/
|
|
35
|
+
describe(): string;
|
|
36
|
+
}
|
|
37
|
+
export default SvgSpriteAction;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================================
|
|
3
|
+
// Imports
|
|
4
|
+
// ============================================================================
|
|
5
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.SvgSpriteAction = void 0;
|
|
19
|
+
const fs_1 = __importDefault(require("fs"));
|
|
20
|
+
const path_1 = __importDefault(require("path"));
|
|
21
|
+
const svg_sprite_1 = __importDefault(require("svg-sprite"));
|
|
22
|
+
const Action_1 = require("../../core/pipeline/Action");
|
|
23
|
+
const svgsprite_config_js_1 = __importDefault(require("./svgsprite.config.js"));
|
|
24
|
+
// ============================================================================
|
|
25
|
+
// Classes
|
|
26
|
+
// ============================================================================
|
|
27
|
+
/**
|
|
28
|
+
* SvgSpriteAction compiles multiple SVG files into a single sprite sheet,
|
|
29
|
+
* making it more efficient to manage and use SVG assets in web applications.
|
|
30
|
+
*/
|
|
31
|
+
class SvgSpriteAction extends Action_1.Action {
|
|
32
|
+
// Constructor
|
|
33
|
+
// ========================================================================
|
|
34
|
+
/**
|
|
35
|
+
* Constructs an instance with merged default and custom configurations.
|
|
36
|
+
* @param {svgSprite.Config} customConfig - Optional custom configuration
|
|
37
|
+
* for svg-sprite.
|
|
38
|
+
*/
|
|
39
|
+
constructor(customConfig = {}) {
|
|
40
|
+
super();
|
|
41
|
+
this.config = Object.assign(Object.assign({}, SvgSpriteAction.defaultConfig), customConfig);
|
|
42
|
+
}
|
|
43
|
+
// Methods
|
|
44
|
+
// ========================================================================
|
|
45
|
+
/**
|
|
46
|
+
* Executes the SVG sprite generation process.
|
|
47
|
+
* @param options - Options including source directory and output directory.
|
|
48
|
+
*/
|
|
49
|
+
execute(options) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
const { sourceDir, outputDir } = options;
|
|
52
|
+
if (!sourceDir || !outputDir) {
|
|
53
|
+
throw new Error("Both 'sourceDir' and 'outputDir' must be specified.");
|
|
54
|
+
}
|
|
55
|
+
this.logInfo(`Generating SVG sprite from: ${sourceDir}`);
|
|
56
|
+
try {
|
|
57
|
+
yield this.generateSprite(sourceDir, outputDir);
|
|
58
|
+
this.logInfo(`SVG sprite successfully generated in: ${outputDir}`);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
this.logError("Error generating SVG sprite:", error);
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Generates an SVG sprite from all SVG files in the specified directory.
|
|
68
|
+
* @param sourceDir - Directory containing source SVG files.
|
|
69
|
+
* @param outputDir - Directory where the generated sprite will be saved.
|
|
70
|
+
*/
|
|
71
|
+
generateSprite(sourceDir, outputDir) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
const files = fs_1.default.readdirSync(sourceDir);
|
|
74
|
+
const sprite = new svg_sprite_1.default(this.config);
|
|
75
|
+
for (const file of files) {
|
|
76
|
+
if (path_1.default.extname(file) === ".svg") {
|
|
77
|
+
const svgPath = path_1.default.resolve(sourceDir, file);
|
|
78
|
+
const content = fs_1.default.readFileSync(svgPath, "utf8");
|
|
79
|
+
sprite.add(svgPath, null, content);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
sprite.compile((error, result) => {
|
|
83
|
+
if (error) {
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
for (const mode in result) {
|
|
87
|
+
for (const resource in result[mode]) {
|
|
88
|
+
const outputPath = path_1.default.resolve(outputDir, result[mode][resource].path);
|
|
89
|
+
fs_1.default.mkdirSync(path_1.default.dirname(outputPath), {
|
|
90
|
+
recursive: true,
|
|
91
|
+
});
|
|
92
|
+
fs_1.default.writeFileSync(outputPath, result[mode][resource].contents);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Provides a description of the action.
|
|
100
|
+
* @returns A string description of the action.
|
|
101
|
+
*/
|
|
102
|
+
describe() {
|
|
103
|
+
return "Generates an SVG sprite from a directory of SVG files.";
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.SvgSpriteAction = SvgSpriteAction;
|
|
107
|
+
/**
|
|
108
|
+
* Default configuration for SVG sprite generation.
|
|
109
|
+
*/
|
|
110
|
+
SvgSpriteAction.defaultConfig = svgsprite_config_js_1.default;
|
|
111
|
+
// ============================================================================
|
|
112
|
+
// Export
|
|
113
|
+
// ============================================================================
|
|
114
|
+
exports.default = SvgSpriteAction;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================================
|
|
3
|
+
// Import
|
|
4
|
+
// ============================================================================
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SvgSpriteAction = void 0;
|
|
7
|
+
const SvgSpriteAction_1 = require("./SvgSpriteAction");
|
|
8
|
+
Object.defineProperty(exports, "SvgSpriteAction", { enumerable: true, get: function () { return SvgSpriteAction_1.SvgSpriteAction; } });
|