kist 0.0.0 → 0.1.31

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.
Files changed (237) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +298 -3
  3. package/js/actions/CoreActions.d.ts +6 -0
  4. package/js/actions/CoreActions.js +47 -0
  5. package/js/actions/DirectoryCleanAction/DirectoryCleanAction.d.ts +36 -0
  6. package/js/actions/DirectoryCleanAction/DirectoryCleanAction.js +123 -0
  7. package/js/actions/DirectoryCleanAction/index.d.ts +2 -0
  8. package/js/actions/DirectoryCleanAction/index.js +8 -0
  9. package/js/actions/DirectoryCopyAction/DirectoryCopyAction.d.ts +42 -0
  10. package/js/actions/DirectoryCopyAction/DirectoryCopyAction.js +118 -0
  11. package/js/actions/DirectoryCopyAction/index.d.ts +2 -0
  12. package/js/actions/DirectoryCopyAction/index.js +8 -0
  13. package/js/actions/DirectoryCreateAction/DirectoryCreateAction.d.ts +30 -0
  14. package/js/actions/DirectoryCreateAction/DirectoryCreateAction.js +85 -0
  15. package/js/actions/DirectoryCreateAction/index.d.ts +2 -0
  16. package/js/actions/DirectoryCreateAction/index.js +8 -0
  17. package/js/actions/DocumentationAction/DocumentationAction.d.ts +23 -0
  18. package/js/actions/DocumentationAction/DocumentationAction.js +88 -0
  19. package/js/actions/DocumentationAction/index.d.ts +2 -0
  20. package/js/actions/DocumentationAction/index.js +8 -0
  21. package/js/actions/FileCopyAction/FileCopyAction.d.ts +42 -0
  22. package/js/actions/FileCopyAction/FileCopyAction.js +127 -0
  23. package/js/actions/FileCopyAction/index.d.ts +2 -0
  24. package/js/actions/FileCopyAction/index.js +8 -0
  25. package/js/actions/FileRenameAction/FileRenameAction.d.ts +30 -0
  26. package/js/actions/FileRenameAction/FileRenameAction.js +84 -0
  27. package/js/actions/FileRenameAction/index.d.ts +2 -0
  28. package/js/actions/FileRenameAction/index.js +8 -0
  29. package/js/actions/JavaScriptMinifyAction/JavaScriptMinifyAction.d.ts +31 -0
  30. package/js/actions/JavaScriptMinifyAction/JavaScriptMinifyAction.js +98 -0
  31. package/js/actions/JavaScriptMinifyAction/index.d.ts +2 -0
  32. package/js/actions/JavaScriptMinifyAction/index.js +8 -0
  33. package/js/actions/JavaScriptMinifyAction/terser.config.d.ts +27 -0
  34. package/js/actions/JavaScriptMinifyAction/terser.config.js +119 -0
  35. package/js/actions/LintAction/LintAction.d.ts +17 -0
  36. package/js/actions/LintAction/LintAction.js +63 -0
  37. package/js/actions/LintAction/index.d.ts +2 -0
  38. package/js/actions/LintAction/index.js +8 -0
  39. package/js/actions/PackageManagerAction/PackageManagerAction.d.ts +57 -0
  40. package/js/actions/PackageManagerAction/PackageManagerAction.js +161 -0
  41. package/js/actions/PackageManagerAction/index.d.ts +2 -0
  42. package/js/actions/PackageManagerAction/index.js +8 -0
  43. package/js/actions/PackageManagerAction/package.config.d.ts +16 -0
  44. package/js/actions/PackageManagerAction/package.config.js +91 -0
  45. package/js/actions/StyleProcessingAction/StyleProcessingAction.d.ts +34 -0
  46. package/js/actions/StyleProcessingAction/StyleProcessingAction.js +164 -0
  47. package/js/actions/StyleProcessingAction/index.d.ts +2 -0
  48. package/js/actions/StyleProcessingAction/index.js +8 -0
  49. package/js/actions/StyleProcessingAction/postcss.config.compressed.d.ts +10 -0
  50. package/js/actions/StyleProcessingAction/postcss.config.compressed.js +31 -0
  51. package/js/actions/StyleProcessingAction/postcss.config.expanded.d.ts +16 -0
  52. package/js/actions/StyleProcessingAction/postcss.config.expanded.js +45 -0
  53. package/js/actions/SvgPackagerAction/SvgPackagerAction.d.ts +68 -0
  54. package/js/actions/SvgPackagerAction/SvgPackagerAction.js +186 -0
  55. package/js/actions/SvgPackagerAction/index.d.ts +2 -0
  56. package/js/actions/SvgPackagerAction/index.js +8 -0
  57. package/js/actions/SvgReaderAction/SvgReaderAction.d.ts +32 -0
  58. package/js/actions/SvgReaderAction/SvgReaderAction.js +87 -0
  59. package/js/actions/SvgReaderAction/index.d.ts +2 -0
  60. package/js/actions/SvgReaderAction/index.js +8 -0
  61. package/js/actions/SvgSpriteAction/SvgSpriteAction.d.ts +37 -0
  62. package/js/actions/SvgSpriteAction/SvgSpriteAction.js +114 -0
  63. package/js/actions/SvgSpriteAction/index.d.ts +2 -0
  64. package/js/actions/SvgSpriteAction/index.js +8 -0
  65. package/js/actions/SvgSpriteAction/svgsprite.config.d.ts +3 -0
  66. package/js/actions/SvgSpriteAction/svgsprite.config.js +117 -0
  67. package/js/actions/SvgToPngAction/SvgToPngAction.d.ts +28 -0
  68. package/js/actions/SvgToPngAction/SvgToPngAction.js +108 -0
  69. package/js/actions/SvgToPngAction/index.d.ts +2 -0
  70. package/js/actions/SvgToPngAction/index.js +8 -0
  71. package/js/actions/TypeScriptCompilerAction/TypeScriptCompilerAction.d.ts +28 -0
  72. package/js/actions/TypeScriptCompilerAction/TypeScriptCompilerAction.js +96 -0
  73. package/js/actions/TypeScriptCompilerAction/index.d.ts +2 -0
  74. package/js/actions/TypeScriptCompilerAction/index.js +8 -0
  75. package/js/actions/VersionWriteAction/VersionWriteAction.d.ts +45 -0
  76. package/js/actions/VersionWriteAction/VersionWriteAction.js +147 -0
  77. package/js/actions/VersionWriteAction/index.d.ts +2 -0
  78. package/js/actions/VersionWriteAction/index.js +8 -0
  79. package/js/cli/ArgumentParser.d.ts +62 -0
  80. package/js/cli/ArgumentParser.js +118 -0
  81. package/js/cli.d.ts +6 -0
  82. package/js/cli.js +58 -0
  83. package/js/core/abstract/AbstractProcess.d.ts +62 -0
  84. package/js/core/abstract/AbstractProcess.js +96 -0
  85. package/js/core/abstract/AbstractValidator.d.ts +72 -0
  86. package/js/core/abstract/AbstractValidator.js +128 -0
  87. package/js/core/config/ConfigLoader.d.ts +47 -0
  88. package/js/core/config/ConfigLoader.js +130 -0
  89. package/js/core/config/ConfigStore.d.ts +53 -0
  90. package/js/core/config/ConfigStore.js +136 -0
  91. package/js/core/config/defaultConfig.d.ts +5 -0
  92. package/js/core/config/defaultConfig.js +131 -0
  93. package/js/core/pipeline/Action.d.ts +60 -0
  94. package/js/core/pipeline/Action.js +77 -0
  95. package/js/core/pipeline/ActionRegistry.d.ts +80 -0
  96. package/js/core/pipeline/ActionRegistry.js +180 -0
  97. package/js/core/pipeline/Pipeline.d.ts +42 -0
  98. package/js/core/pipeline/Pipeline.js +107 -0
  99. package/js/core/pipeline/PipelineManager.d.ts +55 -0
  100. package/js/core/pipeline/PipelineManager.js +164 -0
  101. package/js/core/pipeline/Stage.d.ts +45 -0
  102. package/js/core/pipeline/Stage.js +110 -0
  103. package/js/core/pipeline/Step.d.ts +26 -0
  104. package/js/core/pipeline/Step.js +85 -0
  105. package/js/core/validation/OptionsValidator.d.ts +43 -0
  106. package/js/core/validation/OptionsValidator.js +123 -0
  107. package/js/index.d.ts +3 -0
  108. package/js/index.js +36 -0
  109. package/js/interface/ActionInterface.d.ts +57 -0
  110. package/js/interface/ActionInterface.js +5 -0
  111. package/js/interface/ActionPlugin.d.ts +4 -0
  112. package/js/interface/ActionPlugin.js +5 -0
  113. package/js/interface/ConfigInterface.d.ts +43 -0
  114. package/js/interface/ConfigInterface.js +5 -0
  115. package/js/interface/LiveOptionsInterface.d.ts +42 -0
  116. package/js/interface/LiveOptionsInterface.js +2 -0
  117. package/js/interface/MetadataInterface.d.ts +95 -0
  118. package/js/interface/MetadataInterface.js +2 -0
  119. package/js/interface/OptionsInterface.d.ts +45 -0
  120. package/js/interface/OptionsInterface.js +5 -0
  121. package/js/interface/PipelineOptionsInterface.d.ts +66 -0
  122. package/js/interface/PipelineOptionsInterface.js +5 -0
  123. package/js/interface/StageInterface.d.ts +79 -0
  124. package/js/interface/StageInterface.js +5 -0
  125. package/js/interface/StepInterface.d.ts +66 -0
  126. package/js/interface/StepInterface.js +5 -0
  127. package/js/interface/StepOptionsInterface.d.ts +38 -0
  128. package/js/interface/StepOptionsInterface.js +21 -0
  129. package/js/interface/index.d.ts +7 -0
  130. package/js/interface/index.js +3 -0
  131. package/js/kist.d.ts +58 -0
  132. package/js/kist.js +145 -0
  133. package/js/live/LiveServer.d.ts +95 -0
  134. package/js/live/LiveServer.js +233 -0
  135. package/js/live/LiveWatcher.d.ts +45 -0
  136. package/js/live/LiveWatcher.js +140 -0
  137. package/js/logger/Logger.d.ts +94 -0
  138. package/js/logger/Logger.js +151 -0
  139. package/js/logger/LoggerStyles.d.ts +23 -0
  140. package/js/logger/LoggerStyles.js +30 -0
  141. package/js/types/ActionOptionsType.d.ts +8 -0
  142. package/js/types/ActionOptionsType.js +2 -0
  143. package/js/types/index.d.ts +1 -0
  144. package/js/types/index.js +3 -0
  145. package/package.json +93 -7
  146. package/ts/actions/CoreActions.ts +64 -0
  147. package/ts/actions/DirectoryCleanAction/DirectoryCleanAction.ts +121 -0
  148. package/ts/actions/DirectoryCleanAction/index.ts +11 -0
  149. package/ts/actions/DirectoryCopyAction/DirectoryCopyAction.ts +118 -0
  150. package/ts/actions/DirectoryCopyAction/index.ts +11 -0
  151. package/ts/actions/DirectoryCreateAction/DirectoryCreateAction.ts +81 -0
  152. package/ts/actions/DirectoryCreateAction/index.ts +11 -0
  153. package/ts/actions/DocumentationAction/DocumentationAction.ts +100 -0
  154. package/ts/actions/DocumentationAction/index.ts +11 -0
  155. package/ts/actions/FileCopyAction/FileCopyAction.ts +125 -0
  156. package/ts/actions/FileCopyAction/index.ts +11 -0
  157. package/ts/actions/FileRenameAction/FileRenameAction.ts +82 -0
  158. package/ts/actions/FileRenameAction/index.ts +11 -0
  159. package/ts/actions/JavaScriptMinifyAction/JavaScriptMinifyAction.ts +109 -0
  160. package/ts/actions/JavaScriptMinifyAction/index.ts +11 -0
  161. package/ts/actions/JavaScriptMinifyAction/terser.config.ts +177 -0
  162. package/ts/actions/LintAction/LintAction.ts +67 -0
  163. package/ts/actions/LintAction/index.ts +11 -0
  164. package/ts/actions/PackageManagerAction/PackageManagerAction.ts +176 -0
  165. package/ts/actions/PackageManagerAction/index.ts +11 -0
  166. package/ts/actions/PackageManagerAction/package.config.ts +94 -0
  167. package/ts/actions/SassDocAction/SassDocAction.ts +66 -0
  168. package/ts/actions/SassDocAction/index.ts +11 -0
  169. package/ts/actions/StyleProcessingAction/StyleProcessingAction.ts +142 -0
  170. package/ts/actions/StyleProcessingAction/index.ts +11 -0
  171. package/ts/actions/StyleProcessingAction/postcss.config.compressed.ts +31 -0
  172. package/ts/actions/StyleProcessingAction/postcss.config.expanded.ts +47 -0
  173. package/ts/actions/SvgPackagerAction/SvgPackagerAction.ts +187 -0
  174. package/ts/actions/SvgPackagerAction/index.ts +11 -0
  175. package/ts/actions/SvgReaderAction/SvgReaderAction.ts +77 -0
  176. package/ts/actions/SvgReaderAction/index.ts +11 -0
  177. package/ts/actions/SvgSpriteAction/SvgSpriteAction.ts +127 -0
  178. package/ts/actions/SvgSpriteAction/index.ts +11 -0
  179. package/ts/actions/SvgSpriteAction/svgsprite.config.ts +123 -0
  180. package/ts/actions/SvgToPngAction/SvgToPngAction.ts +113 -0
  181. package/ts/actions/SvgToPngAction/index.ts +11 -0
  182. package/ts/actions/TypeScriptCompilerAction/TypeScriptCompilerAction.ts +117 -0
  183. package/ts/actions/TypeScriptCompilerAction/index.ts +11 -0
  184. package/ts/actions/VersionWriteAction/VersionWriteAction.ts +174 -0
  185. package/ts/actions/VersionWriteAction/index.ts +11 -0
  186. package/ts/actions/index.ts +0 -0
  187. package/ts/cli/ArgumentParser.ts +150 -0
  188. package/ts/cli/index.ts +1 -0
  189. package/ts/cli.ts +56 -0
  190. package/ts/core/abstract/AbstractProcess.ts +109 -0
  191. package/ts/core/abstract/AbstractSingleton.ts +46 -0
  192. package/ts/core/abstract/AbstractValidator.ts +167 -0
  193. package/ts/core/abstract/index.ts +0 -0
  194. package/ts/core/config/ConfigLoader.ts +141 -0
  195. package/ts/core/config/ConfigStore copy.ts +201 -0
  196. package/ts/core/config/ConfigStore.ts +157 -0
  197. package/ts/core/config/defaultConfig.ts +154 -0
  198. package/ts/core/config/index.ts +0 -0
  199. package/ts/core/index.ts +34 -0
  200. package/ts/core/pipeline/Action.ts +101 -0
  201. package/ts/core/pipeline/ActionRegistry.ts +216 -0
  202. package/ts/core/pipeline/Pipeline.ts +121 -0
  203. package/ts/core/pipeline/PipelineManager.ts +170 -0
  204. package/ts/core/pipeline/Stage.ts +131 -0
  205. package/ts/core/pipeline/Step.ts +96 -0
  206. package/ts/core/pipeline/index.ts +0 -0
  207. package/ts/core/validation/ActionValidator.ts +97 -0
  208. package/ts/core/validation/ConfigValidator.ts +103 -0
  209. package/ts/core/validation/OptionsValidator.ts +179 -0
  210. package/ts/core/validation/StageValidator.ts +175 -0
  211. package/ts/core/validation/StepValidator.ts +203 -0
  212. package/ts/core/validation/index.ts +0 -0
  213. package/ts/index.ts +26 -0
  214. package/ts/interface/ActionInterface.ts +70 -0
  215. package/ts/interface/ActionPlugin.ts +14 -0
  216. package/ts/interface/ConfigInterface.ts +55 -0
  217. package/ts/interface/File.ts +24 -0
  218. package/ts/interface/LiveOptionsInterface.ts +46 -0
  219. package/ts/interface/MetadataInterface.ts +105 -0
  220. package/ts/interface/OptionsInterface.ts +58 -0
  221. package/ts/interface/PackageJson.ts +171 -0
  222. package/ts/interface/PipelineOptionsInterface.ts +74 -0
  223. package/ts/interface/SVG.ts +84 -0
  224. package/ts/interface/StageInterface.ts +96 -0
  225. package/ts/interface/StepInterface.ts +83 -0
  226. package/ts/interface/StepOptionsInterface.ts +57 -0
  227. package/ts/interface/index.ts +9 -0
  228. package/ts/kist.ts +161 -0
  229. package/ts/live/LiveServer.ts +311 -0
  230. package/ts/live/LiveWatcher.ts +150 -0
  231. package/ts/live/index.ts +11 -0
  232. package/ts/logger/Logger.ts +187 -0
  233. package/ts/logger/LoggerStyles.ts +28 -0
  234. package/ts/logger/index.ts +0 -0
  235. package/ts/types/ActionOptionsType.ts +10 -0
  236. package/ts/types/index.ts +3 -0
  237. package/index.js +0 -3
