Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first successful tar.gz file with some tests #1

Merged
merged 3 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 178 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
"commander": "^6.1.0",
"dotenv": "^16.3.1",
"semver": "^7.5.4",
"tar": "^6.2.0",
"tslib": "^2.6.2"
},
"devDependencies": {
"@types/node": "^14.11.8",
"@types/jest": "^29.5.8",
"@types/semver": "^7.5.0",
"@types/tar": "^6.1.9",
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"typescript": "^5.2.2"
Expand Down
76 changes: 74 additions & 2 deletions src/build-webon/build-webon.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,79 @@
import { checkDir, logFatal } from "../util/util";
import { joinDirWithFileName, logFatal } from "../util/util";
import { existsSync, mkdirSync, readdirSync, renameSync } from "fs";
import { join, resolve } from "path";
import tar from "tar";

export async function buildWebOn(args: { assetDir: string }) {
checkDir(args.assetDir);

logFatal("buildWebOn not implemented: " + JSON.stringify(args));
// Check if the assetDir path ends with '/out'
const isOutDir = args.assetDir.endsWith("/out");
const outDir = resolve(args.assetDir);
const outDirPath = resolve(args.assetDir, "..", "out");
console.log("outDir: " + outDir.toString());

if (!isOutDir) {
console.log("outDirPath: " + outDirPath.toString());

try {
// Rename the assetDir to include '/out'
renameSync(args.assetDir, outDirPath);
console.log("Renaming asset directory to 'out'...");
} catch (error) {
console.error(`Error renaming directory: ${error}`);
return;
}
} else {
console.log("Directories are already named correctly, no need to rename.");
}

// Create the "out" directory if it doesn't exist in the root path
if (!existsSync(outDir)) {
console.log("Creating 'out' directory...");
mkdirSync(outDir);
}
// Check if the "out" directory contains required files
const requiredFiles = [
"index.html",
"nomo_icon.svg",
"nomo_manifest.json",
].map((file) => {
return join(outDirPath, file);
});
const missingFiles = requiredFiles.filter((file) => !existsSync(file));

if (missingFiles.length > 0) {
console.error(
`Error: The 'out' directory is missing the following required files: ${missingFiles.join(
", "
)}`
);
return; // or handle the error as needed
}

// Create a tar.gz file
const tarFileName = "nomo.tar.gz";
const tarFilePath = joinDirWithFileName(outDir, tarFileName);
console.log(`Creating tar.gz file: ${getDebugPath(tarFilePath)}`);

// Use the tar.create method to properly await the completion
await tar.create(
{
file: tarFilePath,
gzip: true,
},
[outDir]
);

console.log("Build and packaging completed!");
}

function checkDir(dir: string): void {
if (!existsSync(dir)) {
logFatal(`${getDebugPath(dir)} does not exist.`);
}
}

function getDebugPath(path: string): string {
return `\'${resolve(path)}\'`; // Show an absolute path to users in case of errors.
}
6 changes: 4 additions & 2 deletions src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ export function getDebugPath(path: string): string {
return `\'${resolve(path)}\'`; // Show an absolute path to users in case of errors.
}

export function logFatal(msg: string): never {
export function logFatal(msg: string): void {
console.error(`error: ${msg}`);
return process.exit(1) as never;
// Do not exit immediately for testing purposes
}

export function deleteFile(path: string): void {
Expand All @@ -59,4 +59,6 @@ export function nodeVersionSatisfies(feature: string, range: string): void {
if (!semver.satisfies(process.version, range)) {
logFatal(`${feature} requires node ${range}`);
}

}

Loading
Loading