Skip to content

Commit

Permalink
v0.0.21
Browse files Browse the repository at this point in the history
  • Loading branch information
vanvianen committed Jan 3, 2024
1 parent 84156c0 commit a3ce4a5
Show file tree
Hide file tree
Showing 47 changed files with 1,011 additions and 151 deletions.
22 changes: 17 additions & 5 deletions dist/js/class/PackageCreator.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
import { PackageJson } from '../interface/PackageJson.js';
/**
* A class for creating a package.json file for a project.
*/
declare class PackageCreator {
private packageJson;
/**
* Configuration for the Package.json.
*/
config: any;
/**
* Default configuration for Package.json.
*/
private static defaultConfig;
/**
* Initializes a new instance of the PackageCreator class.
* @param {PackageJson} packageJson - The content to be written into package.json.
* @param {PackageJson} customConfig - The content to be written into package.json.
*/
constructor(packageJson: PackageJson);
constructor(customConfig?: any);
/**
* Creates a package.json file in the specified directory.
* @param {string} outputDir - The directory where package.json will be created.
* Creates the directory if it does not exist.
* @param outputDir - The directory where package.json will be created.
*/
createPackageJson(outputDir: string): Promise<void>;
/**
* 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 ensureDirectoryExists;
}
export default PackageCreator;
62 changes: 54 additions & 8 deletions dist/js/class/PackageCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,77 @@ Object.defineProperty(exports, "__esModule", { value: true });
// ============================================================================
// Import
// ============================================================================
var fs_1 = __importDefault(require("fs"));
var promises_1 = __importDefault(require("fs/promises"));
var path_1 = __importDefault(require("path"));
var package_config_js_1 = __importDefault(require("../config/package.config.js"));
// ============================================================================
// Classes
// ============================================================================
/**
* A class for creating a package.json file for a project.
*/
class PackageCreator {
// private config: ts.CompilerOptions;
// private config: { [key: symbol]: any};
/**
* Default configuration for Package.json.
*/
static { this.defaultConfig = package_config_js_1.default; }
/**
* Initializes a new instance of the PackageCreator class.
* @param {PackageJson} packageJson - The content to be written into package.json.
* @param {PackageJson} customConfig - The content to be written into package.json.
*/
constructor(packageJson) {
this.packageJson = packageJson;
constructor(customConfig = {}) {
let newConfig = {
// Populate with necessary fields from packageData
name: customConfig.name,
version: customConfig.version,
description: customConfig.description,
keywords: customConfig.keywords,
license: customConfig.license,
homepage: customConfig.homepage,
// main: 'index.js',
dependencies: customConfig.dependencies
};
this.config = {
...PackageCreator.defaultConfig,
...newConfig
};
}
/**
* Creates a package.json file in the specified directory.
* @param {string} outputDir - The directory where package.json will be created.
* Creates the directory if it does not exist.
* @param 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}`);
const data = JSON.stringify(this.config, null, 2);
try {
// Ensure the output directory exists
await this.ensureDirectoryExists(outputDir);
// Write the package.json file
await promises_1.default.writeFile(filePath, data, 'utf-8');
console.log(`package.json created at ${filePath}`);
}
catch (error) {
console.error(`Error creating package.json: ${error}`);
throw error;
}
}
/**
* 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 promises_1.default.mkdir(dirPath, { recursive: true });
}
catch (error) {
// Check if error is an instance of NodeJS.ErrnoException
if (error instanceof Error && error.code !== 'EEXIST') {
throw error; // Rethrow if it's not a 'directory exists' error
}
}
}
}
// ============================================================================
Expand Down
12 changes: 12 additions & 0 deletions dist/js/config/package.config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
declare const packageConfig: {
name: string;
version: string;
description: string;
keywords: string;
license: string;
homepage: string;
main: string;
types: string;
files: string[];
};
export default packageConfig;
43 changes: 43 additions & 0 deletions dist/js/config/package.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"use strict";
// config/package.config.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.
// ============================================================================
// Constants
// ============================================================================
const packageConfig = {
name: "",
version: "",
description: "",
keywords: "",
license: "Apache-2.0",
homepage: "https://www.scape.agency",
main: "js/index",
types: "js/index",
// main: "js/index.js",
// types: "js/index.d.ts",
// main: 'index.js',
files: [
"svg/**/*.svg",
"js/**/*.d.ts",
"js/**/*.{js,map}",
"ts/**/*.ts",
"css/**/*.{css,map}",
"scss/**/*.scss",
"font/**/*.{eot,otf,ttf,woff,woff2}",
"!.DS_Store"
]
};
// ============================================================================
// Export
// ============================================================================
exports.default = packageConfig;
21 changes: 20 additions & 1 deletion dist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,24 @@
"scss/**/*.scss",
"font/**/*.{eot,otf,ttf,woff,woff2}",
"!.DS_Store"
]
],
"dependencies": {
"@types/fs-extra": "^11.0.4",
"@types/glob": "^8.1.0",
"@types/nunjucks": "^3.2.6",
"@types/svg-sprite": "^0.0.38",
"autoprefixer": "^10.4.15",
"del": "^7.1.0",
"fantasticon": "^2.0.0",
"fs-extra": "^11.2.0",
"glob": "^10.3.10",
"jsdom": "^23.0.1",
"lodash": "^4.17.21",
"nunjucks": "^3.2.4",
"sass": "^1.69.7",
"sharp": "^0.33.1",
"svg-sprite": "^2.0.2",
"svgo": "^3.1.0",
"terser": "^5.26.0"
}
}
99 changes: 83 additions & 16 deletions dist/ts/class/PackageCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
// Import
// ============================================================================

