From 3bb430d04b5247e30d073162241d519a1481d0f8 Mon Sep 17 00:00:00 2001 From: Lars van Vianen Date: Wed, 10 Jan 2024 00:59:05 +0100 Subject: [PATCH] v0.0.39 --- VERSION | 2 +- dist/js/class/JSONLoader.d.ts | 21 +++++++ dist/js/class/JSONLoader.js | 70 +++++++++++++++++++++++ dist/js/config/fantasticon.config.js | 16 +++--- dist/js/index.d.ts | 3 +- dist/js/index.js | 4 +- dist/package.json | 2 +- dist/ts/class/JSONLoader.ts | 84 ++++++++++++++++++++++++++++ dist/ts/config/fantasticon.config.ts | 17 +++--- dist/ts/index.ts | 2 + package-lock.json | 4 +- package.json | 2 +- 12 files changed, 204 insertions(+), 23 deletions(-) create mode 100644 dist/js/class/JSONLoader.d.ts create mode 100644 dist/js/class/JSONLoader.js create mode 100644 dist/ts/class/JSONLoader.ts diff --git a/VERSION b/VERSION index 311e80e..1ceb3b8 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.0.38 \ No newline at end of file +0.0.39 \ No newline at end of file diff --git a/dist/js/class/JSONLoader.d.ts b/dist/js/class/JSONLoader.d.ts new file mode 100644 index 0000000..8f99157 --- /dev/null +++ b/dist/js/class/JSONLoader.d.ts @@ -0,0 +1,21 @@ +declare class JSONLoader { + /** + * Asynchronously loads JSON data from a file and returns it as an object. + * @param filePath The path to the JSON file. + * @returns A promise that resolves to an object containing the JSON data. + */ + loadJSON(filePath: string): Promise; + /** + * Asynchronously loads all JSON files from a given directory. + * @param dirPath The path to the directory containing JSON files. + * @returns A promise that resolves to an array of objects containing the JSON data. + */ + loadJSONFromDirectory(dirPath: string): Promise; + /** + * Merges an array of objects into a single object. + * @param objects An array of objects to merge. + * @returns A single object containing all properties from the input objects. + */ + mergeJSONObjects(objects: T[]): Promise; +} +export default JSONLoader; diff --git a/dist/js/class/JSONLoader.js b/dist/js/class/JSONLoader.js new file mode 100644 index 0000000..9cd9caa --- /dev/null +++ b/dist/js/class/JSONLoader.js @@ -0,0 +1,70 @@ +"use strict"; +// class/JSONLoader.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 fs_1 = require("fs"); +var path_1 = __importDefault(require("path")); +// ============================================================================ +// Classes +// ============================================================================ +class JSONLoader { + /** + * Asynchronously loads JSON data from a file and returns it as an object. + * @param filePath The path to the JSON file. + * @returns A promise that resolves to an object containing the JSON data. + */ + async loadJSON(filePath) { + try { + const data = await fs_1.promises.readFile(filePath, 'utf8'); + return JSON.parse(data); + } + catch (error) { + console.error(`Error reading JSON file: ${filePath}`, error); + throw error; + } + } + /** + * Asynchronously loads all JSON files from a given directory. + * @param dirPath The path to the directory containing JSON files. + * @returns A promise that resolves to an array of objects containing the JSON data. + */ + async loadJSONFromDirectory(dirPath) { + try { + const files = await fs_1.promises.readdir(dirPath); + const jsonFiles = files.filter(file => file.endsWith('.json')); + const jsonData = await Promise.all(jsonFiles.map(file => this.loadJSON(path_1.default.join(dirPath, file)))); + return jsonData; + } + catch (error) { + console.error(`Error reading JSON files from directory: ${dirPath}`, error); + throw error; + } + } + /** + * Merges an array of objects into a single object. + * @param objects An array of objects to merge. + * @returns A single object containing all properties from the input objects. + */ + async mergeJSONObjects(objects) { + return objects.reduce((acc, obj) => ({ ...acc, ...obj }), {}); + } +} +// ============================================================================ +// Export +// ============================================================================ +exports.default = JSONLoader; diff --git a/dist/js/config/fantasticon.config.js b/dist/js/config/fantasticon.config.js index b2d6493..de5602d 100644 --- a/dist/js/config/fantasticon.config.js +++ b/dist/js/config/fantasticon.config.js @@ -17,7 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); var fantasticon_1 = require("fantasticon"); const fantasticonConfig = { // RunnerOptionalOptions - name: 'icon.gl', + name: 'icon', fontTypes: [ fantasticon_1.FontAssetType.TTF, // TTF = "ttf" fantasticon_1.FontAssetType.WOFF, // WOFF = "woff" @@ -59,17 +59,17 @@ const fantasticonConfig = { 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, - // }, + 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', + selector: '.i', // tag: string; // Use our custom Handlebars templates // templates: { diff --git a/dist/js/index.d.ts b/dist/js/index.d.ts index 7b7759f..809c409 100644 --- a/dist/js/index.d.ts +++ b/dist/js/index.d.ts @@ -22,7 +22,8 @@ import SvgPackager from "./class/SvgPackager.js"; import TestRunner from './class/TestRunner.js'; import DocumentationGenerator from './class/DocumentationGenerator.js'; import CodeLinter from './class/CodeLinter.js'; +import JSONLoader from './class/JSONLoader.js'; import gl_installer from './function/gl_installer'; import cleanDirectory from './function/clean_directory'; import readPackageJson from "./function/readPackageJson.js"; -export { DirectoryScanner, DirectoryCleaner, DirectoryCopier, DirectoryCreator, FileCopier, FileRenamer, FilenameExtractor, FontGenerator, PackageCreator, StyleProcessor, VersionWriter, VersionManager, TypeScriptCompiler, JavaScriptMinifier, NpmCommandRunner, StylizedLogger, TemplateWriter, TestRunner, DocumentationGenerator, CodeLinter, SvgReader, SvgToPngConverter, SvgSpriteGenerator, SvgPackager, gl_installer, cleanDirectory, readPackageJson, }; +export { DirectoryScanner, DirectoryCleaner, DirectoryCopier, DirectoryCreator, FileCopier, FileRenamer, FilenameExtractor, FontGenerator, PackageCreator, StyleProcessor, VersionWriter, VersionManager, TypeScriptCompiler, JavaScriptMinifier, NpmCommandRunner, StylizedLogger, TemplateWriter, TestRunner, DocumentationGenerator, CodeLinter, JSONLoader, SvgReader, SvgToPngConverter, SvgSpriteGenerator, SvgPackager, gl_installer, cleanDirectory, readPackageJson, }; diff --git a/dist/js/index.js b/dist/js/index.js index 8265a0e..6623871 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.SvgPackager = exports.SvgSpriteGenerator = exports.SvgToPngConverter = exports.SvgReader = exports.CodeLinter = exports.DocumentationGenerator = exports.TestRunner = exports.TemplateWriter = exports.StylizedLogger = exports.NpmCommandRunner = exports.JavaScriptMinifier = exports.TypeScriptCompiler = exports.VersionManager = exports.VersionWriter = exports.StyleProcessor = exports.PackageCreator = exports.FontGenerator = exports.FilenameExtractor = exports.FileRenamer = exports.FileCopier = exports.DirectoryCreator = exports.DirectoryCopier = exports.DirectoryCleaner = exports.DirectoryScanner = void 0; +exports.readPackageJson = exports.cleanDirectory = exports.gl_installer = exports.SvgPackager = exports.SvgSpriteGenerator = exports.SvgToPngConverter = exports.SvgReader = exports.JSONLoader = exports.CodeLinter = exports.DocumentationGenerator = exports.TestRunner = exports.TemplateWriter = exports.StylizedLogger = exports.NpmCommandRunner = exports.JavaScriptMinifier = exports.TypeScriptCompiler = exports.VersionManager = 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. @@ -68,6 +68,8 @@ var DocumentationGenerator_js_1 = __importDefault(require("./class/Documentation exports.DocumentationGenerator = DocumentationGenerator_js_1.default; var CodeLinter_js_1 = __importDefault(require("./class/CodeLinter.js")); exports.CodeLinter = CodeLinter_js_1.default; +var JSONLoader_js_1 = __importDefault(require("./class/JSONLoader.js")); +exports.JSONLoader = JSONLoader_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 2946640..75b492d 100644 --- a/dist/package.json +++ b/dist/package.json @@ -1,6 +1,6 @@ { "name": "pack.gl", - "version": "0.0.38", + "version": "0.0.39", "description": "Package Builder.", "keywords": [ "pack.gl", diff --git a/dist/ts/class/JSONLoader.ts b/dist/ts/class/JSONLoader.ts new file mode 100644 index 0000000..4435f56 --- /dev/null +++ b/dist/ts/class/JSONLoader.ts @@ -0,0 +1,84 @@ +// class/JSONLoader.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'; +import path from 'path'; + + +// ============================================================================ +// Classes +// ============================================================================ + +class JSONLoader { + /** + * Asynchronously loads JSON data from a file and returns it as an object. + * @param filePath The path to the JSON file. + * @returns A promise that resolves to an object containing the JSON data. + */ + async loadJSON(filePath: string): Promise { + try { + const data = await fs.readFile(filePath, 'utf8'); + return JSON.parse(data) as T; + } catch (error) { + console.error(`Error reading JSON file: ${filePath}`, error); + throw error; + } + } + + /** + * Asynchronously loads all JSON files from a given directory. + * @param dirPath The path to the directory containing JSON files. + * @returns A promise that resolves to an array of objects containing the JSON data. + */ + async loadJSONFromDirectory(dirPath: string): Promise { + try { + const files = await fs.readdir(dirPath); + const jsonFiles = files.filter(file => file.endsWith('.json')); + + const jsonData = await Promise.all( + jsonFiles.map(file => + this.loadJSON(path.join(dirPath, file)) + ) + ); + + return jsonData; + } catch (error) { + console.error(`Error reading JSON files from directory: ${dirPath}`, error); + throw error; + } + } + + /** + * Merges an array of objects into a single object. + * @param objects An array of objects to merge. + * @returns A single object containing all properties from the input objects. + */ + async mergeJSONObjects(objects: T[]): Promise { + return objects.reduce((acc, obj) => ({ ...acc, ...obj }), {} as T); + } +} + + +// ============================================================================ +// Export +// ============================================================================ + +export default JSONLoader; \ No newline at end of file diff --git a/dist/ts/config/fantasticon.config.ts b/dist/ts/config/fantasticon.config.ts index 97f3c53..e939dc5 100644 --- a/dist/ts/config/fantasticon.config.ts +++ b/dist/ts/config/fantasticon.config.ts @@ -27,7 +27,7 @@ import RunnerOptionalOptions from 'fantasticon'; const fantasticonConfig: any = { // RunnerOptionalOptions - name: 'icon.gl', + name: 'icon', fontTypes: [ FontAssetType.TTF, // TTF = "ttf" FontAssetType.WOFF, // WOFF = "woff" @@ -72,17 +72,18 @@ const fantasticonConfig: any = { 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, - // }, + + 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', + selector: '.i', // tag: string; // Use our custom Handlebars templates // templates: { diff --git a/dist/ts/index.ts b/dist/ts/index.ts index 0b3b7e4..8357035 100644 --- a/dist/ts/index.ts +++ b/dist/ts/index.ts @@ -50,6 +50,7 @@ import SvgPackager from "./class/SvgPackager.js"; import TestRunner from './class/TestRunner.js'; import DocumentationGenerator from './class/DocumentationGenerator.js'; import CodeLinter from './class/CodeLinter.js'; +import JSONLoader from './class/JSONLoader.js'; // Import | Internal Functions @@ -87,6 +88,7 @@ export { TestRunner, DocumentationGenerator, CodeLinter, + JSONLoader, SvgReader, SvgToPngConverter, diff --git a/package-lock.json b/package-lock.json index c04ab28..afd129f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pack.gl", - "version": "0.0.37", + "version": "0.0.38", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pack.gl", - "version": "0.0.37", + "version": "0.0.38", "funding": [ { "type": "github", diff --git a/package.json b/package.json index ce5430a..1abc4d9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "pack.gl", "description": "Package Builder.", - "version": "0.0.38", + "version": "0.0.39", "config": { "version_short": "0.0" },