From 102f517cdabc4075c5984caca44c8a1782a04799 Mon Sep 17 00:00:00 2001 From: Lars van Vianen Date: Wed, 3 Jan 2024 15:15:50 +0100 Subject: [PATCH] v0.0.11 --- VERSION | 2 +- dist/js/class/DirectoryCleaner.js | 4 +- dist/js/class/DirectoryCopier.js | 59 ++++--- dist/js/class/DirectoryCreator.js | 37 +++-- dist/js/class/FileCopier.js | 37 +++-- dist/js/class/FileRenamer.js | 31 ++-- dist/js/class/FontGenerator.js | 161 ++++++++++++-------- dist/js/class/JavaScriptMinifier.js | 49 +++--- dist/js/class/NpmCommandRunner.d.ts | 9 ++ dist/js/class/NpmCommandRunner.js | 27 ++++ dist/js/class/PackageCreator.js | 25 ++- dist/js/class/StyleProcessor.js | 61 +++++--- dist/js/class/SvgPackager.js | 149 ++++++++++-------- dist/js/class/SvgSpriteGenerator.d.ts | 18 ++- dist/js/class/SvgSpriteGenerator.js | 83 ++++++---- dist/js/class/TypeScriptCompiler.js | 19 +-- dist/js/class/VersionWriter.js | 29 ++-- dist/js/config/postcss.config.compressed.js | 4 +- dist/js/config/postcss.config.expanded.js | 2 +- dist/js/config/svgsprite.config.d.ts | 3 + dist/js/config/svgsprite.config.js | 109 +++++++++++++ dist/js/config/ts.config.js | 106 ++++++++++++- dist/js/functions/gl_installer.d.ts | 2 + dist/js/functions/gl_installer.js | 40 +++++ dist/js/index.d.ts | 4 +- dist/js/index.js | 32 ++-- dist/package.json | 2 +- dist/ts/class/NpmCommandRunner.ts | 28 ++++ dist/ts/class/SvgSpriteGenerator.ts | 35 ++++- dist/ts/functions/gl_installer.ts | 38 +++++ dist/ts/index.ts | 7 + package-lock.json | 22 ++- package.json | 5 +- script/js/index.js | 3 +- script/js/index.js.map | 2 +- script/ts/index.ts | 4 +- src/ts/class/NpmCommandRunner.ts | 28 ++++ src/ts/class/SvgSpriteGenerator.ts | 35 ++++- src/ts/functions/gl_installer.ts | 38 +++++ src/ts/index.ts | 7 + 40 files changed, 1016 insertions(+), 340 deletions(-) create mode 100644 dist/js/class/NpmCommandRunner.d.ts create mode 100644 dist/js/class/NpmCommandRunner.js create mode 100644 dist/js/config/svgsprite.config.d.ts create mode 100644 dist/js/config/svgsprite.config.js create mode 100644 dist/js/functions/gl_installer.d.ts create mode 100644 dist/js/functions/gl_installer.js create mode 100644 dist/ts/class/NpmCommandRunner.ts create mode 100644 dist/ts/functions/gl_installer.ts create mode 100644 src/ts/class/NpmCommandRunner.ts create mode 100644 src/ts/functions/gl_installer.ts diff --git a/VERSION b/VERSION index b0a1227..58682af 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.10 \ No newline at end of file +0.0.11 \ No newline at end of file diff --git a/dist/js/class/DirectoryCleaner.js b/dist/js/class/DirectoryCleaner.js index a5766f2..7e72c80 100644 --- a/dist/js/class/DirectoryCleaner.js +++ b/dist/js/class/DirectoryCleaner.js @@ -18,8 +18,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); // Import // ============================================================================ // import { promises as fsPromises } from 'fs'; -var path_1 = __importDefault(require("path")); -var fs_1 = __importDefault(require("fs")); +const path_1 = __importDefault(require("path")); +const fs_1 = __importDefault(require("fs")); // ============================================================================ // Classes // ============================================================================ diff --git a/dist/js/class/DirectoryCopier.js b/dist/js/class/DirectoryCopier.js index b3ef303..123807e 100644 --- a/dist/js/class/DirectoryCopier.js +++ b/dist/js/class/DirectoryCopier.js @@ -1,5 +1,14 @@ "use strict"; // class/DirectoryCopier.ts +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; @@ -17,8 +26,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); // ============================================================================ // Import // ============================================================================ -var path_1 = __importDefault(require("path")); -var fs_1 = require("fs"); +const path_1 = __importDefault(require("path")); +const fs_1 = require("fs"); // ============================================================================ // Classes // ============================================================================ @@ -32,33 +41,37 @@ class DirectoryCopier { * @param destDir The destination directory path. * @throws Will throw an error if copying fails for any file or directory. */ - async copyFiles(srcDir, destDir) { - try { - const resolvedSrcDir = path_1.default.resolve(srcDir); - const resolvedDestDir = path_1.default.resolve(destDir); - await this.recursiveCopy(resolvedSrcDir, resolvedDestDir); - console.log(`Files copied from ${resolvedSrcDir} to ${resolvedDestDir}`); - } - catch (error) { - console.error('Error copying files:', error); - throw error; - } + copyFiles(srcDir, destDir) { + return __awaiter(this, void 0, void 0, function* () { + try { + const resolvedSrcDir = path_1.default.resolve(srcDir); + const resolvedDestDir = path_1.default.resolve(destDir); + yield this.recursiveCopy(resolvedSrcDir, resolvedDestDir); + console.log(`Files copied from ${resolvedSrcDir} to ${resolvedDestDir}`); + } + catch (error) { + console.error('Error copying files:', error); + throw error; + } + }); } /** * Recursively copies files and directories. * @param srcDir Source directory. * @param destDir Destination directory. */ - async recursiveCopy(srcDir, destDir) { - await fs_1.promises.mkdir(destDir, { recursive: true }); - const entries = await fs_1.promises.readdir(srcDir, { withFileTypes: true }); - for (let entry of entries) { - const srcPath = path_1.default.join(srcDir, entry.name); - const destPath = path_1.default.join(destDir, entry.name); - entry.isDirectory() ? - await this.recursiveCopy(srcPath, destPath) : - await fs_1.promises.copyFile(srcPath, destPath); - } + recursiveCopy(srcDir, destDir) { + return __awaiter(this, void 0, void 0, function* () { + yield fs_1.promises.mkdir(destDir, { recursive: true }); + const entries = yield fs_1.promises.readdir(srcDir, { withFileTypes: true }); + for (let entry of entries) { + const srcPath = path_1.default.join(srcDir, entry.name); + const destPath = path_1.default.join(destDir, entry.name); + entry.isDirectory() ? + yield this.recursiveCopy(srcPath, destPath) : + yield fs_1.promises.copyFile(srcPath, destPath); + } + }); } } // ============================================================================ diff --git a/dist/js/class/DirectoryCreator.js b/dist/js/class/DirectoryCreator.js index cc2f63c..87bb1d7 100644 --- a/dist/js/class/DirectoryCreator.js +++ b/dist/js/class/DirectoryCreator.js @@ -1,5 +1,14 @@ "use strict"; // class/DirectoryGenerator.ts +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; @@ -17,8 +26,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); // ============================================================================ // Import // ============================================================================ -var fs_1 = require("fs"); -var path_1 = __importDefault(require("path")); +const fs_1 = require("fs"); +const path_1 = __importDefault(require("path")); // ============================================================================ // Classes // ============================================================================ @@ -37,18 +46,20 @@ class DirectoryCreator { * available before performing file operations. * @throws Will throw an error if directory creation fails. */ - async createDirectories(basePath, directories) { - try { - for (const dir of directories) { - const dirPath = path_1.default.join(basePath, dir); - await fs_1.promises.mkdir(dirPath, { recursive: true }); - console.log(`Directory created or already exists: ${dirPath}`); + createDirectories(basePath, directories) { + return __awaiter(this, void 0, void 0, function* () { + try { + for (const dir of directories) { + const dirPath = path_1.default.join(basePath, dir); + yield fs_1.promises.mkdir(dirPath, { recursive: true }); + console.log(`Directory created or already exists: ${dirPath}`); + } + } + catch (error) { + console.error(`Error creating directories: ${error}`); + throw error; } - } - catch (error) { - console.error(`Error creating directories: ${error}`); - throw error; - } + }); } } // ============================================================================ diff --git a/dist/js/class/FileCopier.js b/dist/js/class/FileCopier.js index b4f7f8d..ac4d1af 100644 --- a/dist/js/class/FileCopier.js +++ b/dist/js/class/FileCopier.js @@ -1,5 +1,14 @@ "use strict"; // class/FileCopier.ts +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; @@ -17,8 +26,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); // ============================================================================ // Import // ============================================================================ -var fs_1 = __importDefault(require("fs")); -var path_1 = __importDefault(require("path")); +const fs_1 = __importDefault(require("fs")); +const path_1 = __importDefault(require("path")); // ============================================================================ // Classes // ============================================================================ @@ -32,17 +41,19 @@ class FileCopier { * @param {string} destDir - The destination directory where the file should be copied. * @throws Will throw an error if the file copy operation fails. */ - async copyFileToDirectory(srcFile, destDir) { - try { - const fileName = path_1.default.basename(srcFile); - const destFilePath = path_1.default.join(destDir, fileName); - await fs_1.default.promises.copyFile(srcFile, destFilePath); - console.log(`File copied from ${srcFile} to ${destFilePath}`); - } - catch (error) { - console.error('Error copying file:', error); - throw error; - } + copyFileToDirectory(srcFile, destDir) { + return __awaiter(this, void 0, void 0, function* () { + try { + const fileName = path_1.default.basename(srcFile); + const destFilePath = path_1.default.join(destDir, fileName); + yield fs_1.default.promises.copyFile(srcFile, destFilePath); + console.log(`File copied from ${srcFile} to ${destFilePath}`); + } + catch (error) { + console.error('Error copying file:', error); + throw error; + } + }); } } // ============================================================================ diff --git a/dist/js/class/FileRenamer.js b/dist/js/class/FileRenamer.js index d4607c5..94e67e1 100644 --- a/dist/js/class/FileRenamer.js +++ b/dist/js/class/FileRenamer.js @@ -1,5 +1,14 @@ "use strict"; // class/FileRenamer.ts +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; @@ -17,7 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); // ============================================================================ // Import // ============================================================================ -var fs_1 = __importDefault(require("fs")); +const fs_1 = __importDefault(require("fs")); // ============================================================================ // Classes // ============================================================================ @@ -31,15 +40,17 @@ class FileRenamer { * @param targetPath The new path of the file after renaming. * @returns Promise */ - async renameFile(srcPath, targetPath) { - try { - await fs_1.default.promises.rename(srcPath, targetPath); - console.log(`File renamed from ${srcPath} to ${targetPath}`); - } - catch (error) { - console.error('Error renaming file:', error); - throw error; - } + renameFile(srcPath, targetPath) { + return __awaiter(this, void 0, void 0, function* () { + try { + yield fs_1.default.promises.rename(srcPath, targetPath); + console.log(`File renamed from ${srcPath} to ${targetPath}`); + } + catch (error) { + console.error('Error renaming file:', error); + throw error; + } + }); } } // ============================================================================ diff --git a/dist/js/class/FontGenerator.js b/dist/js/class/FontGenerator.js index 007146a..ea32783 100644 --- a/dist/js/class/FontGenerator.js +++ b/dist/js/class/FontGenerator.js @@ -1,5 +1,14 @@ "use strict"; // class/FontGenerator.ts +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; Object.defineProperty(exports, "__esModule", { value: true }); // Copyright 2023 Scape Agency BV // Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,76 +23,98 @@ Object.defineProperty(exports, "__esModule", { value: true }); // ============================================================================ // Import // ============================================================================ -var fantasticon_1 = require("fantasticon"); +const fantasticon_1 = require("fantasticon"); // ============================================================================ // Classes // ============================================================================ class FontGenerator { - async generateFonts(sourceDirectory, outputDiectory) { - const config = { - // RunnerMandatoryOptions - inputDir: sourceDirectory, // (required) - outputDir: outputDiectory, // (required) - // RunnerOptionalOptions - name: 'icon.gl', - fontTypes: [ - fantasticon_1.FontAssetType.TTF, // TTF = "ttf" - fantasticon_1.FontAssetType.WOFF, // WOFF = "woff" - fantasticon_1.FontAssetType.WOFF2, // WOFF2 = "woff2" - fantasticon_1.FontAssetType.EOT, // EOT = "eot" - fantasticon_1.FontAssetType.SVG, // SVG = "svg" - ], - assetTypes: [ - fantasticon_1.OtherAssetType.CSS, // CSS = "css", - fantasticon_1.OtherAssetType.SCSS, // SCSS = "scss", - fantasticon_1.OtherAssetType.SASS, // SASS = "sass", - fantasticon_1.OtherAssetType.HTML, // HTML = "html", - fantasticon_1.OtherAssetType.JSON, // JSON = "json", - fantasticon_1.OtherAssetType.TS, // TS = "ts" - ], - formatOptions: { - // woff: { - // // Woff Extended Metadata Block - see https://www.w3.org/TR/WOFF/#Metadata - // metadata: '...' + generateFonts(sourceDirectory, outputDiectory) { + return __awaiter(this, void 0, void 0, function* () { + const config = { + // RunnerMandatoryOptions + inputDir: sourceDirectory, // (required) + outputDir: outputDiectory, // (required) + // RunnerOptionalOptions + name: 'icon.gl', + fontTypes: [ + fantasticon_1.FontAssetType.TTF, // TTF = "ttf" + fantasticon_1.FontAssetType.WOFF, // WOFF = "woff" + fantasticon_1.FontAssetType.WOFF2, // WOFF2 = "woff2" + fantasticon_1.FontAssetType.EOT, // EOT = "eot" + fantasticon_1.FontAssetType.SVG, // SVG = "svg" + ], + assetTypes: [ + fantasticon_1.OtherAssetType.CSS, // CSS = "css", + fantasticon_1.OtherAssetType.SCSS, // SCSS = "scss", + fantasticon_1.OtherAssetType.SASS, // SASS = "sass", + fantasticon_1.OtherAssetType.HTML, // HTML = "html", + fantasticon_1.OtherAssetType.JSON, // JSON = "json", + fantasticon_1.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' + // } + }, + pathOptions: { + json: './dist/font/icon.gl.json', + css: './dist/font/icon.gl.css', + scss: './dist/font/icon.gl.scss', + woff: './dist/font/icon.gl.woff', + woff2: './dist/font/icon.gl.woff2', + }, + // codepoints: { + // 'chevron-left': 57344, // decimal representation of 0xe000 + // 'chevron-right': 57345, + // 'thumbs-up': 57358, + // 'thumbs-down': 57359, // }, - // ttf?: TtfOptions; // type TtfOptions = svg2ttf.FontOptions; - // svg?: SvgOptions; // type SvgOptions = Omit; - json: { indent: 4 } - }, - pathOptions: { - json: './dist/font/icon.gl.json', - css: './dist/font/icon.gl.css', - scss: './dist/font/icon.gl.scss', - woff: './dist/font/icon.gl.woff', - woff2: './dist/font/icon.gl.woff2' - }, - // codepoints: { - // 'chevron-left': 57344, // decimal representation of 0xe000 - // 'chevron-right': 57345, - // 'thumbs-up': 57358, - // 'thumbs-down': 57359, - // }, - // fontHeight: number; - // descent: number; - // normalize: boolean; - // round: number; - selector: '.igl', - // tag: string; - // Use our custom Handlebars templates - // templates: { - // css: './build/font/icon.gl.css.hbs', - // scss: './build/font/icon.gl.scss.hbs' - // }, - prefix: 'igl', - fontsUrl: './fonts' - }; - try { - await (0, fantasticon_1.generateFonts)(config); - console.log('Fonts generated successfully.'); - } - catch (error) { - console.error('Error generating fonts:', error); - } + // fontHeight: number; + // descent: number; + // normalize: boolean; + // round: number; + selector: '.igl', + // tag: string; + // Use our custom Handlebars templates + // templates: { + // css: './build/font/icon.gl.css.hbs', + // scss: './build/font/icon.gl.scss.hbs' + // }, + prefix: 'igl', + fontsUrl: './fonts', + // Customize generated icon IDs (unavailable with `.json` config file) + // getIconId: ({ + // basename, // `string` - Example: 'foo'; + // relativeDirPath, // `string` - Example: 'sub/dir/foo.svg' + // absoluteFilePath, // `string` - Example: '/var/icons/sub/dir/foo.svg' + // relativeFilePath, // `string` - Example: 'foo.svg' + // index // `number` - Example: `0` + // }) => [index, basename].join('_') // '0_foo' + }; + try { + yield (0, fantasticon_1.generateFonts)(config); + console.log('Fonts generated successfully.'); + } + catch (error) { + console.error('Error generating fonts:', error); + } + }); } } // ============================================================================ diff --git a/dist/js/class/JavaScriptMinifier.js b/dist/js/class/JavaScriptMinifier.js index 1e09568..142a5dd 100644 --- a/dist/js/class/JavaScriptMinifier.js +++ b/dist/js/class/JavaScriptMinifier.js @@ -1,5 +1,14 @@ "use strict"; // class/JavaScriptMinifier.ts +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; Object.defineProperty(exports, "__esModule", { value: true }); // Copyright 2023 Scape Agency BV // Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,8 +23,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); // ============================================================================ // Import // ============================================================================ -var terser_1 = require("terser"); -var fs_1 = require("fs"); +const terser_1 = require("terser"); +const fs_1 = require("fs"); // ============================================================================ // Classes // ============================================================================ @@ -36,25 +45,27 @@ class JavaScriptMinifier { * @param {string} outputPath - Path to save the minified output file. * @returns {Promise} - A promise that resolves when minification is complete. */ - async minifyFile(inputPath, outputPath) { - try { - // Read the input file - const inputCode = await fs_1.promises.readFile(inputPath, 'utf8'); - // Minify the file using Terser - // const result = await minify(inputCode, options); - const result = await (0, terser_1.minify)(inputCode, this.config); - // If minification is successful, write the output - if (result.code) { - await fs_1.promises.writeFile(outputPath, result.code); + minifyFile(inputPath, outputPath) { + return __awaiter(this, void 0, void 0, function* () { + try { + // Read the input file + const inputCode = yield fs_1.promises.readFile(inputPath, 'utf8'); + // Minify the file using Terser + // const result = await minify(inputCode, options); + const result = yield (0, terser_1.minify)(inputCode, this.config); + // If minification is successful, write the output + if (result.code) { + yield fs_1.promises.writeFile(outputPath, result.code); + } + else { + throw new Error('Minification resulted in empty output.'); + } } - else { - throw new Error('Minification resulted in empty output.'); + catch (error) { + console.error(`Error minifying JavaScript file ${inputPath}:`, error); + throw error; } - } - catch (error) { - console.error(`Error minifying JavaScript file ${inputPath}:`, error); - throw error; - } + }); } } // ============================================================================ diff --git a/dist/js/class/NpmCommandRunner.d.ts b/dist/js/class/NpmCommandRunner.d.ts new file mode 100644 index 0000000..c580759 --- /dev/null +++ b/dist/js/class/NpmCommandRunner.d.ts @@ -0,0 +1,9 @@ +declare class NpmCommandRunner { + /** + * Executes an npm command. + * @param command The npm command to run. + * @returns A promise that resolves with the command output or rejects with an error. + */ + runCommand(command: string): Promise; +} +export default NpmCommandRunner; diff --git a/dist/js/class/NpmCommandRunner.js b/dist/js/class/NpmCommandRunner.js new file mode 100644 index 0000000..9e5e79e --- /dev/null +++ b/dist/js/class/NpmCommandRunner.js @@ -0,0 +1,27 @@ +"use strict"; +// TypeScript Class to Run NPM Commands +Object.defineProperty(exports, "__esModule", { value: true }); +const child_process_1 = require("child_process"); +class NpmCommandRunner { + /** + * Executes an npm command. + * @param command The npm command to run. + * @returns A promise that resolves with the command output or rejects with an error. + */ + runCommand(command) { + return new Promise((resolve, reject) => { + (0, child_process_1.exec)(`npm ${command}`, (error, stdout, stderr) => { + if (error) { + reject(`error: ${error.message}`); + return; + } + if (stderr) { + reject(`stderr: ${stderr}`); + return; + } + resolve(stdout); + }); + }); + } +} +exports.default = NpmCommandRunner; diff --git a/dist/js/class/PackageCreator.js b/dist/js/class/PackageCreator.js index 51e802f..06b11ab 100644 --- a/dist/js/class/PackageCreator.js +++ b/dist/js/class/PackageCreator.js @@ -1,5 +1,14 @@ "use strict"; // class/PackageCreator.ts +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; @@ -17,8 +26,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); // ============================================================================ // Import // ============================================================================ -var fs_1 = __importDefault(require("fs")); -var path_1 = __importDefault(require("path")); +const fs_1 = __importDefault(require("fs")); +const path_1 = __importDefault(require("path")); // ============================================================================ // Classes // ============================================================================ @@ -37,11 +46,13 @@ class PackageCreator { * Creates a package.json file in the specified directory. * @param {string} outputDir - The directory where package.json will be created. */ - async createPackageJson(outputDir) { - const filePath = path_1.default.join(outputDir, 'package.json'); - const data = JSON.stringify(this.packageJson, null, 2); - fs_1.default.writeFileSync(filePath, data, 'utf-8'); - console.log(`package.json created at ${filePath}`); + createPackageJson(outputDir) { + return __awaiter(this, void 0, void 0, function* () { + const filePath = path_1.default.join(outputDir, 'package.json'); + const data = JSON.stringify(this.packageJson, null, 2); + fs_1.default.writeFileSync(filePath, data, 'utf-8'); + console.log(`package.json created at ${filePath}`); + }); } } // ============================================================================ diff --git a/dist/js/class/StyleProcessor.js b/dist/js/class/StyleProcessor.js index af41c47..1370acc 100644 --- a/dist/js/class/StyleProcessor.js +++ b/dist/js/class/StyleProcessor.js @@ -23,6 +23,15 @@ var __importStar = (this && this.__importStar) || function (mod) { __setModuleDefault(result, mod); return result; }; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; @@ -40,11 +49,11 @@ Object.defineProperty(exports, "__esModule", { value: true }); // ============================================================================ // Import // ============================================================================ -var sass = __importStar(require("sass")); -var postcss_1 = __importDefault(require("postcss")); -var fs_1 = __importDefault(require("fs")); -var postcss_config_expanded_js_1 = __importDefault(require("../config/postcss.config.expanded.js")); -var postcss_config_compressed_js_1 = __importDefault(require("../config/postcss.config.compressed.js")); +const sass = __importStar(require("sass")); +const postcss_1 = __importDefault(require("postcss")); +const fs_1 = __importDefault(require("fs")); +const postcss_config_expanded_js_1 = __importDefault(require("../config/postcss.config.expanded.js")); +const postcss_config_compressed_js_1 = __importDefault(require("../config/postcss.config.compressed.js")); // ============================================================================ // Classes // ============================================================================ @@ -59,9 +68,11 @@ class StyleProcessor { * @param styleOption The style option, either 'expanded' or 'compressed'. * @returns Processed CSS string. */ - async processPostCSS(css, styleOption) { - const config = styleOption === 'expanded' ? postcss_config_expanded_js_1.default : postcss_config_compressed_js_1.default; - return (0, postcss_1.default)(config.plugins).process(css, { from: undefined, map: { inline: false } }); + processPostCSS(css, styleOption) { + return __awaiter(this, void 0, void 0, function* () { + const config = styleOption === 'expanded' ? postcss_config_expanded_js_1.default : postcss_config_compressed_js_1.default; + return (0, postcss_1.default)(config.plugins).process(css, { from: undefined, map: { inline: false } }); + }); } /** * Compiles SCSS to CSS and processes it using PostCSS. @@ -69,23 +80,25 @@ class StyleProcessor { * @param outputFile Path to the output CSS file. * @param styleOption Style option for the output. */ - async processStyles(inputFile, outputFile, styleOption) { - try { - // Compile SCSS to CSS - const result = await sass.compileAsync(inputFile, { style: styleOption }); - // Process the compiled CSS with PostCSS and Autoprefixer - const processed = await this.processPostCSS(result.css, styleOption); - // Write the processed CSS to a file - fs_1.default.writeFileSync(outputFile, processed.css); - // Write the source map file - if (processed.map) { - fs_1.default.writeFileSync(`${outputFile}.map`, processed.map.toString()); + processStyles(inputFile, outputFile, styleOption) { + return __awaiter(this, void 0, void 0, function* () { + try { + // Compile SCSS to CSS + const result = yield sass.compileAsync(inputFile, { style: styleOption }); + // Process the compiled CSS with PostCSS and Autoprefixer + const processed = yield this.processPostCSS(result.css, styleOption); + // Write the processed CSS to a file + fs_1.default.writeFileSync(outputFile, processed.css); + // Write the source map file + if (processed.map) { + fs_1.default.writeFileSync(`${outputFile}.map`, processed.map.toString()); + } + } + catch (err) { + // Handle errors in the compilation or processing + console.error(`Error processing styles from ${inputFile}:`, err); } - } - catch (err) { - // Handle errors in the compilation or processing - console.error(`Error processing styles from ${inputFile}:`, err); - } + }); } } // ============================================================================ diff --git a/dist/js/class/SvgPackager.js b/dist/js/class/SvgPackager.js index 3b70266..5a3e0f1 100644 --- a/dist/js/class/SvgPackager.js +++ b/dist/js/class/SvgPackager.js @@ -23,6 +23,15 @@ var __importStar = (this && this.__importStar) || function (mod) { __setModuleDefault(result, mod); return result; }; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; @@ -40,11 +49,11 @@ Object.defineProperty(exports, "__esModule", { value: true }); // ============================================================================ // Import // ============================================================================ -var fs = __importStar(require("fs/promises")); -var path = __importStar(require("path")); -var glob = __importStar(require("glob")); -var svgo_1 = __importDefault(require("svgo")); -var svgo_2 = require("svgo"); +const fs = __importStar(require("fs/promises")); +const path = __importStar(require("path")); +const glob = __importStar(require("glob")); +const svgo_1 = __importDefault(require("svgo")); +const svgo_2 = require("svgo"); // ============================================================================ // Classes // ============================================================================ @@ -66,37 +75,39 @@ class SvgPackager { * @param inputDirectory The directory containing SVG files to process. * @param outputDirectory The directory where optimized SVGs will be output as TypeScript files. */ - async processSvgFiles(inputDirectory, outputDirectory, ts_output_directory, json_output_directory) { - const iconNames = []; - try { - console.log(`Processing directory: ${inputDirectory}`); - const svgFiles = glob.sync(`${inputDirectory}/**/*.svg`); - for (const file of svgFiles) { - console.log(`Processing file: ${file}`); - const iconName = this.sanitizeFileName(path.basename(file, '.svg')); - iconNames.push(iconName); - console.log(`Processing icon: ${iconName}`); - const svgContent = await this.readSvgFile(file); - const optimizedSvg = await this.optimizeSvg(svgContent); - // const optimizedSvg = await this.optimizeSvg(file, svgContent); - // svgo will always add a final newline when in pretty mode - const resultSvg = optimizedSvg.trim(); - // Write the optimized SVG file - await this.writeSvgFile( - // file, - iconName, resultSvg, outputDirectory); - // Write the optimized TypeScript file - await this.writeTypeScriptFile( - // file, - iconName, resultSvg, ts_output_directory); + processSvgFiles(inputDirectory, outputDirectory, ts_output_directory, json_output_directory) { + return __awaiter(this, void 0, void 0, function* () { + const iconNames = []; + try { + console.log(`Processing directory: ${inputDirectory}`); + const svgFiles = glob.sync(`${inputDirectory}/**/*.svg`); + for (const file of svgFiles) { + console.log(`Processing file: ${file}`); + const iconName = this.sanitizeFileName(path.basename(file, '.svg')); + iconNames.push(iconName); + console.log(`Processing icon: ${iconName}`); + const svgContent = yield this.readSvgFile(file); + const optimizedSvg = yield this.optimizeSvg(svgContent); + // const optimizedSvg = await this.optimizeSvg(file, svgContent); + // svgo will always add a final newline when in pretty mode + const resultSvg = optimizedSvg.trim(); + // Write the optimized SVG file + yield this.writeSvgFile( + // file, + iconName, resultSvg, outputDirectory); + // Write the optimized TypeScript file + yield this.writeTypeScriptFile( + // file, + iconName, resultSvg, ts_output_directory); + } + yield this.writeIconsJson(iconNames, json_output_directory); + console.log(`Successfully processed ${svgFiles.length} SVG files.`); + } + catch (error) { + console.error('Error processing SVG files:', error); + throw error; } - await this.writeIconsJson(iconNames, json_output_directory); - console.log(`Successfully processed ${svgFiles.length} SVG files.`); - } - catch (error) { - console.error('Error processing SVG files:', error); - throw error; - } + }); } // public async processSvgFiles(directory: string, outputDirectory: string): Promise { // try { @@ -138,8 +149,10 @@ class SvgPackager { // throw error; // } // } - async readSvgFile(filePath) { - return fs.readFile(filePath, 'utf8'); + readSvgFile(filePath) { + return __awaiter(this, void 0, void 0, function* () { + return fs.readFile(filePath, 'utf8'); + }); } /** * Sanitizes a file name to be a valid TypeScript identifier. @@ -153,9 +166,11 @@ class SvgPackager { sanitizeFileName(fileName) { return fileName.replace(/[^a-zA-Z0-9_]/g, '_'); } - async writeFiles(iconName, svgContent, outputDirectory) { - await this.writeSvgFile(iconName, svgContent, outputDirectory); - await this.writeTypeScriptFile(iconName, svgContent, outputDirectory); + writeFiles(iconName, svgContent, outputDirectory) { + return __awaiter(this, void 0, void 0, function* () { + yield this.writeSvgFile(iconName, svgContent, outputDirectory); + yield this.writeTypeScriptFile(iconName, svgContent, outputDirectory); + }); } /** * Optimizes SVG content using SVGO. @@ -180,10 +195,12 @@ class SvgPackager { // throw error; // } // } - async optimizeSvg(svgContent) { - const config = await (0, svgo_2.loadConfig)(this.svgoConfigPath); - const result = await svgo_1.default.optimize(svgContent, { ...config }); - return result.data.trim(); + optimizeSvg(svgContent) { + return __awaiter(this, void 0, void 0, function* () { + const config = yield (0, svgo_2.loadConfig)(this.svgoConfigPath); + const result = yield svgo_1.default.optimize(svgContent, Object.assign({}, config)); + return result.data.trim(); + }); } /** * Creates a TypeScript file from SVG content. @@ -206,10 +223,12 @@ class SvgPackager { // throw error; // } // } - async writeTypeScriptFile(iconName, svgContent, outputDirectory) { - const tsContent = `export const icon_${iconName} = \`${svgContent}\`;\n`; - const outputPath = path.join(outputDirectory, `${iconName}.ts`); - await fs.writeFile(outputPath, tsContent); + writeTypeScriptFile(iconName, svgContent, outputDirectory) { + return __awaiter(this, void 0, void 0, function* () { + const tsContent = `export const icon_${iconName} = \`${svgContent}\`;\n`; + const outputPath = path.join(outputDirectory, `${iconName}.ts`); + yield fs.writeFile(outputPath, tsContent); + }); } /** * Writes the SVG content to a file. @@ -232,9 +251,11 @@ class SvgPackager { // throw error; // } // } - async writeSvgFile(iconName, svgContent, outputDirectory) { - const outputPath = path.join(outputDirectory, `${iconName}.svg`); - await fs.writeFile(outputPath, svgContent); + writeSvgFile(iconName, svgContent, outputDirectory) { + return __awaiter(this, void 0, void 0, function* () { + const outputPath = path.join(outputDirectory, `${iconName}.svg`); + yield fs.writeFile(outputPath, svgContent); + }); } /** * Writes a JSON file containing the names of processed icons. @@ -245,18 +266,20 @@ class SvgPackager { * @param iconNames An array of strings containing the names of the icons. * @param outputDirectory The directory where the JSON file will be saved. */ - async writeIconsJson(iconNames, outputDirectory) { - try { - const jsonContent = JSON.stringify(iconNames, null, 2); - const outputPath = path.join(outputDirectory, 'icons.json'); - // await fs_extra.outputFile(outputPath, jsonContent); - await fs.writeFile(outputPath, jsonContent); - console.log('Icons JSON file created successfully'); - } - catch (error) { - console.error('Error writing icons JSON file:', error); - throw error; - } + writeIconsJson(iconNames, outputDirectory) { + return __awaiter(this, void 0, void 0, function* () { + try { + const jsonContent = JSON.stringify(iconNames, null, 2); + const outputPath = path.join(outputDirectory, 'icons.json'); + // await fs_extra.outputFile(outputPath, jsonContent); + yield fs.writeFile(outputPath, jsonContent); + console.log('Icons JSON file created successfully'); + } + catch (error) { + console.error('Error writing icons JSON file:', error); + throw error; + } + }); } } // ============================================================================ diff --git a/dist/js/class/SvgSpriteGenerator.d.ts b/dist/js/class/SvgSpriteGenerator.d.ts index 6ec5cb0..b601d14 100644 --- a/dist/js/class/SvgSpriteGenerator.d.ts +++ b/dist/js/class/SvgSpriteGenerator.d.ts @@ -1,13 +1,25 @@ +import svgSprite from 'svg-sprite'; /** * A class for generating SVG sprites from individual SVG files. */ declare class SvgSpriteGenerator { - private config; /** * Constructs an instance of SvgSpriteGenerator with the provided configuration. - * @param {any} config - Configuration object for svg-sprite. + * @param {svgSprite.Config} config - Configuration object for svg-sprite. + */ + /** + * Configuration for the TypeScript compiler. + */ + private config; + /** + * Default configuration for the TypeScript compiler. + */ + private static defaultConfig; + /** + * Constructs an instance with merged configuration of default and custom options. + * @param {svgSprite.Config} customConfig - Optional custom configuration object for svg-sprite. */ - constructor(config: any); + constructor(customConfig?: svgSprite.Config); /** * Generates an SVG sprite from SVG files in a specified directory. * @param {string} sourceDir - Directory containing source SVG files. diff --git a/dist/js/class/SvgSpriteGenerator.js b/dist/js/class/SvgSpriteGenerator.js index 14ef2b7..739aefc 100644 --- a/dist/js/class/SvgSpriteGenerator.js +++ b/dist/js/class/SvgSpriteGenerator.js @@ -1,5 +1,14 @@ "use strict"; // class/SvgSpriteGenerator.ts +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; @@ -17,9 +26,10 @@ Object.defineProperty(exports, "__esModule", { value: true }); // ============================================================================ // Import // ============================================================================ -var svg_sprite_1 = __importDefault(require("svg-sprite")); -var fs_1 = __importDefault(require("fs")); -var path_1 = __importDefault(require("path")); +const svg_sprite_1 = __importDefault(require("svg-sprite")); +const fs_1 = __importDefault(require("fs")); +const path_1 = __importDefault(require("path")); +const svgsprite_config_js_1 = __importDefault(require("../config/svgsprite.config.js")); // ============================================================================ // Classes // ============================================================================ @@ -27,47 +37,54 @@ var path_1 = __importDefault(require("path")); * A class for generating SVG sprites from individual SVG files. */ class SvgSpriteGenerator { + // private static defaultConfig: CompilerOptions = tsConfig; /** - * Constructs an instance of SvgSpriteGenerator with the provided configuration. - * @param {any} config - Configuration object for svg-sprite. + * Constructs an instance with merged configuration of default and custom options. + * @param {svgSprite.Config} customConfig - Optional custom configuration object for svg-sprite. */ - constructor(config) { - this.config = config; + constructor(customConfig = {}) { + this.config = Object.assign(Object.assign({}, SvgSpriteGenerator.defaultConfig), customConfig); } /** * Generates an SVG sprite from SVG files in a specified directory. * @param {string} sourceDir - Directory containing source SVG files. * @param {string} outputDir - Directory where the generated sprite will be saved. */ - async generateSprite(sourceDir, outputDir) { - try { - const files = fs_1.default.readdirSync(sourceDir); - const sprite = new svg_sprite_1.default(this.config); - files.forEach(file => { - if (path_1.default.extname(file) === '.svg') { - const svgPath = path_1.default.resolve(sourceDir, file); - const content = fs_1.default.readFileSync(svgPath, 'utf8'); - sprite.add(svgPath, null, content); - } - }); - sprite.compile((error, result) => { - if (error) { - throw error; - } - for (const mode in result) { - for (const resource in result[mode]) { - const outputPath = path_1.default.resolve(outputDir, result[mode][resource].path); - fs_1.default.mkdirSync(path_1.default.dirname(outputPath), { recursive: true }); - fs_1.default.writeFileSync(outputPath, result[mode][resource].contents); + generateSprite(sourceDir, outputDir) { + return __awaiter(this, void 0, void 0, function* () { + try { + const files = fs_1.default.readdirSync(sourceDir); + const sprite = new svg_sprite_1.default(this.config); + files.forEach(file => { + if (path_1.default.extname(file) === '.svg') { + const svgPath = path_1.default.resolve(sourceDir, file); + const content = fs_1.default.readFileSync(svgPath, 'utf8'); + sprite.add(svgPath, null, content); + } + }); + sprite.compile((error, result) => { + if (error) { + throw error; + } + for (const mode in result) { + for (const resource in result[mode]) { + const outputPath = path_1.default.resolve(outputDir, result[mode][resource].path); + fs_1.default.mkdirSync(path_1.default.dirname(outputPath), { recursive: true }); + fs_1.default.writeFileSync(outputPath, result[mode][resource].contents); + } } - } - }); - } - catch (err) { - console.error('Error generating SVG sprite:', err); - } + }); + } + catch (err) { + console.error('Error generating SVG sprite:', err); + } + }); } } +/** + * Default configuration for the TypeScript compiler. + */ +SvgSpriteGenerator.defaultConfig = svgsprite_config_js_1.default; // ============================================================================ // Export // ============================================================================ diff --git a/dist/js/class/TypeScriptCompiler.js b/dist/js/class/TypeScriptCompiler.js index 86d3dd0..c7d1a68 100644 --- a/dist/js/class/TypeScriptCompiler.js +++ b/dist/js/class/TypeScriptCompiler.js @@ -18,8 +18,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); // Import // ============================================================================ // import * as ts from 'typescript'; -var typescript_1 = __importDefault(require("typescript")); -var ts_config_js_1 = __importDefault(require("../config/ts.config.js")); +const typescript_1 = __importDefault(require("typescript")); +const ts_config_js_1 = __importDefault(require("../config/ts.config.js")); // ============================================================================ // Classes // ============================================================================ @@ -28,20 +28,13 @@ var ts_config_js_1 = __importDefault(require("../config/ts.config.js")); * TypeScriptCompiler class for compiling TypeScript files to JavaScript. */ class TypeScriptCompiler { - /** - * Default configuration for the TypeScript compiler. - */ - static { this.defaultConfig = ts_config_js_1.default; } // private static defaultConfig: CompilerOptions = tsConfig; /** * Constructs an instance with merged configuration of default and custom options. * @param {ts.CompilerOptions} customConfig - Optional custom configuration object for TypeScript compiler */ constructor(customConfig = {}) { - this.config = { - ...TypeScriptCompiler.defaultConfig, - ...customConfig - }; + this.config = Object.assign(Object.assign({}, TypeScriptCompiler.defaultConfig), customConfig); } /** * Compiles TypeScript files to JavaScript. @@ -55,7 +48,7 @@ class TypeScriptCompiler { compile(filePaths, outDir) { return new Promise((resolve, reject) => { // Use outDir if provided, else fall back to this.config.outDir or a default - const options = { ...this.config, outDir: outDir || this.config.outDir || 'dist' }; + const options = Object.assign(Object.assign({}, this.config), { outDir: outDir || this.config.outDir || 'dist' }); // Create a TypeScript compiler host const host = typescript_1.default.createCompilerHost(options); // Create a program with the specified files and options @@ -89,6 +82,10 @@ class TypeScriptCompiler { }).join('\n'); } } +/** + * Default configuration for the TypeScript compiler. + */ +TypeScriptCompiler.defaultConfig = ts_config_js_1.default; // ============================================================================ // Export // ============================================================================ diff --git a/dist/js/class/VersionWriter.js b/dist/js/class/VersionWriter.js index e8d0827..3070397 100644 --- a/dist/js/class/VersionWriter.js +++ b/dist/js/class/VersionWriter.js @@ -1,5 +1,14 @@ "use strict"; // class/VersionWriter.ts +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; Object.defineProperty(exports, "__esModule", { value: true }); // Copyright 2023 Scape Agency BV // Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +23,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); // ============================================================================ // Import // ============================================================================ -var fs_1 = require("fs"); +const fs_1 = require("fs"); // ============================================================================ // Classes // ============================================================================ @@ -27,14 +36,16 @@ class VersionWriter { * @param {string} filePath - The file path where the version will be written. * @param {string} version - The version string to write to the file. */ - async writeVersionToFile(filePath, version) { - try { - await fs_1.promises.writeFile(filePath, version, 'utf8'); - console.log(`Version ${version} written to ${filePath}`); - } - catch (error) { - console.error(`Error writing version to file: ${error}`); - } + writeVersionToFile(filePath, version) { + return __awaiter(this, void 0, void 0, function* () { + try { + yield fs_1.promises.writeFile(filePath, version, 'utf8'); + console.log(`Version ${version} written to ${filePath}`); + } + catch (error) { + console.error(`Error writing version to file: ${error}`); + } + }); } } // ============================================================================ diff --git a/dist/js/config/postcss.config.compressed.js b/dist/js/config/postcss.config.compressed.js index 2d9be8a..4194598 100644 --- a/dist/js/config/postcss.config.compressed.js +++ b/dist/js/config/postcss.config.compressed.js @@ -17,8 +17,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); // ============================================================================ // Import // ============================================================================ -var autoprefixer_1 = __importDefault(require("autoprefixer")); -var cssnano_1 = __importDefault(require("cssnano")); +const autoprefixer_1 = __importDefault(require("autoprefixer")); +const cssnano_1 = __importDefault(require("cssnano")); // ============================================================================ // Constants // ============================================================================ diff --git a/dist/js/config/postcss.config.expanded.js b/dist/js/config/postcss.config.expanded.js index db1bf70..9e25801 100644 --- a/dist/js/config/postcss.config.expanded.js +++ b/dist/js/config/postcss.config.expanded.js @@ -17,7 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); // ============================================================================ // Import // ============================================================================ -var autoprefixer_1 = __importDefault(require("autoprefixer")); +const autoprefixer_1 = __importDefault(require("autoprefixer")); // ============================================================================ // Constants // ============================================================================ diff --git a/dist/js/config/svgsprite.config.d.ts b/dist/js/config/svgsprite.config.d.ts new file mode 100644 index 0000000..13ea770 --- /dev/null +++ b/dist/js/config/svgsprite.config.d.ts @@ -0,0 +1,3 @@ +import svgSprite from "svg-sprite"; +declare const svgspriteConfig: svgSprite.Config; +export default svgspriteConfig; diff --git a/dist/js/config/svgsprite.config.js b/dist/js/config/svgsprite.config.js new file mode 100644 index 0000000..30be997 --- /dev/null +++ b/dist/js/config/svgsprite.config.js @@ -0,0 +1,109 @@ +"use strict"; +// config/svg-sprite.config.ts +Object.defineProperty(exports, "__esModule", { value: true }); +// ============================================================================ +// Constants +// ============================================================================ +const svgspriteConfig = { + dest: './dist/sprite', // Main output directory + // log: null, // Logging verbosity (default: no logging) + shape: { + id: { + separator: '--', // Separator for directory name traversal + generator: 'icon-%s', + // generator: function () { /*...*/ }, // SVG shape ID generator callback + pseudo: '~' // File name separator for shape states (e.g. ':hover') + }, + dimension: { + maxWidth: 2000, // Max. shape width + maxHeight: 2000, // Max. shape height + precision: 2, // Floating point precision + attributes: false, // Width and height attributes on embedded shapes + }, + spacing: { + padding: 0, // Padding around all shapes + box: 'content' // Padding strategy (similar to CSS `box-sizing`) + }, + transform: ['svgo'], // List of transformations / optimizations + // meta: null, // Path to YAML file with meta / accessibility data + // align: null, // Path to YAML file with extended alignment data + // dest: null // Output directory for optimized intermediate SVG shapes + }, + svg: { + xmlDeclaration: false, // Add XML declaration to SVG sprite + // xmlDeclaration: true, // Add XML declaration to SVG sprite + doctypeDeclaration: true, // Add DOCTYPE declaration to SVG sprite + namespaceIDs: true, // Add namespace token to all IDs in SVG shapes + // namespaceIDPrefix: '', // Add a prefix to the automatically generated namespaceIDs + // namespaceClassnames: true, // Add namespace token to all CSS class names in SVG shapes + namespaceClassnames: false, // Add namespace token to all CSS class names in SVG shapes + dimensionAttributes: true // Width and height attributes on the sprite + }, + variables: {}, // Custom Mustache templating variables and functions + mode: { + css: { + render: { + css: true // Render CSS stylesheet + } + }, + view: true, // Create a «view» sprite + defs: true, // Create a «defs» sprite + // symbol: true, // Create a «symbol» sprite + symbol: { + // dest: ".", + // inline: true, // Prepare for inline embedding + sprite: "icon.gl.svg" + }, + stack: true, // Create a «stack» sprite + // symbol: true // Symbol sprite mode + } +}; +// ============================================================================ +// Export +// ============================================================================ +exports.default = svgspriteConfig; +// "svgo": { +// "multipass": true, +// "plugins": [ +// { +// "name": "preset-default", +// "params": { +// "overrides": { +// "removeUnknownsAndDefaults": { +// "keepDataAttrs": false, +// "keepRoleAttr": true +// }, +// "removeViewBox": false +// } +// } +// }, +// "cleanupListOfValues", +// "removeXMLNS", +// { +// "name": "removeAttrs", +// "params": { +// "attrs": [ +// "clip-rule", +// "fill" +// ] +// } +// } +// ] +// } +// : { +// dest: "", // Mode specific output directory +// prefix: "svg-%s", // Prefix for CSS selectors +// dimensions: "-dims", // Suffix for dimension CSS selectors +// sprite: "svg/sprite..svg", // Sprite path and name +// bust: true || false, // Cache busting (mode dependent default value) +// render: { // Stylesheet rendering definitions +// /* ------------------------------------------- +// css: false, // CSS stylesheet options +// scss: false, // Sass stylesheet options +// less: false, // LESS stylesheet options +// styl: false, // Stylus stylesheet options +// : ... // Custom stylesheet options +// ------------------------------------------- */ +// }, +// example: false // Create an HTML example document +// } diff --git a/dist/js/config/ts.config.js b/dist/js/config/ts.config.js index 5ce8453..1635d15 100644 --- a/dist/js/config/ts.config.js +++ b/dist/js/config/ts.config.js @@ -17,7 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); // ============================================================================ // Import // ============================================================================ -var typescript_1 = __importDefault(require("typescript")); +const typescript_1 = __importDefault(require("typescript")); // ============================================================================ // Constants // ============================================================================ @@ -154,7 +154,109 @@ const tsConfig = { // ======================================================================== // skipDefaultLibCheck: true, // Skip type checking .d.ts files that are included with TypeScript. // Skip type checking of declaration files - skipLibCheck: true + skipLibCheck: true, // Skip type checking all .d.ts files. + // Other + // ======================================================================== + // allowImportingTsExtensions?: boolean; + // allowJs?: boolean; + // allowArbitraryExtensions?: boolean; + // allowSyntheticDefaultImports?: boolean; + // allowUmdGlobalAccess?: boolean; + // allowUnreachableCode?: boolean; + // allowUnusedLabels?: boolean; + // alwaysStrict?: boolean; + // baseUrl?: string; + // charset?: string; + // checkJs?: boolean; + // customConditions?: string[]; + // declaration?: boolean; + // declarationMap?: boolean; + // emitDeclarationOnly?: boolean; + // declarationDir?: string; + // disableSizeLimit?: boolean; + // disableSourceOfProjectReferenceRedirect?: boolean; + // disableSolutionSearching?: boolean; + // disableReferencedProjectLoad?: boolean; + // downlevelIteration?: boolean; + // emitBOM?: boolean; + // emitDecoratorMetadata?: boolean; + // exactOptionalPropertyTypes?: boolean; + // experimentalDecorators?: boolean; + // forceConsistentCasingInFileNames?: boolean; + // ignoreDeprecations?: string; + // importHelpers?: boolean; + // importsNotUsedAsValues?: ImportsNotUsedAsValues; + // inlineSourceMap?: boolean; + // inlineSources?: boolean; + // isolatedModules?: boolean; + // jsx?: JsxEmit; + // keyofStringsOnly?: boolean; + // lib?: string[]; + // locale?: string; + // mapRoot?: string; + // maxNodeModuleJsDepth?: number; + // newLine?: NewLineKind; + // noEmit?: boolean; + // noEmitHelpers?: boolean; + // noEmitOnError?: boolean; + // noErrorTruncation?: boolean; + // noFallthroughCasesInSwitch?: boolean; + // noImplicitAny?: boolean; + // noImplicitReturns?: boolean; + // noImplicitThis?: boolean; + // noStrictGenericChecks?: boolean; + // noUnusedLocals?: boolean; + // noUnusedParameters?: boolean; + // noImplicitUseStrict?: boolean; + // noPropertyAccessFromIndexSignature?: boolean; + // assumeChangesOnlyAffectDirectDependencies?: boolean; + // noLib?: boolean; + // noResolve?: boolean; + // noUncheckedIndexedAccess?: boolean; + // out?: string; + // outDir?: string; + // outFile: 'icon.gl.js' // string; + // paths?: MapLike; + // preserveConstEnums?: boolean; + // noImplicitOverride?: boolean; + // preserveSymlinks?: boolean; + // preserveValueImports?: boolean; + // project?: string; + // reactNamespace?: string; + // jsxFactory?: string; + // jsxFragmentFactory?: string; + // jsxImportSource?: string; + // composite?: boolean; + // incremental?: boolean; + // tsBuildInfoFile?: string; + // removeComments?: boolean; + // resolvePackageJsonExports?: boolean; + // resolvePackageJsonImports?: boolean; + // rootDir?: string; + // rootDirs?: string[]; + // skipLibCheck?: boolean; + // skipDefaultLibCheck?: boolean; + // sourceMap?: boolean; + // sourceRoot?: string; + // strict?: boolean; + // strictFunctionTypes?: boolean; + // strictBindCallApply?: boolean; + // strictNullChecks?: boolean; + // strictPropertyInitialization?: boolean; + // stripInternal?: boolean; + // suppressExcessPropertyErrors?: boolean; + // suppressImplicitAnyIndexErrors?: boolean; + // target?: ScriptTarget; + // traceResolution?: boolean; + // useUnknownInCatchVariables?: boolean; + // resolveJsonModule?: boolean; + // types?: string[]; + // /** Paths used to compute primary types search locations + // typeRoots?: string[]; + // verbatimModuleSyntax?: boolean; + // esModuleInterop?: boolean; + // useDefineForClassFields?: boolean; + // [option: string]: CompilerOptionsValue | TsConfigSourceFile | undefined; }; // ============================================================================ // Export diff --git a/dist/js/functions/gl_installer.d.ts b/dist/js/functions/gl_installer.d.ts new file mode 100644 index 0000000..69b19e3 --- /dev/null +++ b/dist/js/functions/gl_installer.d.ts @@ -0,0 +1,2 @@ +declare function gl_installer(): Promise; +export default gl_installer; diff --git a/dist/js/functions/gl_installer.js b/dist/js/functions/gl_installer.js new file mode 100644 index 0000000..a3abf8f --- /dev/null +++ b/dist/js/functions/gl_installer.js @@ -0,0 +1,40 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const NpmCommandRunner_js_1 = __importDefault(require("../class/NpmCommandRunner.js")); +const runner = new NpmCommandRunner_js_1.default(); +// runner.runCommand('install') +// .then(output => console.log(output)) +// .catch(error => console.error(error)); +function gl_installer() { + return __awaiter(this, void 0, void 0, function* () { + try { + let output = ""; + console.log('Running npm install...'); + output = yield runner.runCommand('install pack.gl@latest --save-dev'); + console.log(output); + console.log('Running npm update...'); + output = yield runner.runCommand('install unit.gl@latest --save-dev'); + console.log(output); + // Add more npm commands as needed + // output = await runner.runCommand('your-next-command'); + // console.log(output); + } + catch (error) { + console.error('An error occurred:', error); + } + }); +} +exports.default = gl_installer; +// runSampleCommands(); diff --git a/dist/js/index.d.ts b/dist/js/index.d.ts index 205cdff..d740f3c 100644 --- a/dist/js/index.d.ts +++ b/dist/js/index.d.ts @@ -11,4 +11,6 @@ import SvgSpriteGenerator from "./class/SvgSpriteGenerator.js"; import VersionWriter from './class/VersionWriter.js'; import TypeScriptCompiler from './class/TypeScriptCompiler.js'; import JavaScriptMinifier from './class/JavaScriptMinifier.js'; -export { DirectoryCleaner, DirectoryCopier, DirectoryCreator, FileCopier, FileRenamer, FontGenerator, PackageCreator, SvgPackager, StyleProcessor, SvgSpriteGenerator, VersionWriter, TypeScriptCompiler, JavaScriptMinifier, }; +import NpmCommandRunner from './class/NpmCommandRunner.js'; +import gl_installer from './functions/gl_installer'; +export { DirectoryCleaner, DirectoryCopier, DirectoryCreator, FileCopier, FileRenamer, FontGenerator, PackageCreator, SvgPackager, StyleProcessor, SvgSpriteGenerator, VersionWriter, TypeScriptCompiler, JavaScriptMinifier, NpmCommandRunner, gl_installer, }; diff --git a/dist/js/index.js b/dist/js/index.js index 6234d50..103ba9f 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.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.gl_installer = 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; // 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,30 +19,34 @@ exports.JavaScriptMinifier = exports.TypeScriptCompiler = exports.VersionWriter // Import // ============================================================================ // Import | Utility Classes -var DirectoryCleaner_1 = __importDefault(require("./class/DirectoryCleaner")); +const DirectoryCleaner_1 = __importDefault(require("./class/DirectoryCleaner")); exports.DirectoryCleaner = DirectoryCleaner_1.default; -var DirectoryCopier_1 = __importDefault(require("./class/DirectoryCopier")); +const DirectoryCopier_1 = __importDefault(require("./class/DirectoryCopier")); exports.DirectoryCopier = DirectoryCopier_1.default; -var DirectoryCreator_1 = __importDefault(require("./class/DirectoryCreator")); +const DirectoryCreator_1 = __importDefault(require("./class/DirectoryCreator")); exports.DirectoryCreator = DirectoryCreator_1.default; -var FileCopier_1 = __importDefault(require("./class/FileCopier")); +const FileCopier_1 = __importDefault(require("./class/FileCopier")); exports.FileCopier = FileCopier_1.default; -var FileRenamer_1 = __importDefault(require("./class/FileRenamer")); +const FileRenamer_1 = __importDefault(require("./class/FileRenamer")); exports.FileRenamer = FileRenamer_1.default; // // Import | Internal Classes -var FontGenerator_js_1 = __importDefault(require("./class/FontGenerator.js")); +const FontGenerator_js_1 = __importDefault(require("./class/FontGenerator.js")); exports.FontGenerator = FontGenerator_js_1.default; -var PackageCreator_js_1 = __importDefault(require("./class/PackageCreator.js")); +const PackageCreator_js_1 = __importDefault(require("./class/PackageCreator.js")); exports.PackageCreator = PackageCreator_js_1.default; -var SvgPackager_js_1 = __importDefault(require("./class/SvgPackager.js")); +const SvgPackager_js_1 = __importDefault(require("./class/SvgPackager.js")); exports.SvgPackager = SvgPackager_js_1.default; -var StyleProcessor_js_1 = __importDefault(require("./class/StyleProcessor.js")); +const StyleProcessor_js_1 = __importDefault(require("./class/StyleProcessor.js")); exports.StyleProcessor = StyleProcessor_js_1.default; -var SvgSpriteGenerator_js_1 = __importDefault(require("./class/SvgSpriteGenerator.js")); +const SvgSpriteGenerator_js_1 = __importDefault(require("./class/SvgSpriteGenerator.js")); exports.SvgSpriteGenerator = SvgSpriteGenerator_js_1.default; -var VersionWriter_js_1 = __importDefault(require("./class/VersionWriter.js")); +const VersionWriter_js_1 = __importDefault(require("./class/VersionWriter.js")); exports.VersionWriter = VersionWriter_js_1.default; -var TypeScriptCompiler_js_1 = __importDefault(require("./class/TypeScriptCompiler.js")); +const TypeScriptCompiler_js_1 = __importDefault(require("./class/TypeScriptCompiler.js")); exports.TypeScriptCompiler = TypeScriptCompiler_js_1.default; -var JavaScriptMinifier_js_1 = __importDefault(require("./class/JavaScriptMinifier.js")); +const JavaScriptMinifier_js_1 = __importDefault(require("./class/JavaScriptMinifier.js")); exports.JavaScriptMinifier = JavaScriptMinifier_js_1.default; +const NpmCommandRunner_js_1 = __importDefault(require("./class/NpmCommandRunner.js")); +exports.NpmCommandRunner = NpmCommandRunner_js_1.default; +const gl_installer_1 = __importDefault(require("./functions/gl_installer")); +exports.gl_installer = gl_installer_1.default; diff --git a/dist/package.json b/dist/package.json index 8941cff..3c5850e 100644 --- a/dist/package.json +++ b/dist/package.json @@ -1,6 +1,6 @@ { "name": "pack.gl", - "version": "0.0.10", + "version": "0.0.11", "description": "Package Builder.", "keywords": [ "pack.gl", diff --git a/dist/ts/class/NpmCommandRunner.ts b/dist/ts/class/NpmCommandRunner.ts new file mode 100644 index 0000000..98a87ed --- /dev/null +++ b/dist/ts/class/NpmCommandRunner.ts @@ -0,0 +1,28 @@ +// TypeScript Class to Run NPM Commands + +import { exec } from 'child_process'; + +class NpmCommandRunner { + /** + * Executes an npm command. + * @param command The npm command to run. + * @returns A promise that resolves with the command output or rejects with an error. + */ + runCommand(command: string): Promise { + return new Promise((resolve, reject) => { + exec(`npm ${command}`, (error, stdout, stderr) => { + if (error) { + reject(`error: ${error.message}`); + return; + } + if (stderr) { + reject(`stderr: ${stderr}`); + return; + } + resolve(stdout); + }); + }); + } +} + +export default NpmCommandRunner; diff --git a/dist/ts/class/SvgSpriteGenerator.ts b/dist/ts/class/SvgSpriteGenerator.ts index 4e00225..2354088 100644 --- a/dist/ts/class/SvgSpriteGenerator.ts +++ b/dist/ts/class/SvgSpriteGenerator.ts @@ -22,6 +22,7 @@ import svgSprite from 'svg-sprite'; import fs from 'fs'; import path from 'path'; +import svgspriteConfig from "../config/svgsprite.config.js" // ============================================================================ @@ -33,15 +34,39 @@ import path from 'path'; */ class SvgSpriteGenerator { - private config: any; /** * Constructs an instance of SvgSpriteGenerator with the provided configuration. - * @param {any} config - Configuration object for svg-sprite. + * @param {svgSprite.Config} config - Configuration object for svg-sprite. */ - constructor(config: any) { - this.config = config; - } + // constructor(config: any) { + // this.config = config; + // } + + /** + * Configuration for the TypeScript compiler. + */ + private config: svgSprite.Config; + + /** + * Default configuration for the TypeScript compiler. + */ + private static defaultConfig: svgSprite.Config = svgspriteConfig; + // private static defaultConfig: CompilerOptions = tsConfig; + + /** + * Constructs an instance with merged configuration of default and custom options. + * @param {svgSprite.Config} customConfig - Optional custom configuration object for svg-sprite. + */ + constructor( + customConfig: svgSprite.Config = {}, + ) { + this.config = { + ...SvgSpriteGenerator.defaultConfig, + ...customConfig + }; + } + /** * Generates an SVG sprite from SVG files in a specified directory. diff --git a/dist/ts/functions/gl_installer.ts b/dist/ts/functions/gl_installer.ts new file mode 100644 index 0000000..3178c68 --- /dev/null +++ b/dist/ts/functions/gl_installer.ts @@ -0,0 +1,38 @@ + + +import NpmCommandRunner from '../class/NpmCommandRunner.js'; + + +const runner = new NpmCommandRunner(); + +// runner.runCommand('install') +// .then(output => console.log(output)) +// .catch(error => console.error(error)); + + +async function gl_installer() { + try { + + let output: string = "" + + console.log('Running npm install...'); + output = await runner.runCommand('install pack.gl@latest --save-dev'); + console.log(output); + + console.log('Running npm update...'); + output = await runner.runCommand('install unit.gl@latest --save-dev'); + console.log(output); + + // Add more npm commands as needed + // output = await runner.runCommand('your-next-command'); + // console.log(output); + + } catch (error) { + console.error('An error occurred:', error); + } +} + + +export default gl_installer; +// runSampleCommands(); + diff --git a/dist/ts/index.ts b/dist/ts/index.ts index 5f6da8b..731bb92 100644 --- a/dist/ts/index.ts +++ b/dist/ts/index.ts @@ -36,6 +36,10 @@ 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 gl_installer from './functions/gl_installer'; // // Import | Cconfigurations // import { CONFIG } from './config/config.js'; @@ -67,4 +71,7 @@ export { VersionWriter, TypeScriptCompiler, JavaScriptMinifier, + NpmCommandRunner, + + gl_installer, }; diff --git a/package-lock.json b/package-lock.json index c2d346a..e3c614e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pack.gl", - "version": "0.0.9", + "version": "0.0.10", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pack.gl", - "version": "0.0.9", + "version": "0.0.10", "funding": [ { "type": "github", @@ -51,9 +51,10 @@ "eslint-import-resolver-webpack": "^0.13.2", "eslint-plugin-prettier": "^5.0.1", "html-webpack-plugin": "^5.5.3", + "i": "^0.3.7", "lodash": "^4.17.21", "mini-css-extract-plugin": "^2.7.6", - "pack.gl": "^0.0.9", + "pack.gl": "^0.0.10", "postcss-loader": "^7.3.3", "postcss-preset-env": "^9.1.2", "prettier": "^3.0.3", @@ -8579,6 +8580,15 @@ "ms": "^2.0.0" } }, + "node_modules/i": { + "version": "0.3.7", + "resolved": "https://registry.npmjs.org/i/-/i-0.3.7.tgz", + "integrity": "sha512-FYz4wlXgkQwIPqhzC5TdNMLSE5+GS1IIDJZY/1ZiEPCT2S3COUVZeT5OW4BmW4r5LHLQuOosSwsvnroG9GR59Q==", + "dev": true, + "engines": { + "node": ">=0.4" + } + }, "node_modules/iconv-lite": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", @@ -10549,9 +10559,9 @@ } }, "node_modules/pack.gl": { - "version": "0.0.9", - "resolved": "https://registry.npmjs.org/pack.gl/-/pack.gl-0.0.9.tgz", - "integrity": "sha512-yJNca12C2Dla6VO+HmD6hMdc+3us1IoXpNRugleucqZuthUTHdiSo9D6puygWhbuwDhEasGwfMOZc0GKtbZG7Q==", + "version": "0.0.10", + "resolved": "https://registry.npmjs.org/pack.gl/-/pack.gl-0.0.10.tgz", + "integrity": "sha512-/O2V2AGA1pFCSIasK0GU7zjRo8qCuPUjjXN9s8jkUfjXveEO+ScjY+pr40MheXSmO1ZknWLsW0+X976As/DDFw==", "dev": true }, "node_modules/pako": { diff --git a/package.json b/package.json index 6b30f47..f34b8c1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "pack.gl", "description": "Package Builder.", - "version": "0.0.10", + "version": "0.0.11", "config": { "version_short": "0.0" }, @@ -89,9 +89,10 @@ "eslint-import-resolver-webpack": "^0.13.2", "eslint-plugin-prettier": "^5.0.1", "html-webpack-plugin": "^5.5.3", + "i": "^0.3.7", "lodash": "^4.17.21", "mini-css-extract-plugin": "^2.7.6", - "pack.gl": "^0.0.9", + "pack.gl": "^0.0.10", "postcss-loader": "^7.3.3", "postcss-preset-env": "^9.1.2", "prettier": "^3.0.3", diff --git a/script/js/index.js b/script/js/index.js index f3ed46c..15fa369 100644 --- a/script/js/index.js +++ b/script/js/index.js @@ -3,9 +3,8 @@ import path from 'path'; import { DirectoryCleaner, DirectoryCopier, DirectoryCreator, PackageCreator, VersionWriter, TypeScriptCompiler, } from 'pack.gl'; import { CONFIG } from './config/config.js'; import packageConfig from "./config/package.config.js"; -import tsConfig from "./config/ts.config.js"; var directories = Object.values(CONFIG.path); -var tsCompiler = new TypeScriptCompiler(tsConfig); +var tsCompiler = new TypeScriptCompiler(); var packageCreator = new PackageCreator(packageConfig); var versionWriter = new VersionWriter(); var directoryCopier = new DirectoryCopier(); diff --git a/script/js/index.js.map b/script/js/index.js.map index 86a4aec..c8c8caa 100644 --- a/script/js/index.js.map +++ b/script/js/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":";AAsBA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EACH,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,kBAAkB,GAErB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,aAAa,MAAM,4BAA4B,CAAA;AACtD,OAAO,QAAQ,MAAM,uBAAuB,CAAA;AAQ5C,IAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAC/C,IAAM,UAAU,GAAG,IAAI,kBAAkB,CAAC,QAAQ,CAAC,CAAC;AACpD,IAAM,cAAc,GAAG,IAAI,cAAc,CAAC,aAAa,CAAC,CAAC;AACzD,IAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC;AAC1C,IAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;AAC9C,IAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC;AAChD,IAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC;AAYhD,SAAe,IAAI;;;;;;;oBAOX,gBAAgB,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBAClD,OAAO,CAAC,GAAG,CAAC,6BAAsB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAE,CAAC,CAAC;oBAItD,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;oBAE9C,WAAM,gBAAgB,CAAC,iBAAiB,CAAC,GAAG,EAAE,WAAW,CAAC,EAAA;;oBAA1D,SAA0D,CAAC;;;;oBAOvD,WAAM,eAAe,CAAC,aAAa,CAC/B,MAAM,CAAC,IAAI,CAAC,QAAQ,EACpB,MAAM,CAAC,IAAI,CAAC,SAAS,CACxB,EAAA;;oBAHD,SAGC,CAAC;oBACF,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;;;;oBAE1C,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,OAAK,CAAC,CAAC;;wBAMvD,WAAM,aAAa,CAAC,kBAAkB,CAAC,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC,EAAA;;oBAAxE,SAAwE,CAAC;oBAMzE,WAAM,cAAc,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAA;;oBAAxD,SAAwD,CAAC;oBAOzD,IAAI,CAAC;wBAIK,OAAO,GAAG;4BACZ,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC;yBAI9C,CAAC;wBACI,SAAS,GAAG,WAAW,CAAC;wBAE9B,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;wBAClD,UAAU,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;wBACvC,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;oBAGrD,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACb,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;oBAC/C,CAAC;;;;oBAID,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,OAAK,CAAC,CAAC;;;;;;CAGlD;AAQD,IAAI,EAAE,CAAC"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../ts/index.ts"],"names":[],"mappings":";AAsBA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EACH,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,kBAAkB,GAErB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,aAAa,MAAM,4BAA4B,CAAA;AAStD,IAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAC/C,IAAM,UAAU,GAAG,IAAI,kBAAkB,EAAE,CAAC;AAC5C,IAAM,cAAc,GAAG,IAAI,cAAc,CAAC,aAAa,CAAC,CAAC;AACzD,IAAM,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC;AAC1C,IAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;AAC9C,IAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC;AAChD,IAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAC;AAYhD,SAAe,IAAI;;;;;;;oBAOX,gBAAgB,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBAClD,OAAO,CAAC,GAAG,CAAC,6BAAsB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAE,CAAC,CAAC;oBAItD,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;oBAE9C,WAAM,gBAAgB,CAAC,iBAAiB,CAAC,GAAG,EAAE,WAAW,CAAC,EAAA;;oBAA1D,SAA0D,CAAC;;;;oBAOvD,WAAM,eAAe,CAAC,aAAa,CAC/B,MAAM,CAAC,IAAI,CAAC,QAAQ,EACpB,MAAM,CAAC,IAAI,CAAC,SAAS,CACxB,EAAA;;oBAHD,SAGC,CAAC;oBACF,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;;;;oBAE1C,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,OAAK,CAAC,CAAC;;wBAMvD,WAAM,aAAa,CAAC,kBAAkB,CAAC,SAAS,EAAE,aAAa,CAAC,OAAO,CAAC,EAAA;;oBAAxE,SAAwE,CAAC;oBAMzE,WAAM,cAAc,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAA;;oBAAxD,SAAwD,CAAC;oBAOzD,IAAI,CAAC;wBAIK,OAAO,GAAG;4BACZ,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC;yBAI9C,CAAC;wBACI,SAAS,GAAG,WAAW,CAAC;wBAE9B,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;wBAClD,UAAU,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;wBACvC,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;oBAGrD,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACb,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;oBAC/C,CAAC;;;;oBAID,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,OAAK,CAAC,CAAC;;;;;;CAGlD;AAQD,IAAI,EAAE,CAAC"} \ No newline at end of file diff --git a/script/ts/index.ts b/script/ts/index.ts index 153ebcd..d47ad0a 100644 --- a/script/ts/index.ts +++ b/script/ts/index.ts @@ -34,7 +34,7 @@ import { // Import necessary configurations import { CONFIG } from './config/config.js'; import packageConfig from "./config/package.config.js" -import tsConfig from "./config/ts.config.js" +// import tsConfig from "./config/ts.config.js" // ============================================================================ @@ -43,7 +43,7 @@ import tsConfig from "./config/ts.config.js" // Initialize instances of necessary classes const directories = Object.values(CONFIG.path); -const tsCompiler = new TypeScriptCompiler(tsConfig); +const tsCompiler = new TypeScriptCompiler(); const packageCreator = new PackageCreator(packageConfig); const versionWriter = new VersionWriter(); const directoryCopier = new DirectoryCopier(); diff --git a/src/ts/class/NpmCommandRunner.ts b/src/ts/class/NpmCommandRunner.ts new file mode 100644 index 0000000..98a87ed --- /dev/null +++ b/src/ts/class/NpmCommandRunner.ts @@ -0,0 +1,28 @@ +// TypeScript Class to Run NPM Commands + +import { exec } from 'child_process'; + +class NpmCommandRunner { + /** + * Executes an npm command. + * @param command The npm command to run. + * @returns A promise that resolves with the command output or rejects with an error. + */ + runCommand(command: string): Promise { + return new Promise((resolve, reject) => { + exec(`npm ${command}`, (error, stdout, stderr) => { + if (error) { + reject(`error: ${error.message}`); + return; + } + if (stderr) { + reject(`stderr: ${stderr}`); + return; + } + resolve(stdout); + }); + }); + } +} + +export default NpmCommandRunner; diff --git a/src/ts/class/SvgSpriteGenerator.ts b/src/ts/class/SvgSpriteGenerator.ts index 4e00225..2354088 100644 --- a/src/ts/class/SvgSpriteGenerator.ts +++ b/src/ts/class/SvgSpriteGenerator.ts @@ -22,6 +22,7 @@ import svgSprite from 'svg-sprite'; import fs from 'fs'; import path from 'path'; +import svgspriteConfig from "../config/svgsprite.config.js" // ============================================================================ @@ -33,15 +34,39 @@ import path from 'path'; */ class SvgSpriteGenerator { - private config: any; /** * Constructs an instance of SvgSpriteGenerator with the provided configuration. - * @param {any} config - Configuration object for svg-sprite. + * @param {svgSprite.Config} config - Configuration object for svg-sprite. */ - constructor(config: any) { - this.config = config; - } + // constructor(config: any) { + // this.config = config; + // } + + /** + * Configuration for the TypeScript compiler. + */ + private config: svgSprite.Config; + + /** + * Default configuration for the TypeScript compiler. + */ + private static defaultConfig: svgSprite.Config = svgspriteConfig; + // private static defaultConfig: CompilerOptions = tsConfig; + + /** + * Constructs an instance with merged configuration of default and custom options. + * @param {svgSprite.Config} customConfig - Optional custom configuration object for svg-sprite. + */ + constructor( + customConfig: svgSprite.Config = {}, + ) { + this.config = { + ...SvgSpriteGenerator.defaultConfig, + ...customConfig + }; + } + /** * Generates an SVG sprite from SVG files in a specified directory. diff --git a/src/ts/functions/gl_installer.ts b/src/ts/functions/gl_installer.ts new file mode 100644 index 0000000..3178c68 --- /dev/null +++ b/src/ts/functions/gl_installer.ts @@ -0,0 +1,38 @@ + + +import NpmCommandRunner from '../class/NpmCommandRunner.js'; + + +const runner = new NpmCommandRunner(); + +// runner.runCommand('install') +// .then(output => console.log(output)) +// .catch(error => console.error(error)); + + +async function gl_installer() { + try { + + let output: string = "" + + console.log('Running npm install...'); + output = await runner.runCommand('install pack.gl@latest --save-dev'); + console.log(output); + + console.log('Running npm update...'); + output = await runner.runCommand('install unit.gl@latest --save-dev'); + console.log(output); + + // Add more npm commands as needed + // output = await runner.runCommand('your-next-command'); + // console.log(output); + + } catch (error) { + console.error('An error occurred:', error); + } +} + + +export default gl_installer; +// runSampleCommands(); + diff --git a/src/ts/index.ts b/src/ts/index.ts index 5f6da8b..731bb92 100644 --- a/src/ts/index.ts +++ b/src/ts/index.ts @@ -36,6 +36,10 @@ 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 gl_installer from './functions/gl_installer'; // // Import | Cconfigurations // import { CONFIG } from './config/config.js'; @@ -67,4 +71,7 @@ export { VersionWriter, TypeScriptCompiler, JavaScriptMinifier, + NpmCommandRunner, + + gl_installer, };