Skip to content

Commit

Permalink
v0.0.18
Browse files Browse the repository at this point in the history
  • Loading branch information
vanvianen committed Jan 3, 2024
1 parent eaf006a commit fe0b2ae
Show file tree
Hide file tree
Showing 16 changed files with 177 additions and 36 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.16
0.0.18
15 changes: 12 additions & 3 deletions dist/js/class/TemplateWriter.d.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
declare class TemplateWriter {
context: {};
/**
* Configuration for the Nunjucks writer compiler.
*/
private config;
/**
* Default configuration for the TypeScript compiler.
*/
private static defaultConfig;
/**
* Constructs a TemplateWriter instance.
* @param templatesDir - Directory for Nunjucks templates.
* @param enableCache - Enable or disable caching for Nunjucks.
*/
constructor(templatesDir: string, enableCache?: boolean);
constructor(templatesDir: string, context: {}, customConfig?: any);
/**
* Generates a template using the provided template file and context.
* @param template - The template file name.
* @param context - Context data to render the template with.
* @returns The rendered template as a string.
*/
generateTemplate(template: string, context: {}): Promise<string>;
generateTemplate(template: string): Promise<string>;
/**
* Writes the rendered template content to a file.
* @param template - The template file name.
* @param outputFile - The output file path.
* @param context - Context data to render the template with.
*/
generateToFile(template: string, outputFile: string, context: {}): Promise<void>;
generateToFile(template: string, outputFile: string): Promise<void>;
}
export default TemplateWriter;
27 changes: 18 additions & 9 deletions dist/js/class/TemplateWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,41 @@ Object.defineProperty(exports, "__esModule", { value: true });
var promises_1 = __importDefault(require("fs/promises"));
var path_1 = __importDefault(require("path"));
var nunjucks_1 = __importDefault(require("nunjucks"));
var nunjucks_config_js_1 = __importDefault(require("../config/nunjucks.config.js"));
// ============================================================================
// Classes
// ============================================================================
class TemplateWriter {
/**
* Default configuration for the TypeScript compiler.
*/
static { this.defaultConfig = nunjucks_config_js_1.default; }
/**
* Constructs a TemplateWriter instance.
* @param templatesDir - Directory for Nunjucks templates.
* @param enableCache - Enable or disable caching for Nunjucks.
*/
constructor(templatesDir, enableCache = false) {
nunjucks_1.default.configure(templatesDir, {
autoescape: true,
noCache: !enableCache
});
constructor(templatesDir, context,
// enableCache: boolean = false,
customConfig = {}) {
this.context = context;
this.config = {
...TemplateWriter.defaultConfig,
...customConfig
};
nunjucks_1.default.configure(templatesDir, this.config);
}
/**
* Generates a template using the provided template file and context.
* @param template - The template file name.
* @param context - Context data to render the template with.
* @returns The rendered template as a string.
*/
async generateTemplate(template, context) {
async generateTemplate(template) {
try {
// const formattedColors = this.formatColorsForTemplate();
// return nunjucks.render(template, { colors: formattedColors });
return nunjucks_1.default.render(template, context);
return nunjucks_1.default.render(template, this.context);
}
catch (error) {
console.error(`Error generating template: ${error}`);
Expand All @@ -59,9 +68,9 @@ class TemplateWriter {
* @param outputFile - The output file path.
* @param context - Context data to render the template with.
*/
async generateToFile(template, outputFile, context) {
async generateToFile(template, outputFile) {
try {
const content = await this.generateTemplate(template, context);
const content = await this.generateTemplate(template);
const dir = path_1.default.dirname(outputFile);
// Ensure the directory exists
await promises_1.default.mkdir(dir, { recursive: true });
Expand Down
8 changes: 8 additions & 0 deletions dist/js/config/nunjucks.config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare const nunjucksConfig: {
autoescape: boolean;
throwOnUndefined: boolean;
trimBlocks: boolean;
lstripBlocks: boolean;
noCache: boolean;
};
export default nunjucksConfig;
17 changes: 17 additions & 0 deletions dist/js/config/nunjucks.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";
// config/nunjucks.config.ts
Object.defineProperty(exports, "__esModule", { value: true });
// ============================================================================
// Constants
// ============================================================================
const nunjucksConfig = {
autoescape: true, // Controls if output with dangerous characters are escaped automatically
throwOnUndefined: false, // Throw errors when outputting a null/undefined value
trimBlocks: true, // Automatically remove trailing newlines from a block/tag
lstripBlocks: true, // Automatically remove leading whitespace from a block/tag
noCache: true
};
// ============================================================================
// Export
// ============================================================================
exports.default = nunjucksConfig;
6 changes: 6 additions & 0 deletions dist/js/function/clean_directory.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Cleans a specified directory and logs the process.
* @param directoryPath - The path of the directory to clean.
*/
declare function cleanDirectory(directoryPath: string): Promise<void>;
export default cleanDirectory;
31 changes: 31 additions & 0 deletions dist/js/function/clean_directory.js
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var DirectoryCleaner_js_1 = __importDefault(require("../class/DirectoryCleaner.js"));
var StylizedLogger_js_1 = __importDefault(require("../class/StylizedLogger.js"));
const directoryCleaner = new DirectoryCleaner_js_1.default();
const logger = new StylizedLogger_js_1.default();
/**
* Cleans a specified directory and logs the process.
* @param directoryPath - The path of the directory to clean.
*/
async function cleanDirectory(directoryPath) {
try {
logger.header('Clean Directories');
await directoryCleaner.cleanDirectory(directoryPath);
logger.body(`Directory cleaned: ${directoryPath}`);
}
catch (error) {
logger.error(`Error cleaning directory: ${error}`);
throw error; // Rethrow the error for further handling if necessary
}
}
// ============================================================================
// Export
// ============================================================================
exports.default = cleanDirectory;
// Usage example
// cleanAndLogDirectory(CONFIG.path.dist)
// .then(() => console.log('Directory cleaning completed.'))
// .catch(error => console.error(error));
3 changes: 2 additions & 1 deletion dist/js/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use strict";
// script/index.ts
// index.ts
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Expand Down Expand Up @@ -52,6 +52,7 @@ var StylizedLogger_js_1 = __importDefault(require("./class/StylizedLogger.js"));
exports.StylizedLogger = StylizedLogger_js_1.default;
var TemplateWriter_js_1 = __importDefault(require("./class/TemplateWriter.js"));
exports.TemplateWriter = TemplateWriter_js_1.default;
// Import | Internal Functions
var gl_installer_1 = __importDefault(require("./function/gl_installer"));
exports.gl_installer = gl_installer_1.default;
var clean_directory_1 = __importDefault(require("./function/clean_directory"));
Expand Down
2 changes: 1 addition & 1 deletion dist/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pack.gl",
"version": "0.0.16",
"version": "0.0.18",
"description": "Package Builder.",
"keywords": [
"pack.gl",
Expand Down
45 changes: 36 additions & 9 deletions dist/ts/class/TemplateWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import fs from 'fs/promises';
import path from 'path';
import nunjucks from 'nunjucks';
import nunjucksConfig from "../config/nunjucks.config.js"


// ============================================================================
Expand All @@ -30,19 +31,45 @@ import nunjucks from 'nunjucks';

class TemplateWriter {

context: {};


/**
* Configuration for the Nunjucks writer compiler.
*/
private config: {};

/**
* Default configuration for the TypeScript compiler.
*/
private static defaultConfig: any = nunjucksConfig;

/**
* Constructs a TemplateWriter instance.
* @param templatesDir - Directory for Nunjucks templates.
* @param enableCache - Enable or disable caching for Nunjucks.
*/
constructor(
templatesDir: string,
enableCache: boolean = false
context: {},

// enableCache: boolean = false,
customConfig: any = {},

) {
nunjucks.configure(templatesDir, {
autoescape: true,
noCache: !enableCache
});
this.context = context;
this.config = {
...TemplateWriter.defaultConfig,
...customConfig
};
nunjucks.configure(
templatesDir,
this.config,
// {
// autoescape: true,
// // noCache: !enableCache
// }
);
}

/**
Expand All @@ -51,13 +78,13 @@ class TemplateWriter {
* @param context - Context data to render the template with.
* @returns The rendered template as a string.
*/
async generateTemplate(template: string, context: {}): Promise<string> {
async generateTemplate(template: string): Promise<string> {
try {
// const formattedColors = this.formatColorsForTemplate();
// return nunjucks.render(template, { colors: formattedColors });
return nunjucks.render(
template,
context,
this.context,
);
} catch (error) {
console.error(`Error generating template: ${error}`);
Expand All @@ -73,9 +100,9 @@ class TemplateWriter {
* @param outputFile - The output file path.
* @param context - Context data to render the template with.
*/
async generateToFile(template: string, outputFile: string, context: {}): Promise<void> {
async generateToFile(template: string, outputFile: string): Promise<void> {
try {
const content = await this.generateTemplate(template, context);
const content = await this.generateTemplate(template);
const dir = path.dirname(outputFile);

// Ensure the directory exists
Expand Down
2 changes: 1 addition & 1 deletion dist/ts/config/nunjucks.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const nunjucksConfig = {
throwOnUndefined: false, // Throw errors when outputting a null/undefined value
trimBlocks: true, // Automatically remove trailing newlines from a block/tag
lstripBlocks: true, // Automatically remove leading whitespace from a block/tag
// noCache: !enableCache
noCache: true,

};

Expand Down
33 changes: 33 additions & 0 deletions dist/ts/function/clean_directory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import DirectoryCleaner from '../class/DirectoryCleaner.js';
import StylizedLogger from '../class/StylizedLogger.js';
import CONFIG from '../path/to/config.js'; // Assuming CONFIG is imported from a config file

const directoryCleaner = new DirectoryCleaner();
const logger = new StylizedLogger();

/**
* Cleans a specified directory and logs the process.
* @param directoryPath - The path of the directory to clean.
*/
async function cleanDirectory(directoryPath: string): Promise<void> {
try {
logger.header('Clean Directories');
await directoryCleaner.cleanDirectory(directoryPath);
logger.body(`Directory cleaned: ${directoryPath}`);
} catch (error) {
logger.error(`Error cleaning directory: ${error}`);
throw error; // Rethrow the error for further handling if necessary
}
}

// ============================================================================
// Export
// ============================================================================

export default cleanDirectory;


// Usage example
// cleanAndLogDirectory(CONFIG.path.dist)
// .then(() => console.log('Directory cleaning completed.'))
// .catch(error => console.error(error));
8 changes: 4 additions & 4 deletions dist/ts/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// script/index.ts
// index.ts

// Copyright 2023 Scape Agency BV

Expand All @@ -19,7 +19,6 @@
// Import
// ============================================================================


// Import | Utility Classes
import DirectoryCleaner from './class/DirectoryCleaner';
import DirectoryCopier from './class/DirectoryCopier';
Expand All @@ -40,12 +39,11 @@ import NpmCommandRunner from './class/NpmCommandRunner.js';
import StylizedLogger from './class/StylizedLogger.js';
import TemplateWriter from './class/TemplateWriter.js';


// Import | Internal Functions
import gl_installer from './function/gl_installer';
import cleanDirectory from './function/clean_directory';



// ============================================================================
// Export
// ============================================================================
Expand All @@ -72,6 +70,8 @@ export {
StylizedLogger,
TemplateWriter,

// Export | Internal Functions
gl_installer,
cleanDirectory,

};
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "pack.gl",
"description": "Package Builder.",
"version": "0.0.17",
"version": "0.0.18",
"config": {
"version_short": "0.0"
},
Expand Down
Loading

0 comments on commit fe0b2ae

Please sign in to comment.