Skip to content

Commit

Permalink
v0.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
vanvianen committed Jan 2, 2024
1 parent da16a54 commit edbae38
Show file tree
Hide file tree
Showing 51 changed files with 2,857 additions and 43 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.6
0.0.7
4 changes: 4 additions & 0 deletions dist/js/class/FontGenerator.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare class FontGenerator {
generateFonts(sourceDirectory: string, outputDiectory: string): Promise<void>;
}
export default FontGenerator;
92 changes: 92 additions & 0 deletions dist/js/class/FontGenerator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
"use strict";
// class/FontGenerator.ts
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright 2023 Scape Agency BV
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================
// Import
// ============================================================================
var 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: '...'
// },
// ttf?: TtfOptions; // type TtfOptions = svg2ttf.FontOptions;
// svg?: SvgOptions; // type SvgOptions = Omit<SvgIcons2FontOptions, 'fontName' | 'fontHeight' | 'descent' | 'normalize'>;
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);
}
}
}
// ============================================================================
// Export
// ============================================================================
exports.default = FontGenerator;
19 changes: 19 additions & 0 deletions dist/js/class/JavaScriptMinifier.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Class to minify JavaScript files using Terser.
*/
declare class JavaScriptMinifier {
private config;
/**
* Constructs an instance with the provided configuration.
* @param {any} config - Configuration object - minification options for Terser.
*/
constructor(config: any);
/**
* Minifies a JavaScript file.
* @param {string} inputPath - Path to the input JavaScript file.
* @param {string} outputPath - Path to save the minified output file.
* @returns {Promise<void>} - A promise that resolves when minification is complete.
*/
minifyFile(inputPath: string, outputPath: string): Promise<void>;
}
export default JavaScriptMinifier;
63 changes: 63 additions & 0 deletions dist/js/class/JavaScriptMinifier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"use strict";
// class/JavaScriptMinifier.ts
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright 2023 Scape Agency BV
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================
// Import
// ============================================================================
var terser_1 = require("terser");
var fs_1 = require("fs");
// ============================================================================
// Classes
// ============================================================================
/**
* Class to minify JavaScript files using Terser.
*/
class JavaScriptMinifier {
/**
* Constructs an instance with the provided configuration.
* @param {any} config - Configuration object - minification options for Terser.
*/
constructor(config) {
this.config = config;
}
/**
* Minifies a JavaScript file.
* @param {string} inputPath - Path to the input JavaScript file.
* @param {string} outputPath - Path to save the minified output file.
* @returns {Promise<void>} - 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);
}
else {
throw new Error('Minification resulted in empty output.');
}
}
catch (error) {
console.error(`Error minifying JavaScript file ${inputPath}:`, error);
throw error;
}
}
}
// ============================================================================
// Export
// ============================================================================
exports.default = JavaScriptMinifier;
18 changes: 18 additions & 0 deletions dist/js/class/PackageCreator.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { PackageJson } from '../interface/PackageJson.js';
/**
* A class for creating a package.json file for a project.
*/
declare class PackageCreator {
private packageJson;
/**
* Initializes a new instance of the PackageCreator class.
* @param {PackageJson} packageJson - The content to be written into package.json.
*/
constructor(packageJson: PackageJson);
/**
* Creates a package.json file in the specified directory.
* @param {string} outputDir - The directory where package.json will be created.
*/
createPackageJson(outputDir: string): Promise<void>;
}
export default PackageCreator;
50 changes: 50 additions & 0 deletions dist/js/class/PackageCreator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"use strict";
// class/PackageCreator.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 = __importDefault(require("fs"));
var path_1 = __importDefault(require("path"));
// ============================================================================
// Classes
// ============================================================================
/**
* A class for creating a package.json file for a project.
*/
class PackageCreator {
/**
* Initializes a new instance of the PackageCreator class.
* @param {PackageJson} packageJson - The content to be written into package.json.
*/
constructor(packageJson) {
this.packageJson = packageJson;
}
/**
* 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}`);
}
}
// ============================================================================
// Export
// ============================================================================
exports.default = PackageCreator;
24 changes: 24 additions & 0 deletions dist/js/class/StyleProcessor.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// <reference types="node" />
import postcss from 'postcss';
import fs from 'fs';
/**
* Class responsible for processing styles, including compiling SCSS and
* applying PostCSS transformations.
*/
declare class StyleProcessor {
/**
* Processes the given CSS with PostCSS based on the provided style option.
* @param css The CSS string to process.
* @param styleOption The style option, either 'expanded' or 'compressed'.
* @returns Processed CSS string.
*/
processPostCSS(css: string, styleOption: 'expanded' | 'compressed'): Promise<postcss.Result<postcss.Root>>;
/**
* Compiles SCSS to CSS and processes it using PostCSS.
* @param inputFile Path to the input SCSS file.
* @param outputFile Path to the output CSS file.
* @param styleOption Style option for the output.
*/
processStyles(inputFile: string, outputFile: fs.PathOrFileDescriptor, styleOption: 'expanded' | 'compressed'): Promise<void>;
}
export default StyleProcessor;
94 changes: 94 additions & 0 deletions dist/js/class/StyleProcessor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
"use strict";
// class/StyleProcessor.ts
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
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 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"));
// ============================================================================
// Classes
// ============================================================================
/**
* Class responsible for processing styles, including compiling SCSS and
* applying PostCSS transformations.
*/
class StyleProcessor {
/**
* Processes the given CSS with PostCSS based on the provided style option.
* @param css The CSS string to process.
* @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 } });
}
/**
* Compiles SCSS to CSS and processes it using PostCSS.
* @param inputFile Path to the input SCSS file.
* @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());
}
}
catch (err) {
// Handle errors in the compilation or processing
console.error(`Error processing styles from ${inputFile}:`, err);
}
}
}
// ============================================================================
// Export
// ============================================================================
exports.default = StyleProcessor;
Loading

0 comments on commit edbae38

Please sign in to comment.