diff --git a/.github/workflows/HtmlCI.yml b/.github/workflows/HtmlCI.yml new file mode 100644 index 0000000..5e9b9e4 --- /dev/null +++ b/.github/workflows/HtmlCI.yml @@ -0,0 +1,22 @@ +name: HtmlCI +on: [push, pull_request] +jobs: + build: + runs-on: ubuntu-latest + if: ${{ !contains(github.event.head_commit.message, '[ci skip]') }} + steps: + - uses: actions/checkout@v4 + - name: Html-CreadorCraft-Maker + uses: ./ + with: + path: './test' + pathGame: "./Test.html" + - name: CreadorCraft-Maker + uses: Creadores-Program/CreadorCraft-Maker-GHA@v1.1.0 + with: + path: "./test" + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: My Game + path: gameBuildCCM/TestName 1.0.0.creadorcraftgame.zip diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index b943c35..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,12 +0,0 @@ -name: NodejsCI -on: [push, pull_request] -jobs: - build: - runs-on: ubuntu-latest - if: ${{ !contains(github.event.head_commit.message, '[ci skip]') }} - steps: - - uses: actions/checkout@v4 - - name: CreadorCraft-Maker - uses: ./ - with: - path: './test' diff --git a/README.md b/README.md index e36e895..51aef92 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# CreadorCraft-Maker-GHA +# Html to CreadorCraft Maker GHA ![Github](https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white) ![Github Actions](https://img.shields.io/badge/Github%20Actions-282a2e?style=for-the-badge&logo=githubactions&logoColor=367cfe) @@ -7,13 +7,20 @@ ![JavaScript](https://img.shields.io/badge/JavaScript-323330?style=for-the-badge&logo=javascript&logoColor=F7DF1E) ![Json](https://img.shields.io/badge/json-5E5C5C?style=for-the-badge&logo=json&logoColor=white) -Github Action to package your CreatorCraft game! - -You can now package your CreatorCraft game on Github! +Github Action to transpile your Html5 game to CreatorCraft game on Github! If you want to know how to create a game in CreadorCraft I recommend you check out the [CreadorCraft Maker wiki](https://creadorcraft-maker.blogspot.com/p/documentacionwiki.html) you can also run many programming languages for your game! ## Example Work +You need a Html5 game file .html +### Action options +- path: destination of the game files CreatorCraft (the game's manifest.json should be there when creating) required +- pathGame: Html5 game directory if it is in your Github repo +- pathCustomJs: additional JavaScript file directory for the Html5 game (must be in a different directory than where the CraftCreator game will be generated, same for the css) +- pathCustomCSS: additional css to the Html5 game + +### Example of task: + ```yml name: CI @@ -25,6 +32,12 @@ jobs: if: ${{ !contains(github.event.head_commit.message, '[ci skip]') }} steps: - uses: actions/checkout@v4 + - name: Scratch-CreadorCraft-Maker + uses: Creadores-Program/Html-to-CreadorCraft-Maker-GHA@v1.0.0 + with: + path: "./src" # Destinity CreadorCraft Game (this not genere manifest.json) + pathGame: "./Game.html" + # Pack.. - name: CreadorCraft-Maker uses: Creadores-Program/CreadorCraft-Maker-GHA@v1.1.0 with: @@ -37,7 +50,10 @@ jobs: ``` ### Structure Repo: -myName/RepoGameName/src +myName/RepoGameName/ +- Game.html + +- src - manifest.json: ```json @@ -45,16 +61,13 @@ myName/RepoGameName/src "name": "TestName", "description": "Test game", "version": "1.0.0", - "mainHtml": "index.html",//dir main html file + "mainHtml": "index.html", "mainCSS": "index.css", - "mainJS": "index.js" + "mainJS": "main.js" } ``` - - index.html - - index.css - - index.js -more info in Wiki! +[CreadorCraft Maker Action](https://github.com/marketplace/actions/creadorcraft-maker) Made in Mexico. diff --git a/Test.html b/Test.html new file mode 100644 index 0000000..ebe0ebd --- /dev/null +++ b/Test.html @@ -0,0 +1,12 @@ + + +

