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.7.5 to 1.7.6

9

CHANGELOG.md

@@ -8,6 +8,13 @@ # Change Log

## [1.7.6] - 2024-05-17
### Changed
- `SsgContext.setOutputFrom(filename)` instead of `SsgContext.setOutputFrom(filename)` to unify apis.
### Fixed
- make sure context `inputFile` and `outputFile` are assigned.
## [1.7.5] - 2024-05-15
### Changed
- `SsgContext.read(filename)` becomes `SsgContext.getInputFrom(filename)` to denote it affects the context's `inputFile`.

@@ -14,0 +21,0 @@ - `SsgContext.readOrNew(filename, dir)` becomes `SsgContext.setOutputFrom(filename)` to denote it affects the context's `outputFile`.

4

dist/src/SsgContext.d.ts

@@ -48,5 +48,5 @@ import { Logger } from "./Logger.js";

*
* By default (if the file is not found), output contents are equal to input contents.
* By default, (if the file is not found), output contents are equal to input contents.
*/
setOutputFrom(filePath: string): SsgFile;
getOutputFrom(filePath: string): SsgFile;
}

@@ -0,1 +1,2 @@

/// <reference types="node" />
import { SsgContext } from "./SsgContext.js";

@@ -46,2 +47,3 @@ import { Logger } from "./Logger.js";

* @param fileName The name of the file.
* @returns {SsgFile}
* @protected

@@ -51,3 +53,4 @@ */

getInputFrom(filePath: string): SsgFile;
setOutputFrom(filePath: string): SsgFile;
getOutputFrom(filePath: string): SsgFile;
createOutput(filePath: string, encoding: BufferEncoding): SsgFile;
}

@@ -92,2 +92,3 @@ import { ObjectUtil } from "./util/ObjectUtil.js";

* @param fileName The name of the file.
* @returns {SsgFile}
* @protected

@@ -104,28 +105,12 @@ */

}
setOutputFrom(filePath) {
getOutputFrom(filePath) {
var _a;
const encoding = (_a = this._outputFile) === null || _a === void 0 ? void 0 : _a.encoding;
let outFile;
try {
outFile = this.readFile(filePath);
this.logger.debug("Read output file", outFile.name);
}
catch (e) {
if (e.code === "ENOENT") {
let lang;
try {
lang = SsgFile.getLang(this, filePath);
}
catch (e) {
if (e.errno !== -2) {
throw e;
}
lang = { lang: this.locale, variants: [] };
}
if (filePath.endsWith(".html")) {
const fileInfo = new SsgFile(filePath, encoding || "utf-8", this.inputFile.contents, new Date(), lang);
outFile = HtmlSsgFile.create(fileInfo);
}
else {
outFile = new SsgFile(filePath, "utf8", this.inputFile.contents, new Date(), lang);
}
outFile = this.createOutput(filePath, ((_a = this._outputFile) === null || _a === void 0 ? void 0 : _a.encoding) || "utf-8");
}

@@ -139,4 +124,27 @@ else {

}
createOutput(filePath, encoding) {
let outFile;
let lang;
try {
lang = SsgFile.getLang(this, filePath);
}
catch (e) {
if (e.errno !== -2) {
throw e;
}
lang = { lang: this.locale, variants: [] };
}
const creationDate = new Date();
if (filePath.endsWith(".html")) {
const fileInfo = new SsgFile(filePath, encoding, this.inputFile.contents, creationDate, lang);
outFile = HtmlSsgFile.create(fileInfo);
}
else {
outFile = new SsgFile(filePath, encoding, this.inputFile.contents, creationDate, lang);
}
this.logger.debug("Created new output file", outFile.name);
return outFile;
}
}
SsgContextImpl.CONTEXT_PREFIX = "$context.";
SsgContextImpl.DEFAULT_NAME = "Ssg";

@@ -61,4 +61,4 @@ import fs from "fs";

context.debug("Processing file", filePath);
context.getInputFrom(filePath);
context.setOutputFrom(contentsConfig.getOutputFile(context).name);
context.inputFile = context.getInputFrom(filePath);
context.outputFile = context.getOutputFrom(contentsConfig.getOutputFile(context).name);
const processed = this.shouldProcess(context);

@@ -65,0 +65,0 @@ if (processed) {

@@ -32,5 +32,5 @@ import path from "path";

async execute(context) {
context.getInputFrom(this.templateFileName);
context.inputFile = context.getInputFrom(this.templateFileName);
const outputFilePath = path.join(this.config.outDir, this.templateFileName);
context.setOutputFrom(outputFilePath);
context.outputFile = context.getOutputFrom(outputFilePath);
const dirNames = (await this.findDirs(this.rootDirs))

@@ -37,0 +37,0 @@ .filter(dirName => !this.excludedDirs.includes(dirName));

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

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

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

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