-
Notifications
You must be signed in to change notification settings - Fork 136
Add Templates plugin #67
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Changelog | ||
|
|
||
| Toutes les modifications importantes de ce projet seront documentées dans ce fichier. | ||
|
|
||
| ## [1.0.0] - 2026-07-17 | ||
|
|
||
| ### Added | ||
| - Création automatique de modèles de projets dans Acode. | ||
| - Ajout du template HTML5 : | ||
| - `index.html` | ||
| - `style.css` | ||
| - `script.js` | ||
| - Ajout du template PHP : | ||
| - `index.php` | ||
| - Ajout du template JavaScript : | ||
| - `index.js` | ||
| - Ajout de la commande Acode `Templates`. | ||
| - Ajout d'un menu de sélection pour choisir le type de projet. | ||
| - Intégration avec le système de fichiers Acode (`fsOperation`). | ||
| - Détection automatique du dossier ouvert dans Acode. | ||
|
|
||
| ### Fixed | ||
| - Correction de la récupération du dossier actif avec `addedFolder`. | ||
| - Correction de la création des fichiers dans le dossier sélectionné. | ||
| - Amélioration de la compatibilité avec Acode v1.12.6. | ||
|
|
||
| ### Notes | ||
| - Version initiale du plugin Templates. | ||
| - Créé Hacker2.0. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # Templates | ||
|
|
||
| Templates is an Acode plugin that helps developers quickly create project templates. | ||
|
|
||
| ## Features | ||
|
|
||
| - Create HTML5 projects | ||
| - Create PHP projects | ||
| - Create JavaScript projects | ||
|
|
||
| ## Generated files | ||
|
|
||
| ### HTML5 Template | ||
| - index.html | ||
| - style.css | ||
| - script.js | ||
|
|
||
| ### PHP Template | ||
| - index.php | ||
|
|
||
| ### JavaScript Template | ||
| - index.js | ||
|
|
||
| ## Installation | ||
|
|
||
| Install the plugin from the generated `plugin.zip` file in Acode. | ||
|
|
||
| ## Author | ||
|
|
||
| Hacker2.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| (()=>{var i={$schema:"https://acode.app/schema/plugin/v0.1.0.json",id:"com.degrace.templates",name:"Templates",main:"dist/main.js",version:"1.0.0",icon:"icon.png",minVersionCode:290,license:"MIT",price:0,keywords:["template","html","php","javascript"],author:{name:"Hacker2.0",email:"kiminoudegrace64@gmail.com",github:"Degrace15"},description:"Create HTML, PHP and JavaScript project templates in Acode."};function n(c,d,p){let o=acode.require("commands"),s=acode.require("select"),r=acode.require("fsOperation");o.addCommand({name:"templates",description:"Create project templates",exec:async()=>{let t=await s("Choose a template",[["html","HTML5 Template"],["php","PHP Template"],["js","JavaScript Template"]]);if(!t)return;let a=addedFolder[0];if(!a){acode.alert("Error","Please open a folder in Acode first.");return}try{let e=await r(a.url);t==="html"?(await e.createFile("index.html",`<!DOCTYPE html> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>My Project</title> | ||
| <link rel="stylesheet" href="style.css"> | ||
| </head> | ||
|
|
||
| <body> | ||
|
|
||
| <h1>Hello Acode \u{1F680}</h1> | ||
|
|
||
| <script src="script.js"><\/script> | ||
|
|
||
| </body> | ||
| </html>`),await e.createFile("style.css",`body { | ||
| margin: 0; | ||
| padding: 20px; | ||
| font-family: Arial, sans-serif; | ||
| }`),await e.createFile("script.js",'console.log("JavaScript loaded successfully");')):t==="php"?await e.createFile("index.php",`<?php | ||
|
|
||
| echo "Hello PHP \u{1F680}"; | ||
|
|
||
| ?>`):t==="js"&&await e.createFile("index.js",'console.log("Hello JavaScript \u{1F680}");'),a.reload(),window.toast("Template created successfully \u2705")}catch(e){acode.alert("Error",e.message)}}})}function m(){acode.require("commands").removeCommand("templates")}acode.setPluginInit(i.id,n);acode.setPluginUnmount(i.id,m);})(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,69 +1,29 @@ | ||
| const path = require('path'); | ||
| const fs = require('fs'); | ||
| const jszip = require('jszip'); | ||
|
|
||
| const iconFile = path.join(__dirname, 'icon.png'); | ||
| const pluginJSON = path.join(__dirname, 'plugin.json'); | ||
| const distFolder = path.join(__dirname, 'dist'); | ||
| const json = JSON.parse(fs.readFileSync(pluginJSON, 'utf8')); | ||
| let readmeDotMd; | ||
| let changelogDotMd; | ||
|
|
||
| if (!json.readme) { | ||
| readmeDotMd = path.join(__dirname, 'readme.md'); | ||
| if (!fs.existsSync(readmeDotMd)) { | ||
| readmeDotMd = path.join(__dirname, 'README.md'); | ||
| import fs from "fs"; | ||
| import JSZip from "jszip"; | ||
|
Comment on lines
+1
to
+2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| const zip = new JSZip(); | ||
|
|
||
| const files = [ | ||
| "plugin.json", | ||
| "README.md", | ||
| "CHANGELOG.md", | ||
| "icon.png", | ||
| "dist/main.js" | ||
| ]; | ||
|
|
||
| for (const file of files) { | ||
| if (fs.existsSync(file)) { | ||
| zip.file(file, fs.readFileSync(file)); | ||
| } | ||
| } | ||
|
|
||
| const content = await zip.generateAsync({ | ||
| type: "nodebuffer" | ||
| }); | ||
|
|
||
| if (!json.changelogs) { | ||
| if (!fs.existsSync(changelogDotMd)) { | ||
| changelogDotMd = path.join(__dirname, 'CHANGELOG.md'); | ||
| } | ||
|
|
||
| if (!fs.existsSync(changelogDotMd)) { | ||
| changelogDotMd = path.join(__dirname, 'changelog.md'); | ||
| } | ||
| } | ||
|
|
||
| // create zip file of dist folder | ||
|
|
||
| const zip = new jszip(); | ||
|
|
||
| zip.file('icon.png', fs.readFileSync(iconFile)); | ||
| zip.file('plugin.json', fs.readFileSync(pluginJSON)); | ||
|
|
||
| if (readmeDotMd) { | ||
| zip.file("readme.md", fs.readFileSync(readmeDotMd)); | ||
| } | ||
| if (changelogDotMd) { | ||
| zip.file("changelog.md", fs.readFileSync(changelogDotMd)); | ||
| } | ||
|
|
||
| loadFile('', distFolder); | ||
|
|
||
| zip | ||
| .generateNodeStream({ type: 'nodebuffer', streamFiles: true }) | ||
| .pipe(fs.createWriteStream(path.join(__dirname, 'plugin.zip'))) | ||
| .on('finish', () => { | ||
| console.log('Plugin plugin.zip written.'); | ||
| }); | ||
|
|
||
| function loadFile(root, folder) { | ||
| const distFiles = fs.readdirSync(folder); | ||
| distFiles.forEach((file) => { | ||
|
|
||
| const stat = fs.statSync(path.join(folder, file)); | ||
|
|
||
| if (stat.isDirectory()) { | ||
| zip.folder(file); | ||
| loadFile(path.join(root, file), path.join(folder, file)); | ||
| return; | ||
| } | ||
| fs.writeFileSync( | ||
| "plugin.zip", | ||
| content | ||
| ); | ||
|
|
||
| if (!/LICENSE.txt/.test(file)) { | ||
| zip.file(path.join(root, file), fs.readFileSync(path.join(folder, file))); | ||
| } | ||
| }); | ||
| } | ||
| console.log("plugin.zip created successfully."); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plugin implementation was committed as a pre-built minified bundle at
main.js(repo root), but the build system never picks it up.esbuild.config.mjscompilessrc/main.js(still the empty class scaffold) intodist/main.js.plugin.jsonreferences"main": "dist/main.js", andpack-zip.jspackagesdist/main.js. So when anyone runsnpm run build, the outputdist/main.jswill contain the empty template — not this plugin — and the packagedplugin.zipwill silently ship broken code. The plugin logic here (main.js) also never gets included in the zip. The implementation needs to live insrc/main.jsso esbuild can bundle it intodist/main.js.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The plugin implementation is now correctly located in src/main.js. The build pipeline generates dist/main.js with the plugin code, and npm run build works correctly.