Skip to content
Open
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
29 changes: 29 additions & 0 deletions CHANGELOG.md
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.
30 changes: 30 additions & 0 deletions README.md
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
Binary file modified icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions main.js
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>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Plugin source never wired into the build pipeline

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.mjs compiles src/main.js (still the empty class scaffold) into dist/main.js. plugin.json references "main": "dist/main.js", and pack-zip.js packages dist/main.js. So when anyone runs npm run build, the output dist/main.js will contain the empty template — not this plugin — and the packaged plugin.zip will silently ship broken code. The plugin logic here (main.js) also never gets included in the zip. The implementation needs to live in src/main.js so esbuild can bundle it into dist/main.js.

Copy link
Copy Markdown
Author

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 addedFolder accessed outside the try/catch block

let a=addedFolder[0] is evaluated before the try block. While Acode normally exposes addedFolder as a global array (making it safe to index), the subsequent if(!a) check and folder-open guard are only useful when addedFolder exists. If a future Acode version changes this global's shape or it is evaluated in a test context where the global is absent, the TypeError would propagate uncaught past the error handler. Moving the line inside the try block costs nothing and makes the error path consistent.

<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);})();
88 changes: 24 additions & 64 deletions pack-zip.js
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 ESM import in a CommonJS file will throw a SyntaxError

pack-zip.js uses import statements and top-level await, which are ESM-only features. Because package.json has no "type": "module", Node.js treats every .js file as CommonJS, and running node ./pack-zip.js (as esbuild.config.mjs does via exec) will immediately fail with SyntaxError: Cannot use import statement in a module. The fix is either to rename the file to pack-zip.mjs, or add "type": "module" to package.json (which would require updating all CommonJS require() calls elsewhere).


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.");
Loading