Skip to content
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
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"files.exclude": {
"**/node_modules": true,
// "**/node_modules": true,
// "**/dist": true,
// "**/plugins": true,
}
Expand Down
65 changes: 0 additions & 65 deletions build/build.ts

This file was deleted.

10 changes: 0 additions & 10 deletions build/copy-package.ts

This file was deleted.

73 changes: 0 additions & 73 deletions build/generate-exports.ts

This file was deleted.

9 changes: 0 additions & 9 deletions build/generate-key.ts

This file was deleted.

30 changes: 0 additions & 30 deletions build/gzip-build.ts

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"dependencies": {
"@types/node": "^24.3.1",
"@types/ws": "^8.18.1",
"cac": "^6.7.14",
"chokidar": "^3.6.0",
"cookie": "^1.0.2",
"edge.js": "^6.3.0",
Expand Down
15 changes: 15 additions & 0 deletions packages/cli/builder/config-generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { readFileSync } from "fs";

function extractStaticServePath(filePath: string): string {
const content = readFileSync(filePath, "utf8");

// Cari pattern: staticServe({ path: "..." })
const match = content.match(/staticServe\s*\(\s*\{\s*path\s*:\s*["'`](.*?)["'`]/);

if (match && match[1]) {
return match[1]; // nilai path ditemukan
}

// Kalau gak ketemu, return default
return "/public";
}
42 changes: 42 additions & 0 deletions packages/cli/builder/gzip-build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { createBrotliCompress, createGzip } from 'node:zlib';
import { pipeline } from 'node:stream/promises';
import fs from 'fs';
import { glob } from 'glob';
import path from 'node:path';
import { GamanConfig } from '@gaman/core';

const compressFile = async (inputPath: string) => {
const gzipPath = `${inputPath}.gz`;
const brPath = `${inputPath}.br`;

await Promise.all([
pipeline(
fs.createReadStream(inputPath),
createGzip(),
fs.createWriteStream(gzipPath),
),
pipeline(
fs.createReadStream(inputPath),
createBrotliCompress(),
fs.createWriteStream(brPath),
),
]);
};

const exts = ['.js', '.mjs', '.css', '.html', '.json', '.svg', '.xml', '.txt'];

/**
* @ID Compress semua file yang ada di folder dist/client seperti .js jadi .js.br atau .gzip
* @param config
*/
export const compressDistFiles = async (config: GamanConfig) => {
const files = glob.sync(`./${config.build?.outdir || 'dist'}/client/**/*.*`, {
ignore: ['**/*.gz', '**/*.br'],
});
for (const file of files) {
if (exts.includes(path.extname(file))) {
await compressFile(file);
console.log(`Compressed: ${file}`);
}
}
};
28 changes: 28 additions & 0 deletions packages/cli/builder/helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import fs, { existsSync } from 'fs';
import path from 'path';

export const isDevelopment = (outdir: string) => {
return existsSync(path.join(outdir, '.development'));
};

/**
* ini akan membuat file `.development` di folder /dist atau folder tujuan build jadinya
* file ini menandakan bahwa build an tersebut itu di mode development
*/
export const createDevelopmentFile = (outdir: string) => {
fs.mkdirSync(outdir, { recursive: true });
const filePath = path.join(outdir, '.development');
const content = `# GamanJS Development Mode\nCreated at: ${new Date().toISOString()}\n`;
fs.writeFileSync(filePath, content, 'utf-8');
};

/**
* Ini akan membuat file `.production` di folder /dist atau folder tujuan build jadi nya
* file ini menandakan bahwa build an tersebut itu di mode production
*/
export const createProductionFile = (outdir: string) => {
fs.mkdirSync(outdir, { recursive: true });
const filePath = path.join(outdir, '.production');
const content = `# GamanJS Production Mode\nCreated at: ${new Date().toISOString()}\n`;
fs.writeFileSync(filePath, content, 'utf-8');
};
Loading