import fs from 'fs';
import fs from 'fs/promises';
import path from 'path';
// import * as pack from '../../package.json' assert { type: 'json' };
import { PackageJson } from '../interface/PackageJson.js'
import { PackageJson } from '../interface/PackageJson.js';
import packageConfig from "../config/package.config.js"

// ============================================================================
// Classes
Expand All @@ -34,33 +34,100 @@ import { PackageJson } from '../interface/PackageJson.js'
class PackageCreator {


private packageJson: PackageJson;

/**
* Configuration for the Package.json.
*/
public config: any;
// private config: ts.CompilerOptions;
// private config: { [key: symbol]: any};

/**
* Default configuration for Package.json.
*/
private static defaultConfig: any = packageConfig;

/**
* Initializes a new instance of the PackageCreator class.
* @param {PackageJson} packageJson - The content to be written into package.json.
* @param {PackageJson} customConfig - The content to be written into package.json.
*/
constructor(packageJson: PackageJson) {
this.packageJson = packageJson;
}

constructor(
customConfig: any = {},
// customConfig: any = {},
// customConfig: ts.CompilerOptions = {},
) {
let newConfig = {
// Populate with necessary fields from packageData
name: customConfig.name,
version: customConfig.version,
description: customConfig.description,
keywords: customConfig.keywords,
license: customConfig.license,
homepage: customConfig.homepage,
// main: 'index.js',
dependencies: customConfig.dependencies,
// files: [
// "svg/**/*.{svg}",
// "js/**/*.{js,map}",
// "ts/**/*.ts",
// "css/**/*.{css,map}",
// "scss/**/*.{scss}",
// "font/**/*.{eot,otf,ttf,woff,woff2}",
// "!.DS_Store"
// ],
}

this.config = {
...PackageCreator.defaultConfig,
...newConfig
};
}




/**
* Creates a package.json file in the specified directory.
* @param {string} outputDir - The directory where package.json will be created.
* Creates the directory if it does not exist.
* @param outputDir - The directory where package.json will be created.
*/
async createPackageJson(outputDir: string): Promise<void> {
async createPackageJson(outputDir: string): Promise<void> {
const filePath = path.join(outputDir, 'package.json');
const data = JSON.stringify(this.packageJson, null, 2);

fs.writeFileSync(filePath, data, 'utf-8');
console.log(`package.json created at ${filePath}`);
const data = JSON.stringify(this.config, null, 2);

try {
// Ensure the output directory exists
await this.ensureDirectoryExists(outputDir);

// Write the package.json file
await fs.writeFile(filePath, data, 'utf-8');
console.log(`package.json created at ${filePath}`);
} catch (error) {
console.error(`Error creating package.json: ${error}`);
throw error;
}
}

/**
* 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 fs.mkdir(dirPath, { recursive: true });
} catch (error) {
// Check if error is an instance of NodeJS.ErrnoException
if (error instanceof Error && (error as NodeJS.ErrnoException).code !== 'EEXIST') {
throw error; // Rethrow if it's not a 'directory exists' error
}
}
}

}


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

export default PackageCreator;
export default PackageCreator;
2 changes: 1 addition & 1 deletion dist/ts/class/SvgSpriteGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import svgspriteConfig from "../config/svgsprite.config.js"
* A class for generating SVG sprites from individual SVG files.
*/
class SvgSpriteGenerator {


/**
* Constructs an instance of SvgSpriteGenerator with the provided configuration.
Expand Down
31 changes: 16 additions & 15 deletions dist/ts/config/package.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@


// ============================================================================
// Import
// Constants
// ============================================================================

import * as pack_object from '../../../package.json' assert { type: 'json' };

const pack = JSON.parse(JSON.stringify(pack_object)).default; // req.body = [Object: null prototype] { title: 'product' }


const packageConfig = {
name: pack.name,
version: pack.version,
description: pack.description,
keywords: pack.keywords,
license: pack.license,
homepage: pack.homepage,
main: 'index.js',
name: "",
version: "",
description: "",
keywords: "",
license: "Apache-2.0",
homepage: "https://www.scape.agency",
main: "js/index",
types: "js/index",
// main: "js/index.js",
// types: "js/index.d.ts",
// main: 'index.js',
files: [
"svg/**/*.{svg}",
"svg/**/*.svg",
"js/**/*.d.ts",
"js/**/*.{js,map}",
"ts/**/*.ts",
"css/**/*.{css,map}",
"scss/**/*.{scss}",
"scss/**/*.scss",
"font/**/*.{eot,otf,ttf,woff,woff2}",
"!.DS_Store"
],
Expand Down Expand Up @@ -74,3 +74,4 @@ const packageConfig = {
// ============================================================================

export default packageConfig;

Loading

0 comments on commit a3ce4a5

Please sign in to comment.