Skip to content

Commit 31aba23

Browse files
refactor: Add environment files for navigation templates and implement utility functions for command checks, online status, and directory write permissions; update build process and remove unused files
1 parent e5377ba commit 31aba23

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+741
-171
lines changed

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ jobs:
1616
- name: Set up Node.js
1717
uses: actions/setup-node@v2
1818
with:
19-
node-version: "16" # Specify the Node.js version you want to use
19+
node-version: "18" # Specify the Node.js version you want to use
2020
registry-url: "https://registry.npmjs.org"
2121

2222
- name: Install dependencies
2323
run: npm ci
2424

2525
- name: Build
26-
run: npm run release
26+
run: npm run build
2727

2828
- name: Publish to NPM
2929
run: npm publish

esbuild.config.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import fs from "fs";
2+
import path from "path";
3+
import { build } from "esbuild";
4+
import { fileURLToPath } from "url";
5+
import { nodeExternalsPlugin } from "esbuild-node-externals";
6+
7+
// Function to copy the templates folder recursively
8+
function copyFiles(src, dest) {
9+
const entries = fs.readdirSync(src, { withFileTypes: true });
10+
11+
fs.mkdirSync(dest, { recursive: true });
12+
13+
for (let entry of entries) {
14+
const srcPath = path.join(src, entry.name);
15+
const destPath = path.join(dest, entry.name);
16+
17+
entry.isDirectory()
18+
? copyFiles(srcPath, destPath)
19+
: fs.copyFileSync(srcPath, destPath);
20+
}
21+
}
22+
23+
// Get the directory name in ES modules
24+
const __filename = fileURLToPath(import.meta.url);
25+
const __dirname = path.dirname(__filename);
26+
27+
const templateSource = path.resolve(__dirname, "templates");
28+
const templateDest = path.resolve(__dirname, "dist", "templates");
29+
30+
const scriptSource = path.resolve(__dirname, "scripts");
31+
const scriptDist = path.resolve(__dirname, "dist", "scripts");
32+
33+
build({
34+
entryPoints: ["./index.ts"],
35+
bundle: true,
36+
outfile: "dist/index.js",
37+
platform: "node",
38+
format: "esm",
39+
plugins: [nodeExternalsPlugin()],
40+
})
41+
.then(() => {
42+
copyFiles(templateSource, templateDest);
43+
copyFiles(scriptSource, scriptDist);
44+
console.log("Templates copied successfully.");
45+
})
46+
.catch((error) => {
47+
console.error("Error: ", error);
48+
process.exit(1);
49+
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable import/no-extraneous-dependencies */
2-
import { async as glob } from "fast-glob";
2+
import glob from "fast-glob";
33
import { resolve, dirname, basename, join } from "node:path";
44
import { copyFile, mkdir, writeFile } from "node:fs/promises";
55

@@ -41,7 +41,7 @@ export const copyFiles = async (
4141
throw new TypeError("`src` and `dest` are required");
4242
}
4343

44-
const sourceFiles = await glob(source, {
44+
const sourceFiles = await glob.glob(source, {
4545
cwd,
4646
dot: true,
4747
absolute: false,

helpers/get-scripts.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import path from "path";
2+
import { fileURLToPath } from "url";
3+
4+
// Function to get the path to script files
5+
function getScriptPath(scriptFileName: string): string {
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
8+
return path.join(__dirname, "scripts", scriptFileName);
9+
}
10+
11+
export default getScriptPath;
File renamed without changes.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable import/no-extraneous-dependencies */
22
import { lstatSync, readdirSync } from "node:fs";
33
import { join } from "node:path";
4-
import { green, blue } from "picocolors";
4+
import colors from "picocolors";
55

66
/**
77
* Checks if a folder is empty, considering a predefined list of valid files.
@@ -70,14 +70,14 @@ export default function isFolderEmpty(root: string, name: string): boolean {
7070

7171
if (conflicts.length > 0) {
7272
console.log(
73-
`The directory ${green(name)} contains files that could conflict:`
73+
`The directory ${colors.green(name)} contains files that could conflict:`
7474
);
7575
console.log();
7676
for (const file of conflicts) {
7777
try {
7878
const stats = lstatSync(join(root, file));
7979
if (stats.isDirectory()) {
80-
console.log(` ${blue(file)}/`);
80+
console.log(` ${colors.blue(file)}/`);
8181
} else {
8282
console.log(` ${file}`);
8383
}

0 commit comments

Comments
 (0)