Socket
Socket
Sign inDemoInstall

ssg-api

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ssg-api - npm Package Compare versions

Comparing version 1.5.1 to 1.5.2

dist/src/testAll.d.ts

6

CHANGELOG.md

@@ -8,2 +8,8 @@ # Change Log

## [1.5.2] - 2023-11-02
### Fixed
`FileUtil.ssgCopy()` removed `cpy` dependency which has a bug causing output dir not always applied.
## [1.5.1] - 2023-10-21

@@ -10,0 +16,0 @@

4

dist/src/step/CopyStep.d.ts
import { SsgStep } from './SsgStep';
import { SsgConfig } from '../Ssg';
import { SsgContext } from '../SsgContext';
import { IOptions } from 'glob';
export type CopyStepResult = {

@@ -13,5 +14,6 @@ files: string[];

protected config: SsgConfig;
protected options?: IOptions | undefined;
readonly name = "copy";
constructor(copies: string[], config: SsgConfig);
constructor(copies: string[], config: SsgConfig, options?: IOptions | undefined);
execute(context: SsgContext): Promise<CopyStepResult>;
}

@@ -7,5 +7,6 @@ import { FileUtil } from '../util';

export class CopyStep {
constructor(copies, config) {
constructor(copies, config, options) {
this.copies = copies;
this.config = config;
this.options = options;
this.name = 'copy';

@@ -18,3 +19,3 @@ }

context.log('Copying to', dest, copies);
const copiedFiles = await FileUtil.ssgCopy(dest, copies);
const copiedFiles = await FileUtil.ssgCopy(dest, copies, this.options);
const cwd = process.cwd();

@@ -21,0 +22,0 @@ const files = copiedFiles.map(file => file.startsWith(cwd) ? file.substring(cwd.length + 1) : file);

import { CopyStep } from './CopyStep';
import { SsgContextImpl } from '../SsgContextImpl';
import { describe, expect, test } from '@javarome/testscript';
describe("CopyStep", () => {
test("copy", async () => {
const config = { outDir: "out/" };
const copies = ['test/test.html', '**/*.bpmn'];
const step = new CopyStep(copies, config);
const context = new SsgContextImpl("fr");
import path from 'path';
describe('CopyStep', () => {
test('copy', async () => {
const config = { outDir: 'out/' };
const copies = ['**/test.html', '**/*.bpmn'];
const step = new CopyStep(copies, config, { ignore: 'out/**' });
const context = new SsgContextImpl('fr');
const result = await step.execute(context);
expect(result).toEqual({ files: ['out/test/test.html', 'test/dir/example.bpmn'] });
expect(result).toEqual({ files: [path.join(config.outDir, 'test/test.html'), path.join(config.outDir, 'test/dir/example.bpmn')] });
});
});
/// <reference types="node" />
import { Options } from 'cpy';
import { IOptions } from 'glob';
export declare class FileUtil {

@@ -7,7 +7,22 @@ static toBufferEncoding(encoding: string | undefined): BufferEncoding | undefined;

static getCharSet(html: HTMLElement): BufferEncoding | undefined;
static ensureDirectoryExistence(filePath: string): true | undefined;
/**
* Checks if a directory exists and, if not, creates it.
*
* @param dir The path of the directory that must exist.
*/
static ensureDirectoryExistence(dir: string): string;
static writeFile(fileName: string, contents: string, encoding: BufferEncoding): Promise<void>;
static dirNames(dir: string): Promise<string[]>;
static ssgCopy(to: string, from: string[], options?: Options): Promise<string[]>;
/**
* Copy files to a destination directory.
*
* @param toDir the destination directory path.
* @param sourcePatterns An array of file nmes.
* @param options
* @return the list of output files.
*/
static ssgCopy(toDir: string, sourcePatterns: string[], options?: IOptions): Promise<string[]>;
static copyFiles(sourceFiles: string[], toDir: string): string[];
static copyFile(sourceFile: string, toDir: string): string;
static getContentType(html: HTMLElement): BufferEncoding | undefined;
}

@@ -6,3 +6,3 @@ import * as fs from 'fs';

import { readdir } from 'fs/promises';
import cpy from 'cpy';
import { promise as glob } from 'glob-promise';
export class FileUtil {

@@ -47,9 +47,14 @@ static toBufferEncoding(encoding) {

}
static ensureDirectoryExistence(filePath) {
const dirname = path.dirname(filePath);
if (fs.existsSync(dirname)) {
return true;
/**
* Checks if a directory exists and, if not, creates it.
*
* @param dir The path of the directory that must exist.
*/
static ensureDirectoryExistence(dir) {
const dirname = path.dirname(dir);
if (!fs.existsSync(dirname)) {
this.ensureDirectoryExistence(dirname); // Recursive to create the whole directories chain.
fs.mkdirSync(dirname);
}
this.ensureDirectoryExistence(dirname);
fs.mkdirSync(dirname);
return path.resolve(dir);
}

@@ -65,5 +70,34 @@ static async writeFile(fileName, contents, encoding) {

}
static async ssgCopy(to, from, options) {
return cpy(from, to, options);
/**
* Copy files to a destination directory.
*
* @param toDir the destination directory path.
* @param sourcePatterns An array of file nmes.
* @param options
* @return the list of output files.
*/
static async ssgCopy(toDir, sourcePatterns, options) {
let result = [];
for (const sourcePattern of sourcePatterns) {
const sourceFiles = await glob(sourcePattern, options);
const copied = this.copyFiles(sourceFiles, toDir);
result = result.concat(copied);
}
return result;
}
static copyFiles(sourceFiles, toDir) {
const result = [];
for (const sourceFile of sourceFiles) {
const to = this.copyFile(sourceFile, toDir);
result.push(to);
}
return result;
}
static copyFile(sourceFile, toDir) {
const from = path.resolve(sourceFile);
const to = path.join(toDir, sourceFile);
this.ensureDirectoryExistence(to);
fs.copyFileSync(from, to);
return to;
}
static getContentType(html) {

@@ -70,0 +104,0 @@ let contentType;

@@ -5,3 +5,3 @@ {

"author": "Jérôme Beau <javarome@gmail.com> (https://javarome.com)",
"version": "1.5.1",
"version": "1.5.2",
"description": "Static Site Generation TypeScript API",

@@ -23,8 +23,7 @@ "exports": "./dist/src/index.js",

"prepublishOnly": "npm run build && npm test",
"test": "rm -Rf out && tsx src/test.ts",
"test-one": "rm -Rf out && tsx src/step/DirectoryStepTest.ts",
"test-ci": "rm -Rf out && NODE_OPTIONS=--experimental-vm-modules jest --coverage --runInBand"
"test": "rm -Rf out && tsx src/testAll.ts",
"test-one": "rm -Rf out && tsx src/step/CopyStepTest.ts",
"test-ci": "rm -Rf out && tsx src/testAll.ts"
},
"dependencies": {
"cpy": "^10.1.0",
"detect-character-encoding": "^0.8.0",

@@ -40,3 +39,3 @@ "glob-promise": "^6.0.5",

"tsx": "3.14.0",
"@javarome/testscript": "^0.4.1"
"@javarome/testscript": "^0.6.1"
},

@@ -43,0 +42,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc