Skip to content

Commit

Permalink
v0.0.34
Browse files Browse the repository at this point in the history
  • Loading branch information
vanvianen committed Jan 4, 2024
1 parent 8b7b9ff commit 0af7ae4
Show file tree
Hide file tree
Showing 19 changed files with 412 additions and 506 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.32
0.0.33
18 changes: 6 additions & 12 deletions bin/js/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bin/js/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 7 additions & 10 deletions bin/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,13 @@ async function main() {

// Minify JavaScript
// --------------------------------------------------------------------
const jsMinifier = new JavaScriptMinifier();
await jsMinifier.minifyFile(
path.join(CONFIG.path.js_output, 'index.js'),
path.join(CONFIG.path.js_output, `${packageConfig.name}.min.js`),
)
.then(() => console.log('JavaScript minification completed.'))
.catch(console.error);



// const jsMinifier = new JavaScriptMinifier();
// await jsMinifier.minifyFile(
// path.join(CONFIG.path.js_output, 'index.js'),
// path.join(CONFIG.path.js_output, `${packageConfig.name}.min.js`),
// )
// .then(() => console.log('JavaScript minification completed.'))
// .catch(console.error);


} catch (error) {
Expand Down
11 changes: 2 additions & 9 deletions dist/js/class/StyleProcessor.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
/// <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>>;
processPostCSS(css: string, styleOption: 'expanded' | 'compressed'): Promise<string>;
/**
* Ensures that the given directory exists. Creates it if it does not exist.
* @param dirPath - The path of the directory to check and create.
Expand All @@ -24,6 +17,6 @@ declare class StyleProcessor {
* @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>;
processStyles(inputFile: string, outputFile: string, styleOption: 'expanded' | 'compressed'): Promise<void>;
}
export default StyleProcessor;
108 changes: 90 additions & 18 deletions dist/js/class/StyleProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
// ============================================================================
// Import
// ============================================================================
// import * as sass from 'sass';
// import postcss from 'postcss';
// import fs from 'fs';
// import { promises as fsPromises } from 'fs';
// import path from 'path';
var sass = __importStar(require("sass"));
var postcss_1 = __importDefault(require("postcss"));
var fs_1 = __importDefault(require("fs"));
var fs_2 = require("fs");
var fs_1 = require("fs");
var path_1 = __importDefault(require("path"));
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.
Expand All @@ -63,19 +63,26 @@ class StyleProcessor {
*/
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 } });
const result = await (0, postcss_1.default)(config.plugins).process(css, { from: undefined, map: { inline: false } });
return result.css;
}
/**
* Ensures that the given directory exists. Creates it if it does not exist.
* @param dirPath - The path of the directory to check and create.
*/
async ensureDirectoryExists(dirPath) {
try {
await fs_2.promises.mkdir(dirPath, { recursive: true });
await fs_1.promises.mkdir(dirPath, { recursive: true });
}
catch (error) {
if (error.code !== 'EEXIST') {
throw error;
if (error instanceof Error) {
const nodeError = error;
if (nodeError.code !== 'EEXIST') {
throw nodeError; // Rethrow if it's not a 'directory exists' error
}
}
else {
throw error; // Rethrow if it's not an Error instance
}
}
}
Expand All @@ -92,21 +99,86 @@ class StyleProcessor {
await this.ensureDirectoryExists(outputDir);
// 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);
// Process the compiled CSS with PostCSS
const processedCss = 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());
}
await fs_1.promises.writeFile(outputFile, processedCss, 'utf-8');
// Optionally handle source maps
// ...
}
catch (err) {
// Handle errors in the compilation or processing
console.error(`Error processing styles from ${inputFile}:`, err);
throw err; // Re-throw the error for further handling if necessary
}
}
}
// /**
// * 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: string,
// styleOption: 'expanded' | 'compressed'
// ) {
// const config = styleOption === 'expanded' ? postcssConfigExpanded : postcssConfigCompressed;
// return postcss(config.plugins).process(css, { from: undefined, map: { inline: false } });
// }
// /**
// * Ensures that the given directory exists. Creates it if it does not exist.
// * @param dirPath - The path of the directory to check and create.
// */
// private async ensureDirectoryExists(dirPath: string): Promise<void> {
// try {
// await fsPromises.mkdir(dirPath, { recursive: true });
// } catch (error) {
// if (error.code !== 'EEXIST') {
// throw error;
// }
// }
// }
// /**
// * 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: string,
// outputFile: fs.PathOrFileDescriptor,
// styleOption: 'expanded' | 'compressed'
// ) {
// try {
// // Ensure the output directory exists
// const outputDir = path.dirname(outputFile as string);
// await this.ensureDirectoryExists(outputDir);
// // 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.writeFileSync(outputFile, processed.css);
// // Write the source map file
// if (processed.map) {
// fs.writeFileSync(`${outputFile}.map`, processed.map.toString());
// }
// } catch (err) {
// // Handle errors in the compilation or processing
// console.error(`Error processing styles from ${inputFile}:`, err);
// }
// }
// }
// ============================================================================
// Export
// ============================================================================
Expand Down
1 change: 1 addition & 0 deletions dist/js/config/package.config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ declare const packageConfig: {
type: string;
url: string;
}[];
type: string;
main: string;
types: string;
files: string[];
Expand Down
4 changes: 2 additions & 2 deletions dist/js/config/package.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const packageConfig = {
"url": "https://github.com/sponsors/scape-foundation"
}
],
// type: "module",
type: "module",
main: "js/index",
// main: "js/index.js",
types: "js/index",
Expand Down Expand Up @@ -56,7 +56,7 @@ const packageConfig = {
"svg/**/*.svg",
"tex/**/*.tex",
"ts/**/*.ts",
"!.DS_Store",
"!.DS_Store"
]
};
// ============================================================================
Expand Down
9 changes: 5 additions & 4 deletions dist/js/config/ts.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ const tsConfig = {
// ES2022 = 9,
// ESNext = 99,
// JSON = 100,
// Latest = 99,
// Latest = 99,\
lib: ["es2015", "dom"],
// target: "es2015", // Set the JavaScript language version for emitted JavaScript and include compatible library declarations.
// lib: ["esnext", "es2017", "ES2015", "dom"], // Specify a set of bundled library declaration files that describe the target runtime environment.
lib: ["es2015", "dom"], // Specify library files to be included in the compilation
// lib: ["es2015"] // Specify library files to be included in the compilation
// lib: ["esnext", "es2017`", "ES2015", "dom"], // Specify a set of bundled library declaration files that describe the target runtime environment.
// lib: ["es2015", "dom"], // Specify library files to be included in the compilation
// lib: ["es2015"], // Specify library files to be included in the compilation
// jsx: "preserve", // Specify what JSX code is generated.
// experimentalDecorators: true, // Enable experimental support for TC39 stage 2 draft decorators.
// emitDecoratorMetadata: true, // Emit design-type metadata for decorated declarations in source files.
Expand Down
1 change: 0 additions & 1 deletion dist/js/pack.gl.min.js

This file was deleted.

Loading

0 comments on commit 0af7ae4

Please sign in to comment.