diff --git a/.gitignore b/.gitignore index 13fa826..586610d 100644 --- a/.gitignore +++ b/.gitignore @@ -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) diff --git a/package.json b/package.json index 77b538f..3aa8ee2 100755 --- a/package.json +++ b/package.json @@ -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" } -} +} \ No newline at end of file diff --git a/scripts/compile.js b/scripts/compile.js new file mode 100644 index 0000000..3370480 --- /dev/null +++ b/scripts/compile.js @@ -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 '); + 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); +}); diff --git a/src/GProxy.ts b/src/GProxy.ts index 5f5410c..f19400b 100755 --- a/src/GProxy.ts +++ b/src/GProxy.ts @@ -1,4 +1,4 @@ -import { TypeEventProxyHandler } from 'GEnums'; +import { TypeEventProxyHandler } from './GEnums'; import { isStaticType } from './GUtils'; export type PathProxyHandler = any; diff --git a/tests/tpl/one.html b/tests/tpl/one.html new file mode 100644 index 0000000..a3d51c7 --- /dev/null +++ b/tests/tpl/one.html @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/tsconfig-webpack.json b/tsconfig-webpack.json index 3a1e6e4..245e8cb 100755 --- a/tsconfig-webpack.json +++ b/tsconfig-webpack.json @@ -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. */ diff --git a/tsconfig.json b/tsconfig.json index 6416688..0b5dcc6 100755 --- a/tsconfig.json +++ b/tsconfig.json @@ -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": { @@ -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 ''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. */ @@ -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. */ @@ -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. */ diff --git a/webpack.node.config.js b/webpack.node.config.js new file mode 100644 index 0000000..9706152 --- /dev/null +++ b/webpack.node.config.js @@ -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 + }) + ] +}; \ No newline at end of file