Hola Mundo!

+ + + diff --git a/action.yml b/action.yml index 5448652..1eb8b14 100644 --- a/action.yml +++ b/action.yml @@ -1,10 +1,19 @@ -name: "CreadorCraft-Maker" +name: "Html-CreadorCraft-Maker" author: "Creadores Program" -description: "Github Action to package your CreadorCraft game!" +description: "Github Action to package your Html5 game to CreatorCraft game!" inputs: path: - description: "directory where the game to be packaged is" + description: "destination directory for the generated game" required: true + pathGame: + description: "Html game directory" + required: true + pathCustomJs: + description: "Custom js for Game" + required: false + pathCustomCSS: + description: "Custom css for Game" + required: false runs: using: "node20" main: "index.js" diff --git a/game.html b/game.html new file mode 100644 index 0000000..55cee24 --- /dev/null +++ b/game.html @@ -0,0 +1,363 @@ + + + + + + + + + Geometry Dash v1.5 + + + + + +
+ + + +
+ + + +
+
+ + + + + + + + + + + + diff --git a/index.js b/index.js index 89a4540..45a572a 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ -const prefix = "[CreadorCraft Maker] "; -console.info(prefix+"CreadorCraft Maker Action by Creadores Program ©2024"); +const prefix = "[Html CreadorCraft Maker] "; +console.info(prefix+"Html CreadorCraft Maker Action by Creadores Program ©2024"); console.info(prefix+"Loading Libraries..."); try{ const { execSync } = require("child_process"); @@ -7,97 +7,43 @@ try{ execSync("npm install", { stdio: "inherit", cwd: rute }); var core = require('@actions/core'); var github = require('@actions/github'); - var archiver = require('archiver'); + var cheerio = require('cheerio'); var fs = require("fs"); }catch(error){ console.error(error.stack || error.message); core.setFailed(error.stack || error.message); } -//error Messages -const errorMessages = { - inManifest: "\nError in manifest.json", - inFileNotFound: function(file){ - return "\nError "+file+" Not Found"; - } -}; console.info(prefix+"Done!"); console.info(prefix+"Creating CreatorCraft Game..."); -var dirGame = core.getInput("path"); +var dirGameDes = core.getInput("path"); +var dirGame = core.getInput("pathGame"); try{ - var manifestCCG = {}; - fs.readFile(dirGame+"/manifest.json", 'utf8', (err, data) => { - if(err){ - throw err; - } - manifestCCG = JSON.parse(data); - if(manifestCCG.name == null || manifestCCG.name.trim() == ""){ - throw new Error(prefix+"You need a name for the game!"+errorMessages.inManifest); - } - if(manifestCCG.version == null || manifestCCG.version.trim() == ""){ - throw new Error(prefix+"You need a version for the game!"+errorMessages.inManifest); - } - if(manifestCCG.description == null){ - throw new Error(prefix+"You need a description for the game!"+errorMessages.inManifest); - } - if(((manifestCCG.description.trim().toLowerCase().indexOf(" { - console.info(prefix+"Game "+manifestCCG.name+" "+manifestCCG.version+".creadorcraftgame.zip Build Correctly in "+outPath); - }); - - archive.on('error', (err) => { - console.error(prefix+"Game "+manifestCCG.name+" "+manifestCCG.version+".creadorcraftgame.zip Build Fail"); - throw err; - }); - - archive.pipe(output); - archive.directory(sourceDir, false); - - archive.finalize(); -} - - const sourceDir = dirGame; - if(!fs.existsSync("./gameBuildCCM")){ - fs.mkdirSync("./gameBuildCCM"); + function convertCCG(htms){ + console.info(prefix+"Convert Html to Game by CreatorCraft..."); + let $ = cheerio.load(htms); + let jsFileCache = ""; + $("script").each(function(){ + jsFileCache += $(this).html() + "\n"; + $(this).remove(); + }); + if(core.getInput("pathCustomJs") != null && core.getInput("pathCustomJs").trim() != ""){ + jsFileCache += fs.readFileSync(core.getInput("pathCustomJs")); + } + let cssFileCache = ""; + $("style").each(function(){ + cssFileCache += $(this).html() + "\n"; + $(this).remove(); + }); + if(core.getInput("pathCustomCSS") != null && core.getInput("pathCustomCSS").trim() != ""){ + cssFileCache += fs.readFileSync(core.getInput("pathCustomCSS")); + } + fs.writeFileSync(dirGameDes+"/main.js", jsFileCache); + fs.writeFileSync(dirGameDes+"/index.css", cssFileCache); + fs.writeFileSync(dirGameDes+"/index.html", $.html()); + console.info(prefix+"Done!"); + console.info(prefix+"Saved Your project in "+dirGameDes+"/*"); } - const outPath = "./gameBuildCCM/"+manifestCCG.name+" "+manifestCCG.version+".creadorcraftgame.zip"; - - zipDirectory(sourceDir, outPath); - }); + convertCCG(fs.readFileSync(dirGame)); }catch(error){ console.error(error.message); core.setFailed(error.message); diff --git a/package.json b/package.json index cce9769..30948a8 100644 --- a/package.json +++ b/package.json @@ -1,28 +1,29 @@ { - "name": "CreadorCraft-Maker", - "version": "1.1.0", - "description": "Github Action to package your CreatorCraft game!", + "name": "Html-CreadorCraft-Maker", + "version": "1.0.0", + "description": "Github Action to package your Html5 game to CreatorCraft game!", "main": "index.js", "repository": { "type": "git", - "url": "git+https://github.com/Creadores-Program/CreadorCraft-Maker-GHA.git" + "url": "git+https://github.com/Creadores-Program/Html-to-CreadorCraft-Maker-GHA.git" }, "keywords": [ "github", "action", "node", - "CreadorCraft" + "CreadorCraft", + "Html" ], "author": "Creadores Program", "license": "MIT", "bugs": { - "url": "https://github.com/Creadores-Program/CreadorCraft-Maker-GHA/issues" + "url": "https://github.com/Creadores-Program/Html-to-CreadorCraft-Maker-GHA/issues" }, "homepage": "https://creadorcraft-maker.blogspot.com/", "dependencies": { "@actions/core": "^1.10.1", "@actions/github": "^6.0.0", - "archiver": "^7.0.1" + "cheerio": "^1.0.0" } } diff --git a/test/index.css b/test/index.css deleted file mode 100644 index 3a7f54a..0000000 --- a/test/index.css +++ /dev/null @@ -1 +0,0 @@ -/* code... */ diff --git a/test/index.html b/test/index.html deleted file mode 100644 index b76bb48..0000000 --- a/test/index.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/test/index.js b/test/index.js deleted file mode 100644 index 381099d..0000000 --- a/test/index.js +++ /dev/null @@ -1 +0,0 @@ -// code... diff --git a/test/manifest.json b/test/manifest.json index 16c2a36..dcb47df 100644 --- a/test/manifest.json +++ b/test/manifest.json @@ -1,8 +1,8 @@ -{ - "name":"CreadorCraft Game", - "version":"1.0.0", - "description":"Un juego fantasma 👻", - "mainHtml":"index.html", - "mainCSS":"index.css", - "mainJS":"index.js" -} +{ + "name": "TestName", + "description": "Test Game Scratch", + "version": "1.0.0", + "mainHtml": "index.html", + "mainJS": "main.js", + "mainCSS": "index.css" +} \ No newline at end of file