Comparing version 1.5.1 to 1.5.2
@@ -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 @@ |
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": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
137962
3
146
2445
- Removedcpy@^10.1.0
- Removed@nodelib/fs.scandir@2.1.5(transitive)
- Removed@nodelib/fs.stat@2.0.5(transitive)
- Removed@nodelib/fs.walk@1.2.8(transitive)
- Removedaggregate-error@4.0.1(transitive)
- Removedarrify@3.0.0(transitive)
- Removedbraces@3.0.3(transitive)
- Removedclean-stack@4.2.0(transitive)
- Removedcp-file@10.0.0(transitive)
- Removedcpy@10.1.0(transitive)
- Removeddir-glob@3.0.1(transitive)
- Removedescape-string-regexp@5.0.0(transitive)
- Removedfast-glob@3.3.2(transitive)
- Removedfastq@1.17.1(transitive)
- Removedfill-range@7.1.1(transitive)
- Removedglob-parent@5.1.2(transitive)
- Removedglobby@13.2.2(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedignore@5.3.2(transitive)
- Removedindent-string@5.0.0(transitive)
- Removedis-extglob@2.1.1(transitive)
- Removedis-glob@4.0.3(transitive)
- Removedis-number@7.0.0(transitive)
- Removedjunk@4.0.1(transitive)
- Removedmerge2@1.4.1(transitive)
- Removedmicromatch@4.0.8(transitive)
- Removednested-error-stacks@2.1.1(transitive)
- Removedp-event@5.0.1(transitive)
- Removedp-filter@3.0.0(transitive)
- Removedp-map@5.5.06.0.0(transitive)
- Removedp-timeout@5.1.0(transitive)
- Removedpath-type@4.0.0(transitive)
- Removedpicomatch@2.3.1(transitive)
- Removedqueue-microtask@1.2.3(transitive)
- Removedreusify@1.0.4(transitive)
- Removedrun-parallel@1.2.0(transitive)
- Removedslash@4.0.0(transitive)
- Removedto-regex-range@5.0.1(transitive)