diff --git a/VERSION b/VERSION index 2b80db2..e9d5322 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.33 \ No newline at end of file +0.0.35 \ No newline at end of file diff --git a/dist/js/class/DirectoryScanner.d.ts b/dist/js/class/DirectoryScanner.d.ts new file mode 100644 index 0000000..5b487d1 --- /dev/null +++ b/dist/js/class/DirectoryScanner.d.ts @@ -0,0 +1,11 @@ +declare class DirectoryScanner { + /** + * Scans a directory and returns a list of file paths. + * Can optionally scan directories recursively. + * @param dirPath The directory to scan. + * @param recursive Whether to scan directories recursively. + * @returns A promise that resolves to an array of file paths. + */ + scanDirectory(dirPath: string, recursive?: boolean): Promise; +} +export default DirectoryScanner; diff --git a/dist/js/class/DirectoryScanner.js b/dist/js/class/DirectoryScanner.js new file mode 100644 index 0000000..e7c4e04 --- /dev/null +++ b/dist/js/class/DirectoryScanner.js @@ -0,0 +1,53 @@ +"use strict"; +// class/DirectoryScanner.ts +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// Copyright 2023 Scape Agency BV +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ============================================================================ +// Import +// ============================================================================ +var promises_1 = __importDefault(require("fs/promises")); +var path_1 = __importDefault(require("path")); +// ============================================================================ +// Classes +// ============================================================================ +class DirectoryScanner { + /** + * Scans a directory and returns a list of file paths. + * Can optionally scan directories recursively. + * @param dirPath The directory to scan. + * @param recursive Whether to scan directories recursively. + * @returns A promise that resolves to an array of file paths. + */ + async scanDirectory(dirPath, recursive = false) { + try { + const entries = await promises_1.default.readdir(dirPath, { withFileTypes: true }); + const files = await Promise.all(entries.map(async (entry) => { + const resolvedPath = path_1.default.resolve(dirPath, entry.name); + return entry.isDirectory() && recursive + ? this.scanDirectory(resolvedPath, true) + : resolvedPath; + })); + return files.flat(); + } + catch (error) { + console.error(`Error scanning directory: ${dirPath}`, error); + throw error; + } + } +} +// ============================================================================ +// Export +// ============================================================================ +exports.default = DirectoryScanner; diff --git a/dist/js/class/FilenameExtractor.d.ts b/dist/js/class/FilenameExtractor.d.ts new file mode 100644 index 0000000..b17b860 --- /dev/null +++ b/dist/js/class/FilenameExtractor.d.ts @@ -0,0 +1,9 @@ +declare class FilenameExtractor { + /** + * Extracts the filename without its extension from a file path. + * @param filePath The full path of the file. + * @returns The filename without its extension. + */ + getFilenameWithoutExtension(filePath: string): string; +} +export default FilenameExtractor; diff --git a/dist/js/class/FilenameExtractor.js b/dist/js/class/FilenameExtractor.js new file mode 100644 index 0000000..321c92d --- /dev/null +++ b/dist/js/class/FilenameExtractor.js @@ -0,0 +1,37 @@ +"use strict"; +// class/FilenameExtractor.ts +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +// Copyright 2023 Scape Agency BV +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ============================================================================ +// Import +// ============================================================================ +var path_1 = __importDefault(require("path")); +// ============================================================================ +// Classes +// ============================================================================ +class FilenameExtractor { + /** + * Extracts the filename without its extension from a file path. + * @param filePath The full path of the file. + * @returns The filename without its extension. + */ + getFilenameWithoutExtension(filePath) { + return path_1.default.basename(filePath, path_1.default.extname(filePath)); + } +} +// ============================================================================ +// Export +// ============================================================================ +exports.default = FilenameExtractor; diff --git a/dist/js/class/FontGenerator.js b/dist/js/class/FontGenerator.js index 007146a..1657d39 100644 --- a/dist/js/class/FontGenerator.js +++ b/dist/js/class/FontGenerator.js @@ -48,7 +48,21 @@ class FontGenerator { // }, // ttf?: TtfOptions; // type TtfOptions = svg2ttf.FontOptions; // svg?: SvgOptions; // type SvgOptions = Omit; - json: { indent: 4 } + json: { + indent: 4 + }, + ts: { + // select what kind of types you want to generate + // (default `['enum', 'constant', 'literalId', 'literalKey']`) + types: ['enum', 'constant', 'literalId', 'literalKey'], + // render the types with `'` instead of `"` (default is `"`) + singleQuotes: false, + // customise names used for the generated types and constants + enumName: 'icon_gl', + constantName: 'MY_CODEPOINTS' + // literalIdName: 'IconId', + // literalKeyName: 'IconKey' + } }, pathOptions: { json: './dist/font/icon.gl.json', diff --git a/dist/js/class/SvgReader.d.ts b/dist/js/class/SvgReader.d.ts new file mode 100644 index 0000000..fcfd961 --- /dev/null +++ b/dist/js/class/SvgReader.d.ts @@ -0,0 +1,9 @@ +declare class SvgReader { + /** + * Reads the content of an SVG file asynchronously. + * @param filePath The path to the SVG file. + * @returns A promise that resolves to the content of the SVG file. + */ + readSVG(filePath: string): Promise; +} +export default SvgReader; diff --git a/dist/js/class/SvgReader.js b/dist/js/class/SvgReader.js new file mode 100644 index 0000000..0ed84d8 --- /dev/null +++ b/dist/js/class/SvgReader.js @@ -0,0 +1,41 @@ +"use strict"; +// class/SvgReader.ts +Object.defineProperty(exports, "__esModule", { value: true }); +// Copyright 2023 Scape Agency BV +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ============================================================================ +// Import +// ============================================================================ +var fs_1 = require("fs"); +// ============================================================================ +// Classes +// ============================================================================ +class SvgReader { + /** + * Reads the content of an SVG file asynchronously. + * @param filePath The path to the SVG file. + * @returns A promise that resolves to the content of the SVG file. + */ + async readSVG(filePath) { + try { + const data = await fs_1.promises.readFile(filePath, 'utf-8'); + return data; + } + catch (error) { + console.error(`Error reading SVG file: ${filePath}`, error); + throw error; // Rethrow the error for further handling if necessary + } + } +} +// ============================================================================ +// Export +// ============================================================================ +exports.default = SvgReader; diff --git a/dist/js/index.d.ts b/dist/js/index.d.ts index f39690a..62c1399 100644 --- a/dist/js/index.d.ts +++ b/dist/js/index.d.ts @@ -1,21 +1,24 @@ +import DirectoryScanner from './class/DirectoryScanner'; import DirectoryCleaner from './class/DirectoryCleaner'; import DirectoryCopier from './class/DirectoryCopier'; import DirectoryCreator from './class/DirectoryCreator'; import FileCopier from './class/FileCopier'; import FileRenamer from './class/FileRenamer'; +import FilenameExtractor from './class/FilenameExtractor'; import FontGenerator from './class/FontGenerator.js'; import PackageCreator from './class/PackageCreator.js'; -import SvgPackager from "./class/SvgPackager.js"; import StyleProcessor from "./class/StyleProcessor.js"; -import SvgSpriteGenerator from "./class/SvgSpriteGenerator.js"; import VersionWriter from './class/VersionWriter.js'; import TypeScriptCompiler from './class/TypeScriptCompiler.js'; import JavaScriptMinifier from './class/JavaScriptMinifier.js'; import NpmCommandRunner from './class/NpmCommandRunner.js'; import StylizedLogger from './class/StylizedLogger.js'; import TemplateWriter from './class/TemplateWriter.js'; +import SvgReader from './class/SvgReader.js'; import SvgToPngConverter from './class/SvgToPngConverter.js'; +import SvgSpriteGenerator from "./class/SvgSpriteGenerator.js"; +import SvgPackager from "./class/SvgPackager.js"; import gl_installer from './function/gl_installer'; import cleanDirectory from './function/clean_directory'; import readPackageJson from "./function/readPackageJson.js"; -export { DirectoryCleaner, DirectoryCopier, DirectoryCreator, FileCopier, FileRenamer, FontGenerator, PackageCreator, SvgPackager, StyleProcessor, SvgSpriteGenerator, VersionWriter, TypeScriptCompiler, JavaScriptMinifier, NpmCommandRunner, StylizedLogger, TemplateWriter, SvgToPngConverter, gl_installer, cleanDirectory, readPackageJson, }; +export { DirectoryScanner, DirectoryCleaner, DirectoryCopier, DirectoryCreator, FileCopier, FileRenamer, FilenameExtractor, FontGenerator, PackageCreator, StyleProcessor, VersionWriter, TypeScriptCompiler, JavaScriptMinifier, NpmCommandRunner, StylizedLogger, TemplateWriter, SvgReader, SvgToPngConverter, SvgSpriteGenerator, SvgPackager, gl_installer, cleanDirectory, readPackageJson, }; diff --git a/dist/js/index.js b/dist/js/index.js index de86d16..13a21b3 100644 --- a/dist/js/index.js +++ b/dist/js/index.js @@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.readPackageJson = exports.cleanDirectory = exports.gl_installer = exports.SvgToPngConverter = exports.TemplateWriter = exports.StylizedLogger = exports.NpmCommandRunner = exports.JavaScriptMinifier = exports.TypeScriptCompiler = exports.VersionWriter = exports.SvgSpriteGenerator = exports.StyleProcessor = exports.SvgPackager = exports.PackageCreator = exports.FontGenerator = exports.FileRenamer = exports.FileCopier = exports.DirectoryCreator = exports.DirectoryCopier = exports.DirectoryCleaner = void 0; +exports.readPackageJson = exports.cleanDirectory = exports.gl_installer = exports.SvgPackager = exports.SvgSpriteGenerator = exports.SvgToPngConverter = exports.SvgReader = exports.TemplateWriter = exports.StylizedLogger = exports.NpmCommandRunner = exports.JavaScriptMinifier = exports.TypeScriptCompiler = exports.VersionWriter = exports.StyleProcessor = exports.PackageCreator = exports.FontGenerator = exports.FilenameExtractor = exports.FileRenamer = exports.FileCopier = exports.DirectoryCreator = exports.DirectoryCopier = exports.DirectoryCleaner = exports.DirectoryScanner = void 0; // Copyright 2023 Scape Agency BV // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,6 +19,8 @@ exports.readPackageJson = exports.cleanDirectory = exports.gl_installer = export // Import // ============================================================================ // Import | Utility Classes +var DirectoryScanner_1 = __importDefault(require("./class/DirectoryScanner")); +exports.DirectoryScanner = DirectoryScanner_1.default; var DirectoryCleaner_1 = __importDefault(require("./class/DirectoryCleaner")); exports.DirectoryCleaner = DirectoryCleaner_1.default; var DirectoryCopier_1 = __importDefault(require("./class/DirectoryCopier")); @@ -29,17 +31,15 @@ var FileCopier_1 = __importDefault(require("./class/FileCopier")); exports.FileCopier = FileCopier_1.default; var FileRenamer_1 = __importDefault(require("./class/FileRenamer")); exports.FileRenamer = FileRenamer_1.default; +var FilenameExtractor_1 = __importDefault(require("./class/FilenameExtractor")); +exports.FilenameExtractor = FilenameExtractor_1.default; // Import | Internal Classes var FontGenerator_js_1 = __importDefault(require("./class/FontGenerator.js")); exports.FontGenerator = FontGenerator_js_1.default; var PackageCreator_js_1 = __importDefault(require("./class/PackageCreator.js")); exports.PackageCreator = PackageCreator_js_1.default; -var SvgPackager_js_1 = __importDefault(require("./class/SvgPackager.js")); -exports.SvgPackager = SvgPackager_js_1.default; var StyleProcessor_js_1 = __importDefault(require("./class/StyleProcessor.js")); exports.StyleProcessor = StyleProcessor_js_1.default; -var SvgSpriteGenerator_js_1 = __importDefault(require("./class/SvgSpriteGenerator.js")); -exports.SvgSpriteGenerator = SvgSpriteGenerator_js_1.default; var VersionWriter_js_1 = __importDefault(require("./class/VersionWriter.js")); exports.VersionWriter = VersionWriter_js_1.default; var TypeScriptCompiler_js_1 = __importDefault(require("./class/TypeScriptCompiler.js")); @@ -52,8 +52,14 @@ var StylizedLogger_js_1 = __importDefault(require("./class/StylizedLogger.js")); exports.StylizedLogger = StylizedLogger_js_1.default; var TemplateWriter_js_1 = __importDefault(require("./class/TemplateWriter.js")); exports.TemplateWriter = TemplateWriter_js_1.default; +var SvgReader_js_1 = __importDefault(require("./class/SvgReader.js")); +exports.SvgReader = SvgReader_js_1.default; var SvgToPngConverter_js_1 = __importDefault(require("./class/SvgToPngConverter.js")); exports.SvgToPngConverter = SvgToPngConverter_js_1.default; +var SvgSpriteGenerator_js_1 = __importDefault(require("./class/SvgSpriteGenerator.js")); +exports.SvgSpriteGenerator = SvgSpriteGenerator_js_1.default; +var SvgPackager_js_1 = __importDefault(require("./class/SvgPackager.js")); +exports.SvgPackager = SvgPackager_js_1.default; // Import | Internal Functions var gl_installer_1 = __importDefault(require("./function/gl_installer")); exports.gl_installer = gl_installer_1.default; diff --git a/dist/package.json b/dist/package.json index 21b4983..ba3f571 100644 --- a/dist/package.json +++ b/dist/package.json @@ -1,6 +1,6 @@ { "name": "pack.gl", - "version": "0.0.33", + "version": "0.0.35", "description": "Package Builder.", "keywords": [ "pack.gl", diff --git a/dist/ts/class/DirectoryCreator.ts b/dist/ts/class/DirectoryCreator.ts index 1d64503..e784c7a 100644 --- a/dist/ts/class/DirectoryCreator.ts +++ b/dist/ts/class/DirectoryCreator.ts @@ -23,7 +23,6 @@ import { promises as fsPromises } from 'fs'; import path from 'path'; - // ============================================================================ // Classes // ============================================================================ diff --git a/dist/ts/class/DirectoryScanner.ts b/dist/ts/class/DirectoryScanner.ts new file mode 100644 index 0000000..a998549 --- /dev/null +++ b/dist/ts/class/DirectoryScanner.ts @@ -0,0 +1,65 @@ +// class/DirectoryScanner.ts + +// Copyright 2023 Scape Agency BV + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +// ============================================================================ +// Import +// ============================================================================ + +import fs from 'fs/promises'; +import path from 'path'; + + +// ============================================================================ +// Classes +// ============================================================================ + +class DirectoryScanner { + + /** + * Scans a directory and returns a list of file paths. + * Can optionally scan directories recursively. + * @param dirPath The directory to scan. + * @param recursive Whether to scan directories recursively. + * @returns A promise that resolves to an array of file paths. + */ + async scanDirectory( + dirPath: string, + recursive: boolean = false + ): Promise { + try { + const entries = await fs.readdir(dirPath, { withFileTypes: true }); + const files = await Promise.all(entries.map(async (entry) => { + const resolvedPath = path.resolve(dirPath, entry.name); + return entry.isDirectory() && recursive + ? this.scanDirectory(resolvedPath, true) + : resolvedPath; + })); + + return files.flat(); + } catch (error) { + console.error(`Error scanning directory: ${dirPath}`, error); + throw error; + } + } + +} + +// ============================================================================ +// Export +// ============================================================================ + +export default DirectoryScanner; diff --git a/dist/ts/class/FilenameExtractor.ts b/dist/ts/class/FilenameExtractor.ts new file mode 100644 index 0000000..51c8100 --- /dev/null +++ b/dist/ts/class/FilenameExtractor.ts @@ -0,0 +1,47 @@ +// class/FilenameExtractor.ts + +// Copyright 2023 Scape Agency BV + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +// ============================================================================ +// Import +// ============================================================================ + +import path from 'path'; + + +// ============================================================================ +// Classes +// ============================================================================ + +class FilenameExtractor { + + /** + * Extracts the filename without its extension from a file path. + * @param filePath The full path of the file. + * @returns The filename without its extension. + */ + getFilenameWithoutExtension(filePath: string): string { + return path.basename(filePath, path.extname(filePath)); + } + +} + + +// ============================================================================ +// Export +// ============================================================================ + +export default FilenameExtractor; diff --git a/dist/ts/class/FontGenerator.ts b/dist/ts/class/FontGenerator.ts index d42b079..e840e0e 100644 --- a/dist/ts/class/FontGenerator.ts +++ b/dist/ts/class/FontGenerator.ts @@ -57,27 +57,28 @@ class FontGenerator { OtherAssetType.TS, // TS = "ts" ], - formatOptions: { - // woff: { - // // Woff Extended Metadata Block - see https://www.w3.org/TR/WOFF/#Metadata - // metadata: '...' - // }, - // ttf?: TtfOptions; // type TtfOptions = svg2ttf.FontOptions; - // svg?: SvgOptions; // type SvgOptions = Omit; - json: { indent: 4 } , - // ts: { - // // select what kind of types you want to generate - // // (default `['enum', 'constant', 'literalId', 'literalKey']`) - // types: ['enum', 'constant', 'literalId', 'literalKey'], - // // render the types with `'` instead of `"` (default is `"`) - // singleQuotes: false, - // // customise names used for the generated types and constants - // enumName: 'icon_gl', - // constantName: 'MY_CODEPOINTS' - // // literalIdName: 'IconId', - // // literalKeyName: 'IconKey' - // } + // woff: { + // // Woff Extended Metadata Block - see https://www.w3.org/TR/WOFF/#Metadata + // metadata: '...' + // }, + // ttf?: TtfOptions; // type TtfOptions = svg2ttf.FontOptions; + // svg?: SvgOptions; // type SvgOptions = Omit; + json: { + indent: 4 + }, + ts: { + // select what kind of types you want to generate + // (default `['enum', 'constant', 'literalId', 'literalKey']`) + types: ['enum', 'constant', 'literalId', 'literalKey'], + // render the types with `'` instead of `"` (default is `"`) + singleQuotes: false, + // customise names used for the generated types and constants + enumName: 'icon_gl', + constantName: 'MY_CODEPOINTS' + // literalIdName: 'IconId', + // literalKeyName: 'IconKey' + } }, pathOptions: { json: './dist/font/icon.gl.json', diff --git a/dist/ts/class/SVGReader.ts b/dist/ts/class/SVGReader.ts new file mode 100644 index 0000000..985fc20 --- /dev/null +++ b/dist/ts/class/SVGReader.ts @@ -0,0 +1,53 @@ +// class/SvgReader.ts + +// Copyright 2023 Scape Agency BV + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +// ============================================================================ +// Import +// ============================================================================ + +import { promises as fs } from 'fs'; + + +// ============================================================================ +// Classes +// ============================================================================ + +class SvgReader { + + /** + * Reads the content of an SVG file asynchronously. + * @param filePath The path to the SVG file. + * @returns A promise that resolves to the content of the SVG file. + */ + async readSVG(filePath: string): Promise { + try { + const data = await fs.readFile(filePath, 'utf-8'); + return data; + } catch (error) { + console.error(`Error reading SVG file: ${filePath}`, error); + throw error; // Rethrow the error for further handling if necessary + } + } + +} + + +// ============================================================================ +// Export +// ============================================================================ + +export default SvgReader; diff --git a/dist/ts/index.ts b/dist/ts/index.ts index 11f2926..03d1814 100644 --- a/dist/ts/index.ts +++ b/dist/ts/index.ts @@ -20,25 +20,31 @@ // ============================================================================ // Import | Utility Classes +import DirectoryScanner from './class/DirectoryScanner'; import DirectoryCleaner from './class/DirectoryCleaner'; import DirectoryCopier from './class/DirectoryCopier'; import DirectoryCreator from './class/DirectoryCreator'; import FileCopier from './class/FileCopier'; import FileRenamer from './class/FileRenamer'; +import FilenameExtractor from './class/FilenameExtractor'; // Import | Internal Classes import FontGenerator from './class/FontGenerator.js'; import PackageCreator from './class/PackageCreator.js'; -import SvgPackager from "./class/SvgPackager.js"; import StyleProcessor from "./class/StyleProcessor.js"; -import SvgSpriteGenerator from "./class/SvgSpriteGenerator.js"; import VersionWriter from './class/VersionWriter.js'; import TypeScriptCompiler from './class/TypeScriptCompiler.js'; import JavaScriptMinifier from './class/JavaScriptMinifier.js'; import NpmCommandRunner from './class/NpmCommandRunner.js'; import StylizedLogger from './class/StylizedLogger.js'; import TemplateWriter from './class/TemplateWriter.js'; + +import SvgReader from './class/SvgReader.js'; import SvgToPngConverter from './class/SvgToPngConverter.js'; +import SvgSpriteGenerator from "./class/SvgSpriteGenerator.js"; +import SvgPackager from "./class/SvgPackager.js"; + + // Import | Internal Functions import gl_installer from './function/gl_installer'; @@ -53,25 +59,29 @@ import readPackageJson from "./function/readPackageJson.js" export { // Export | Utility Classes + DirectoryScanner, DirectoryCleaner, DirectoryCopier, DirectoryCreator, FileCopier, FileRenamer, + FilenameExtractor, // // Export | Internal Classes FontGenerator, PackageCreator, - SvgPackager, StyleProcessor, - SvgSpriteGenerator, VersionWriter, TypeScriptCompiler, JavaScriptMinifier, NpmCommandRunner, StylizedLogger, TemplateWriter, + + SvgReader, SvgToPngConverter, + SvgSpriteGenerator, + SvgPackager, // Export | Internal Functions gl_installer, diff --git a/package.json b/package.json index 0bf682b..e534b08 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "pack.gl", "description": "Package Builder.", - "version": "0.0.34", + "version": "0.0.35", "config": { "version_short": "0.0" }, diff --git a/src/ts/class/DirectoryCreator.ts b/src/ts/class/DirectoryCreator.ts index 1d64503..e784c7a 100644 --- a/src/ts/class/DirectoryCreator.ts +++ b/src/ts/class/DirectoryCreator.ts @@ -23,7 +23,6 @@ import { promises as fsPromises } from 'fs'; import path from 'path'; - // ============================================================================ // Classes // ============================================================================ diff --git a/src/ts/class/DirectoryScanner.ts b/src/ts/class/DirectoryScanner.ts new file mode 100644 index 0000000..a998549 --- /dev/null +++ b/src/ts/class/DirectoryScanner.ts @@ -0,0 +1,65 @@ +// class/DirectoryScanner.ts + +// Copyright 2023 Scape Agency BV + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +// ============================================================================ +// Import +// ============================================================================ + +import fs from 'fs/promises'; +import path from 'path'; + + +// ============================================================================ +// Classes +// ============================================================================ + +class DirectoryScanner { + + /** + * Scans a directory and returns a list of file paths. + * Can optionally scan directories recursively. + * @param dirPath The directory to scan. + * @param recursive Whether to scan directories recursively. + * @returns A promise that resolves to an array of file paths. + */ + async scanDirectory( + dirPath: string, + recursive: boolean = false + ): Promise { + try { + const entries = await fs.readdir(dirPath, { withFileTypes: true }); + const files = await Promise.all(entries.map(async (entry) => { + const resolvedPath = path.resolve(dirPath, entry.name); + return entry.isDirectory() && recursive + ? this.scanDirectory(resolvedPath, true) + : resolvedPath; + })); + + return files.flat(); + } catch (error) { + console.error(`Error scanning directory: ${dirPath}`, error); + throw error; + } + } + +} + +// ============================================================================ +// Export +// ============================================================================ + +export default DirectoryScanner; diff --git a/src/ts/class/FilenameExtractor.ts b/src/ts/class/FilenameExtractor.ts new file mode 100644 index 0000000..51c8100 --- /dev/null +++ b/src/ts/class/FilenameExtractor.ts @@ -0,0 +1,47 @@ +// class/FilenameExtractor.ts + +// Copyright 2023 Scape Agency BV + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +// ============================================================================ +// Import +// ============================================================================ + +import path from 'path'; + + +// ============================================================================ +// Classes +// ============================================================================ + +class FilenameExtractor { + + /** + * Extracts the filename without its extension from a file path. + * @param filePath The full path of the file. + * @returns The filename without its extension. + */ + getFilenameWithoutExtension(filePath: string): string { + return path.basename(filePath, path.extname(filePath)); + } + +} + + +// ============================================================================ +// Export +// ============================================================================ + +export default FilenameExtractor; diff --git a/src/ts/class/FontGenerator.ts b/src/ts/class/FontGenerator.ts index d42b079..e840e0e 100644 --- a/src/ts/class/FontGenerator.ts +++ b/src/ts/class/FontGenerator.ts @@ -57,27 +57,28 @@ class FontGenerator { OtherAssetType.TS, // TS = "ts" ], - formatOptions: { - // woff: { - // // Woff Extended Metadata Block - see https://www.w3.org/TR/WOFF/#Metadata - // metadata: '...' - // }, - // ttf?: TtfOptions; // type TtfOptions = svg2ttf.FontOptions; - // svg?: SvgOptions; // type SvgOptions = Omit; - json: { indent: 4 } , - // ts: { - // // select what kind of types you want to generate - // // (default `['enum', 'constant', 'literalId', 'literalKey']`) - // types: ['enum', 'constant', 'literalId', 'literalKey'], - // // render the types with `'` instead of `"` (default is `"`) - // singleQuotes: false, - // // customise names used for the generated types and constants - // enumName: 'icon_gl', - // constantName: 'MY_CODEPOINTS' - // // literalIdName: 'IconId', - // // literalKeyName: 'IconKey' - // } + // woff: { + // // Woff Extended Metadata Block - see https://www.w3.org/TR/WOFF/#Metadata + // metadata: '...' + // }, + // ttf?: TtfOptions; // type TtfOptions = svg2ttf.FontOptions; + // svg?: SvgOptions; // type SvgOptions = Omit; + json: { + indent: 4 + }, + ts: { + // select what kind of types you want to generate + // (default `['enum', 'constant', 'literalId', 'literalKey']`) + types: ['enum', 'constant', 'literalId', 'literalKey'], + // render the types with `'` instead of `"` (default is `"`) + singleQuotes: false, + // customise names used for the generated types and constants + enumName: 'icon_gl', + constantName: 'MY_CODEPOINTS' + // literalIdName: 'IconId', + // literalKeyName: 'IconKey' + } }, pathOptions: { json: './dist/font/icon.gl.json', diff --git a/src/ts/class/SVGReader.ts b/src/ts/class/SVGReader.ts new file mode 100644 index 0000000..985fc20 --- /dev/null +++ b/src/ts/class/SVGReader.ts @@ -0,0 +1,53 @@ +// class/SvgReader.ts + +// Copyright 2023 Scape Agency BV + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 + +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +// ============================================================================ +// Import +// ============================================================================ + +import { promises as fs } from 'fs'; + + +// ============================================================================ +// Classes +// ============================================================================ + +class SvgReader { + + /** + * Reads the content of an SVG file asynchronously. + * @param filePath The path to the SVG file. + * @returns A promise that resolves to the content of the SVG file. + */ + async readSVG(filePath: string): Promise { + try { + const data = await fs.readFile(filePath, 'utf-8'); + return data; + } catch (error) { + console.error(`Error reading SVG file: ${filePath}`, error); + throw error; // Rethrow the error for further handling if necessary + } + } + +} + + +// ============================================================================ +// Export +// ============================================================================ + +export default SvgReader; diff --git a/src/ts/index.ts b/src/ts/index.ts index 11f2926..03d1814 100644 --- a/src/ts/index.ts +++ b/src/ts/index.ts @@ -20,25 +20,31 @@ // ============================================================================ // Import | Utility Classes +import DirectoryScanner from './class/DirectoryScanner'; import DirectoryCleaner from './class/DirectoryCleaner'; import DirectoryCopier from './class/DirectoryCopier'; import DirectoryCreator from './class/DirectoryCreator'; import FileCopier from './class/FileCopier'; import FileRenamer from './class/FileRenamer'; +import FilenameExtractor from './class/FilenameExtractor'; // Import | Internal Classes import FontGenerator from './class/FontGenerator.js'; import PackageCreator from './class/PackageCreator.js'; -import SvgPackager from "./class/SvgPackager.js"; import StyleProcessor from "./class/StyleProcessor.js"; -import SvgSpriteGenerator from "./class/SvgSpriteGenerator.js"; import VersionWriter from './class/VersionWriter.js'; import TypeScriptCompiler from './class/TypeScriptCompiler.js'; import JavaScriptMinifier from './class/JavaScriptMinifier.js'; import NpmCommandRunner from './class/NpmCommandRunner.js'; import StylizedLogger from './class/StylizedLogger.js'; import TemplateWriter from './class/TemplateWriter.js'; + +import SvgReader from './class/SvgReader.js'; import SvgToPngConverter from './class/SvgToPngConverter.js'; +import SvgSpriteGenerator from "./class/SvgSpriteGenerator.js"; +import SvgPackager from "./class/SvgPackager.js"; + + // Import | Internal Functions import gl_installer from './function/gl_installer'; @@ -53,25 +59,29 @@ import readPackageJson from "./function/readPackageJson.js" export { // Export | Utility Classes + DirectoryScanner, DirectoryCleaner, DirectoryCopier, DirectoryCreator, FileCopier, FileRenamer, + FilenameExtractor, // // Export | Internal Classes FontGenerator, PackageCreator, - SvgPackager, StyleProcessor, - SvgSpriteGenerator, VersionWriter, TypeScriptCompiler, JavaScriptMinifier, NpmCommandRunner, StylizedLogger, TemplateWriter, + + SvgReader, SvgToPngConverter, + SvgSpriteGenerator, + SvgPackager, // Export | Internal Functions gl_installer,