Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
garag-lib committed Jun 8, 2024
1 parent b679d74 commit 87d6985
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

**/aot

package-lock.json

# Diagnostic reports (https://nodejs.org/api/report.html)
Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
"version": "1.1.1",
"repository": "https://github.com/garag-lib/GTPL",
"description": "GTPL is a TypeScript library designed for creating reactive template systems with a unique approach that incorporates Direct DOM and Proxy. Inspired by technologies like Vue.js, angular aot or jsx, GTPL offers an efficient and powerful way to build reactive applications with optimized performance and all of this in a compact 9 KB javascript package.",
"main": "gtpl.js",
"scripts": {
"build": "npx tsc",
"bundle_dev": "webpack --mode development",
"bundle": "webpack --mode production",
"bundle_dev_www": "webpack --mode development --config webpack.config.js",
"bundle_www": "webpack --mode production --config webpack.config.js",
"bundle_dev_node": "webpack --mode development --config webpack.node.config.js",
"bundle_node": "webpack --mode production --config webpack.node.config.js",
"server": "php -S localhost:8080"
},
"author": "Manuel Peliz",
"license": "LGPL-2.1 license",
"devDependencies": {
"fs": "^0.0.1-security",
"path": "^0.12.7",
"ts-loader": "^9.4.4",
"typescript": "^4.9.5",
"uglify-js": "^3.17.4",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4"
}
}
}
76 changes: 76 additions & 0 deletions scripts/compile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const fs = require('fs').promises;
const path = require('path');
const { parse } = require('node-html-parser');
const gtpl = require('../dist/lib/gtpl.min.js');

// Tu función de compilación AOT (ajusta esta función según tus necesidades)
async function compileToAOT(htmlContent) {
// Implementa tu lógica de compilación aquí
// Esto es solo un ejemplo
const root = parse(htmlContent);
console.log(root);
let code = '';
if (root.childNodes.length == 1) {
code = await gtpl.jit.GCode(root.childNodes[0]);
} else {
code = await gtpl.jit.GCode(root.childNodes);
}
return 'export default ' + code;
}

// Función para compilar archivos de una carpeta a otra
async function compileHtmlFiles(sourceDir, destDir) {
try {
const files = await fs.readdir(sourceDir);
for (const file of files) {
const ext = path.extname(file);
if (ext === '.html') {
const sourceFilePath = path.join(sourceDir, file);
const destFilePath = path.join(destDir, path.basename(file, ext) + '.js');
try {
const data = await fs.readFile(sourceFilePath, 'utf8');
const compiledContent = await compileToAOT(data);
await fs.writeFile(destFilePath, compiledContent, 'utf8');
console.log(`Archivo compilado exitosamente: ${destFilePath}`);
} catch (readWriteError) {
console.error(`Error procesando el archivo ${sourceFilePath}:`, readWriteError);
}
}
}
} catch (err) {
console.error('Error leyendo la carpeta de origen:', err);
}
}

// Función principal
async function main() {
const args = process.argv.slice(2);
if (args.length < 2) {
console.error('Uso: node compile.js <carpeta-origen> <carpeta-destino>');
process.exit(1);
}
const sourceDir = args[0];
const destDir = args[1];
// Verifica si la carpeta de origen existe
try {
await fs.access(sourceDir);
} catch {
console.error(`La carpeta de origen "${sourceDir}" no existe.`);
process.exit(1);
}
// Crea la carpeta de destino si no existe
try {
await fs.mkdir(destDir, { recursive: true });
} catch (mkdirError) {
console.error(`Error creando la carpeta de destino "${destDir}":`, mkdirError);
process.exit(1);
}
// Compila los archivos HTML
await compileHtmlFiles(sourceDir, destDir);
}

// Ejecuta la función principal
main().catch(err => {
console.error('Error en la ejecución principal:', err);
process.exit(1);
});
2 changes: 1 addition & 1 deletion src/GProxy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TypeEventProxyHandler } from 'GEnums';
import { TypeEventProxyHandler } from './GEnums';
import { isStaticType } from './GUtils';

export type PathProxyHandler = any;
Expand Down
4 changes: 4 additions & 0 deletions tests/tpl/one.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<ul>
<li>{{ 'hello world' }}</li>
<li>{{ alert('ok'); }}</li>
</ul>
2 changes: 1 addition & 1 deletion tsconfig-webpack.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
/* Type Checking */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
"strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
Expand Down
14 changes: 7 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
/* Modules */
"rootDir": "./src", /* Specify the root folder within your source files. */
//"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
/*
"baseUrl": "./src",
"paths": {
Expand All @@ -41,7 +41,7 @@
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
// "resolveJsonModule": true, /* Enable importing .json files. */
"resolveJsonModule": true, /* Enable importing .json files. */
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
/* JavaScript Support */
"allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
Expand All @@ -52,8 +52,8 @@
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
"sourceMap": true, /* Create source map files for emitted JavaScript files. */
"module": "AMD", /* ESNext Specify what module code is generated. */
"outFile": "./dist/gtpl.js", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
"module": "CommonJS", /* ESNext Specify what module code is generated. */
//"outFile": "./dist/gtpl.js", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
"outDir": "./dist", /* Specify an output folder for all emitted files. */
"removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
Expand All @@ -74,14 +74,14 @@
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
"preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
/* Type Checking */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
"strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
Expand Down
50 changes: 50 additions & 0 deletions webpack.node.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const path = require('path');
const webpack = require('webpack');
const fs = require('fs');
const packageJsonContent = fs.readFileSync('./package.json', 'utf8');
const packageJson = JSON.parse(packageJsonContent);

module.exports = {
target: 'node',
devtool: 'source-map',
entry: './src/lib/gtpl.ts',
module: {
rules: [
{
test: /\.ts$/,
use: {
loader: 'ts-loader',
options: {
configFile: path.resolve(__dirname, 'tsconfig.json')
}
},
exclude: /node_modules/
}
]
},
output: {
filename: 'gtpl.min.js',
path: path.resolve(__dirname, 'dist') + '/lib',
globalObject: 'this',
library: {
name: 'gtpl',
type: 'umd',
export: 'default'
}
},
resolve: {
extensions: ['.ts', '.js']
},
plugins: [
new webpack.BannerPlugin({
banner: `/**
* ${packageJson.name} v${packageJson.version}
* (c) 2024 ${packageJson.author}
* @license ${packageJson.license}
* @repository ${packageJson.repository}
**/`,
raw: true,
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT
})
]
};

0 comments on commit 87d6985

Please sign in to comment.