@@ -0,0 +1,123 @@
1
+ // ============================================================================
2
+ // Import
3
+ // ============================================================================
4
+
5
+ import svgSprite from "svg-sprite";
6
+
7
+ // ============================================================================
8
+ // Constants
9
+ // ============================================================================
10
+
11
+ const svgspriteConfig: svgSprite.Config = {
12
+ dest: "./dist/sprite", // Main output directory
13
+ // log: null, // Logging verbosity (default: no logging)
14
+ shape: {
15
+ // SVG shape related options
16
+ id: {
17
+ separator: "--", // Separator for directory name traversal
18
+ generator: "icon-%s",
19
+ // generator: function () { /*...*/ }, // SVG shape ID generator callback
20
+ pseudo: "~", // File name separator for shape states (e.g. ':hover')
21
+ },
22
+ dimension: {
23
+ // Dimension related options
24
+ maxWidth: 2000, // Max. shape width
25
+ maxHeight: 2000, // Max. shape height
26
+ precision: 2, // Floating point precision
27
+ attributes: false, // Width and height attributes on embedded shapes
28
+ },
29
+ spacing: {
30
+ // Spacing related options
31
+ padding: 0, // Padding around all shapes
32
+ box: "content", // Padding strategy (similar to CSS `box-sizing`)
33
+ },
34
+ transform: ["svgo"], // List of transformations / optimizations
35
+ // meta: null, // Path to YAML file with meta / accessibility data
36
+ // align: null, // Path to YAML file with extended alignment data
37
+ // dest: null // Output directory for optimized intermediate SVG shapes
38
+ },
39
+ svg: {
40
+ // General options for created SVG files
41
+ xmlDeclaration: false, // Add XML declaration to SVG sprite
42
+ // xmlDeclaration: true, // Add XML declaration to SVG sprite
43
+ doctypeDeclaration: true, // Add DOCTYPE declaration to SVG sprite
44
+ namespaceIDs: true, // Add namespace token to all IDs in SVG shapes
45
+ // namespaceIDPrefix: '', // Add a prefix to the automatically generated namespaceIDs
46
+ // namespaceClassnames: true, // Add namespace token to all CSS class names in SVG shapes
47
+ namespaceClassnames: false, // Add namespace token to all CSS class names in SVG shapes
48
+ dimensionAttributes: true, // Width and height attributes on the sprite
49
+ },
50
+ variables: {}, // Custom Mustache templating variables and functions
51
+ mode: {
52
+ css: {
53
+ // CSS sprite mode
54
+ render: {
55
+ css: true, // Render CSS stylesheet
56
+ },
57
+ },
58
+ view: true, // Create a «view» sprite
59
+ defs: true, // Create a «defs» sprite
60
+ // symbol: true, // Create a «symbol» sprite
61
+ symbol: {
62
+ // Create a «symbol» sprite
63
+ // dest: ".",
64
+ // inline: true, // Prepare for inline embedding
65
+ sprite: "icon.gl.svg",
66
+ },
67
+ stack: true, // Create a «stack» sprite
68
+ // symbol: true // Symbol sprite mode
69
+ },
70
+ };
71
+
72
+ // ============================================================================
73
+ // Export
74
+ // ============================================================================
75
+
76
+ export default svgspriteConfig;
77
+
78
+ // "svgo": {
79
+ // "multipass": true,
80
+ // "plugins": [
81
+ // {
82
+ // "name": "preset-default",
83
+ // "params": {
84
+ // "overrides": {
85
+ // "removeUnknownsAndDefaults": {
86
+ // "keepDataAttrs": false,
87
+ // "keepRoleAttr": true
88
+ // },
89
+ // "removeViewBox": false
90
+ // }
91
+ // }
92
+ // },
93
+ // "cleanupListOfValues",
94
+ // "removeXMLNS",
95
+ // {
96
+ // "name": "removeAttrs",
97
+ // "params": {
98
+ // "attrs": [
99
+ // "clip-rule",
100
+ // "fill"
101
+ // ]
102
+ // }
103
+ // }
104
+ // ]
105
+ // }
106
+
107
+ // <mode>: {
108
+ // dest: "<mode>", // Mode specific output directory
109
+ // prefix: "svg-%s", // Prefix for CSS selectors
110
+ // dimensions: "-dims", // Suffix for dimension CSS selectors
111
+ // sprite: "svg/sprite.<mode>.svg", // Sprite path and name
112
+ // bust: true || false, // Cache busting (mode dependent default value)
113
+ // render: { // Stylesheet rendering definitions
114
+ // /* -------------------------------------------
115
+ // css: false, // CSS stylesheet options
116
+ // scss: false, // Sass stylesheet options
117
+ // less: false, // LESS stylesheet options
118
+ // styl: false, // Stylus stylesheet options
119
+ // <custom>: ... // Custom stylesheet options
120
+ // ------------------------------------------- */
121
+ // },
122
+ // example: false // Create an HTML example document
123
+ // }
@@ -0,0 +1,113 @@
1
+ // ============================================================================
2
+ // Imports
3
+ // ============================================================================
4
+
5
+ import fs from "fs";
6
+ import { JSDOM } from "jsdom";
7
+ import path from "path";
8
+ import sharp from "sharp";
9
+ import { Action } from "../../core/pipeline/Action";
10
+ import { ActionOptionsType } from "../../types/ActionOptionsType";
11
+
12
+ // ============================================================================
13
+ // Classes
14
+ // ============================================================================
15
+
16
+ /**
17
+ * SvgToPngAction converts SVG content to PNG format.
18
+ * Uses `sharp` for conversion and `jsdom` for SVG element manipulation.
19
+ */
20
+ export class SvgToPngAction extends Action {
21
+ // Methods
22
+ // ========================================================================
23
+
24
+ /**
25
+ * Executes the SVG-to-PNG conversion process.
26
+ * @param options - Options including SVG content, output path, width,
27
+ * and height.
28
+ */
29
+ async execute(options: ActionOptionsType): Promise<void> {
30
+ const { svgContent, outputPath, width, height } = options;
31
+
32
+ if (!svgContent || !outputPath) {
33
+ throw new Error(
34
+ "Both 'svgContent' and 'outputPath' must be provided.",
35
+ );
36
+ }
37
+
38
+ this.logInfo(`Converting SVG to PNG: ${outputPath}`);
39
+
40
+ try {
41
+ await this.convert(svgContent, outputPath, width, height);
42
+ this.logInfo(`SVG successfully converted to PNG: ${outputPath}`);
43
+ } catch (error) {
44
+ this.logError("Error converting SVG to PNG:", error);
45
+ throw error;
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Converts SVG content to a PNG file, optionally resizing the output.
51
+ * @param svgContent - The SVG content to be converted.
52
+ * @param outputPath - The filesystem path where the PNG should be saved.
53
+ * @param width - Optional width for resizing.
54
+ * @param height - Optional height for resizing.
55
+ */
56
+ private async convert(
57
+ svgContent: string,
58
+ outputPath: string,
59
+ width?: number,
60
+ height?: number,
61
+ ): Promise<void> {
62
+ try {
63
+ // Ensure the output directory exists
64
+ const outputDir = path.dirname(outputPath);
65
+ if (!fs.existsSync(outputDir)) {
66
+ fs.mkdirSync(outputDir, { recursive: true });
67
+ }
68
+
69
+ // Create a JSDOM instance to parse the SVG
70
+ const dom = new JSDOM(svgContent);
71
+ const svgElement = dom.window.document.querySelector("svg");
72
+
73
+ if (!svgElement) {
74
+ throw new Error("Invalid SVG content");
75
+ }
76
+
77
+ if (width) {
78
+ svgElement.setAttribute("width", width.toString());
79
+ }
80
+
81
+ if (height) {
82
+ svgElement.setAttribute("height", height.toString());
83
+ }
84
+
85
+ // Serialize the updated SVG content
86
+ const updatedSvgContent = svgElement.outerHTML;
87
+
88
+ // Convert SVG to PNG using Sharp
89
+ const pngBuffer = await sharp(Buffer.from(updatedSvgContent))
90
+ .png()
91
+ .toBuffer();
92
+ await sharp(pngBuffer).toFile(outputPath);
93
+ } catch (error) {
94
+ throw new Error(
95
+ `Error converting SVG to PNG: ${(error as Error).message}`,
96
+ );
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Provides a description of the action.
102
+ * @returns A string description of the action.
103
+ */
104
+ describe(): string {
105
+ return "Converts SVG content to PNG format with optional resizing.";
106
+ }
107
+ }
108
+
109
+ // ============================================================================
110
+ // Export
111
+ // ============================================================================
112
+
113
+ export default SvgToPngAction;
@@ -0,0 +1,11 @@
1
+ // ============================================================================
2
+ // Import
3
+ // ============================================================================
4
+
5
+ import { SvgToPngAction } from "./SvgToPngAction";
6
+
7
+ // ============================================================================
8
+ // Export
9
+ // ============================================================================
10
+
11
+ export { SvgToPngAction };
@@ -0,0 +1,117 @@
1
+ // ============================================================================
2
+ // Imports
3
+ // ============================================================================
4
+
5
+ import path from "path";
6
+ import ts from "typescript";
7
+ import { Action } from "../../core/pipeline/Action";
8
+ import { ActionOptionsType } from "../../types/ActionOptionsType";
9
+
10
+ // ============================================================================
11
+ // Classes
12
+ // ============================================================================
13
+
14
+ /**
15
+ * TypeScriptCompilerAction compiles TypeScript files into JavaScript.
16
+ */
17
+ export class TypeScriptCompilerAction extends Action {
18
+ /**
19
+ * Executes the TypeScript compilation process.
20
+ *
21
+ * @param options - The options specifying the tsconfig path and additional compiler options.
22
+ * @returns A Promise that resolves when compilation is completed successfully.
23
+ * @throws {Error} Throws an error if compilation fails.
24
+ */
25
+ async execute(options: ActionOptionsType): Promise<void> {
26
+ const { tsconfigPath = "tsconfig.json" } = options;
27
+ const resolvedTsconfigPath = path.resolve(tsconfigPath);
28
+
29
+ this.logInfo(
30
+ `Compiling TypeScript using configuration: ${resolvedTsconfigPath}`,
31
+ );
32
+
33
+ try {
34
+ // **Properly Parse tsconfig.json**
35
+ const parsedConfig = this.loadAndParseTsConfig(
36
+ resolvedTsconfigPath,
37
+ );
38
+
39
+ // **Create a TypeScript Program**
40
+ const program = ts.createProgram(
41
+ parsedConfig.fileNames,
42
+ parsedConfig.options,
43
+ );
44
+ const emitResult = program.emit();
45
+
46
+ // **Collect Diagnostics**
47
+ const allDiagnostics = ts
48
+ .getPreEmitDiagnostics(program)
49
+ .concat(emitResult.diagnostics);
50
+ if (allDiagnostics.length > 0) {
51
+ allDiagnostics.forEach((diagnostic) => {
52
+ const message = ts.flattenDiagnosticMessageText(
53
+ diagnostic.messageText,
54
+ "\n",
55
+ );
56
+ this.logError(`TypeScript Error: ${message}`);
57
+ });
58
+ throw new Error(
59
+ "TypeScript compilation failed due to errors.",
60
+ );
61
+ }
62
+
63
+ this.logInfo("TypeScript compilation completed successfully.");
64
+ } catch (error: any) {
65
+ this.logError("Error during TypeScript compilation:", error);
66
+ throw new Error(`TypeScript compilation failed: ${error.message}`);
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Loads and parses `tsconfig.json` properly before passing it to the compiler.
72
+ *
73
+ * @param tsconfigPath - The path to the tsconfig.json file.
74
+ * @returns Parsed TypeScript compiler options and source files.
75
+ */
76
+ private loadAndParseTsConfig(tsconfigPath: string): ts.ParsedCommandLine {
77
+ // **Read and Parse tsconfig.json**
78
+ const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
79
+
80
+ if (configFile.error) {
81
+ throw new Error(
82
+ `Error reading tsconfig.json: ${ts.flattenDiagnosticMessageText(configFile.error.messageText, "\n")}`,
83
+ );
84
+ }
85
+
86
+ // **Parse the configuration content**
87
+ const parsedConfig = ts.parseJsonConfigFileContent(
88
+ configFile.config,
89
+ ts.sys,
90
+ path.dirname(tsconfigPath),
91
+ );
92
+
93
+ if (parsedConfig.errors.length > 0) {
94
+ throw new Error(
95
+ `Error parsing tsconfig.json: ${parsedConfig.errors
96
+ .map((diag) =>
97
+ ts.flattenDiagnosticMessageText(
98
+ diag.messageText,
99
+ "\n",
100
+ ),
101
+ )
102
+ .join("\n")}`,
103
+ );
104
+ }
105
+
106
+ return parsedConfig;
107
+ }
108
+
109
+ /**
110
+ * Provides a description of the action.
111
+ *
112
+ * @returns A string description of the action.
113
+ */
114
+ describe(): string {
115
+ return "Compiles TypeScript files using a given tsconfig.json configuration.";
116
+ }
117
+ }
@@ -0,0 +1,11 @@
1
+ // ============================================================================
2
+ // Import
3
+ // ============================================================================
4
+
5
+ import { TypeScriptCompilerAction } from "./TypeScriptCompilerAction";
6
+
7
+ // ============================================================================
8
+ // Export
9
+ // ============================================================================
10
+
11
+ export { TypeScriptCompilerAction };
@@ -0,0 +1,174 @@
1
+ // ============================================================================
2
+ // Import
3
+ // ============================================================================
4
+
5
+ import { promises as fs } from "fs";
6
+ import path from "path";
7
+ import { Action } from "../../core/pipeline/Action";
8
+ import { ActionOptionsType } from "../../types";
9
+
10
+ // ============================================================================
11
+ // Classes
12
+ // ============================================================================
13
+
14
+ /**
15
+ * VersionWriteAction is a step action responsible for replacing a version
16
+ * string in one or more specified files. The version is located and replaced
17
+ * based on a specified key and pattern.
18
+ */
19
+ export class VersionWriteAction extends Action {
20
+ // Methods
21
+ // ========================================================================
22
+
23
+ /**
24
+ * Executes the version writing action.
25
+ * @param options - The options specific to version writing, including the
26
+ * files, key, and version string or a flag to retrieve it from
27
+ * `package.json`.
28
+ * @returns A Promise that resolves when the version has been successfully
29
+ * replaced in all specified files, or rejects with an error if the
30
+ * action fails.
31
+ */
32
+ async execute(options: ActionOptionsType): Promise<void> {
33
+ const files = options.files as
34
+ | { path: string; key?: string }[]
35
+ | undefined;
36
+ let version = options.version as string | undefined;
37
+
38
+ if (!files) {
39
+ throw new Error(`Missing required option: files.`);
40
+ }
41
+
42
+ // Retrieve version from package.json if not explicitly provided
43
+ if (!version) {
44
+ version = await this.getVersionFromPackageJson();
45
+ if (!version) {
46
+ throw new Error(
47
+ `Version is not provided in options and could not be retrieved from package.json.`,
48
+ );
49
+ }
50
+ }
51
+
52
+ this.logInfo(`Replacing version "${version}" in specified files.`);
53
+
54
+ try {
55
+ // Replace the version in each file
56
+ await Promise.all(
57
+ files.map(({ path: filePath, key }) =>
58
+ this.replaceVersionInFile(
59
+ filePath,
60
+ version!,
61
+ key || "version:",
62
+ ),
63
+ ),
64
+ );
65
+ this.logInfo(
66
+ `Version "${version}" replaced successfully in all specified files.`,
67
+ );
68
+ } catch (error) {
69
+ this.logError(
70
+ `Failed to replace version in one or more files.`,
71
+ error,
72
+ );
73
+ throw error;
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Retrieves the version string from the `package.json` file.
79
+ * @returns A promise that resolves to the version string or `undefined`
80
+ * if not found.
81
+ * @throws {Error} Throws an error if `package.json` cannot be read.
82
+ */
83
+ private async getVersionFromPackageJson(): Promise<string | undefined> {
84
+ try {
85
+ const packageJsonPath = path.resolve(
86
+ process.cwd(),
87
+ "package.json",
88
+ );
89
+ const packageJsonContent = await fs.readFile(
90
+ packageJsonPath,
91
+ "utf8",
92
+ );
93
+ const packageJson = JSON.parse(packageJsonContent);
94
+ const version = packageJson.version;
95
+
96
+ if (version && /^\d+\.\d+\.\d+$/.test(version)) {
97
+ this.logInfo(
98
+ `Version "${version}" retrieved from package.json.`,
99
+ );
100
+ return version;
101
+ } else {
102
+ this.logWarn(`Invalid or missing version in package.json.`);
103
+ return undefined;
104
+ }
105
+ } catch (error) {
106
+ this.logError(
107
+ `Error reading package.json for version retrieval.`,
108
+ error,
109
+ );
110
+ return undefined;
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Replaces a version string in a file for a specific key.
116
+ * This method reads the file, replaces the version for the key, and
117
+ * writes the updated content back to the file.
118
+ *
119
+ * @param filePath - The file path where the version should be replaced.
120
+ * @param version - The new version string to replace in the file.
121
+ * @param key - The key prefix that identifies the version line (e.g.,
122
+ * `version:`).
123
+ * @returns A promise that resolves when the version has been successfully
124
+ * replaced.
125
+ * @throws {Error} Throws an error if reading or writing the file fails.
126
+ */
127
+ private async replaceVersionInFile(
128
+ filePath: string,
129
+ version: string,
130
+ key: string,
131
+ ): Promise<void> {
132
+ try {
133
+ const content = await fs.readFile(filePath, "utf8");
134
+ const lines = content.split("\n");
135
+
136
+ const updatedLines = lines.map((line) => {
137
+ const regex = new RegExp(`^\\s*${key}\\s*\\d+\\.\\d+\\.\\d+`);
138
+ if (regex.test(line)) {
139
+ return line.replace(/\d+\.\d+\.\d+$/, version);
140
+ }
141
+ return line;
142
+ });
143
+
144
+ await fs.writeFile(filePath, updatedLines.join("\n"), "utf8");
145
+ this.logInfo(
146
+ `Version replaced in file "${filePath}" for key "${key}".`,
147
+ );
148
+ } catch (error) {
149
+ throw new Error(
150
+ `Error replacing version in file "${filePath}":
151
+ ${(error as Error).message}`,
152
+ );
153
+ }
154
+ }
155
+
156
+ /**
157
+ * Provides a description of the action.
158
+ * @returns A string description of the action.
159
+ */
160
+ describe(): string {
161
+ let description = `
162
+ Replaces a version string in one or more specified files based on
163
+ a key and pattern. Can retrieve the version from package.json or
164
+ set it manually.
165
+ `;
166
+ return description;
167
+ }
168
+ }
169
+
170
+ // ============================================================================
171
+ // Export
172
+ // ============================================================================
173
+
174
+ // export default VersionWriteAction;
@@ -0,0 +1,11 @@
1
+ // ============================================================================
2
+ // Import
3
+ // ============================================================================
4
+
5
+ import { VersionWriteAction } from "./VersionWriteAction";
6
+
7
+ // ============================================================================
8
+ // Export
9
+ // ============================================================================
10
+
11
+ export { VersionWriteAction };
File without changes