Skip to content

Commit

Permalink
Merge pull request #875 from acacode/fix-build-warnings-2
Browse files Browse the repository at this point in the history
Fix build warnings
  • Loading branch information
smorimoto authored Aug 11, 2024
2 parents 7b7e4f2 + 062ac1e commit 210f22b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
34 changes: 21 additions & 13 deletions src/templates-worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { resolve } from "node:path";
import * as path from "node:path";
import * as url from "node:url";
import * as Eta from "eta";
Expand Down Expand Up @@ -36,14 +35,21 @@ class TemplatesWorker {
*/
getTemplatePaths = (config) => {
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
const baseTemplatesPath = resolve(__dirname, "../templates/base");
const defaultTemplatesPath = resolve(__dirname, "../templates/default");
const modularTemplatesPath = resolve(__dirname, "../templates/modular");
const baseTemplatesPath = path.resolve(__dirname, "../templates/base");
const defaultTemplatesPath = path.resolve(
__dirname,
"../templates/default",
);
const modularTemplatesPath = path.resolve(
__dirname,
"../templates/modular",
);
const originalTemplatesPath = config.modular
? modularTemplatesPath
: defaultTemplatesPath;
const customTemplatesPath =
(config.templates && resolve(process.cwd(), config.templates)) || null;
(config.templates && path.resolve(process.cwd(), config.templates)) ||
null;

return {
/** `templates/base` */
Expand All @@ -65,8 +71,8 @@ class TemplatesWorker {
path,
);

getTemplateFullPath = (path, fileName) => {
const raw = resolve(path, "./", this.cropExtension(fileName));
getTemplateFullPath = (path_, fileName) => {
const raw = path.resolve(path_, "./", this.cropExtension(fileName));
const pathVariants = this.config.templateExtensions.map(
(extension) => `${raw}${extension}`,
);
Expand Down Expand Up @@ -171,13 +177,13 @@ class TemplatesWorker {
return pathVariants.find((variant) => this.fileSystem.pathIsExist(variant));
};

getTemplateContent = (path) => {
getTemplateContent = (path_) => {
const foundTemplatePathKey = lodash
.keys(this.config.templatePaths)
.find((key) => path.startsWith(`@${key}`));
.find((key) => path_.startsWith(`@${key}`));

const rawPath = resolve(
path.replace(
const rawPath = path.resolve(
path_.replace(
`@${foundTemplatePathKey}`,
this.config.templatePaths[foundTemplatePathKey],
),
Expand All @@ -190,14 +196,16 @@ class TemplatesWorker {

const customPath =
this.config.templatePaths.custom &&
this.findTemplateWithExt(resolve(this.config.templatePaths.custom, path));
this.findTemplateWithExt(
path.resolve(this.config.templatePaths.custom, path_),
);

if (customPath) {
return this.fileSystem.getFileContent(customPath);
}

const originalPath = this.findTemplateWithExt(
resolve(this.config.templatePaths.original, path),
path.resolve(this.config.templatePaths.original, path_),
);

if (originalPath) {
Expand Down
8 changes: 4 additions & 4 deletions src/util/file-system.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from "node:fs";
import { dirname, resolve } from "node:path";
import * as path from "node:path";
import * as url from "node:url";
import * as lodash from "lodash";
import { Logger } from "./logger.js";
Expand Down Expand Up @@ -83,9 +83,9 @@ class FileSystem {
return !!path && fs.existsSync(path);
};

createFile = ({ path, fileName, content, withPrefix }) => {
const __dirname = dirname(url.fileURLToPath(import.meta.url));
const absolutePath = resolve(__dirname, path, `./${fileName}`);
createFile = ({ path: path_, fileName, content, withPrefix }) => {
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
const absolutePath = path.resolve(__dirname, path_, `./${fileName}`);
const fileContent = `${withPrefix ? FILE_PREFIX : ""}${content}`;

return fs.writeFileSync(absolutePath, fileContent, lodash.noop);
Expand Down

0 comments on commit 210f22b

Please sign in to comment.