-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Agron Kabashi
committed
Jun 12, 2019
0 parents
commit 09988b6
Showing
35 changed files
with
4,691 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"env": { | ||
"test": { | ||
"presets": ["@babel/preset-env"], | ||
"retainLines": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
extends: [ | ||
"./node_modules/@agronkabashi/eslint-config/config.json" | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
name: Bug report | ||
about: Create a report to help us improve | ||
|
||
--- | ||
|
||
**Describe the bug** | ||
A clear and concise description of what the bug is. | ||
|
||
**Expected behavior** | ||
A clear and concise description of what you expected to happen. | ||
|
||
**To Reproduce** | ||
Steps to reproduce the behavior. | ||
|
||
**Screenshots** | ||
If applicable, add screenshots to help explain your problem. | ||
|
||
**Additional context** | ||
Add any other context about the problem here. | ||
- link to repo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Mocha Tests", | ||
"env": { | ||
"NODE_ENV": "test", | ||
"NODE_PATH": "./src" | ||
}, | ||
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha", | ||
"runtimeArgs": [ | ||
"--nolazy" | ||
], | ||
"internalConsoleOptions": "openOnSessionStart", | ||
"sourceMaps": true | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Changelog | ||
|
||
## Version 0.1.0 | ||
*2019-06-13* | ||
* Initial version. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 Agron Kabashi | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# jspicl CLI | ||
jspicl CLI is a command line tool that simplifies PICO-8 game development in JavaScript. | ||
|
||
Features: | ||
* Comes with its own set of build pipeline so you don't need one. | ||
* JavaScript to PICO-8 Lua transpilation through [jspicl](https://github.com/AgronKabashi/jspicl). | ||
* Treeshaking which prevents unused code from being included and increasing your token count. | ||
* Allows a PNG file to be used as a spritesheet, no need to edit your assets in PICO-8 anymore. Use your image editor of choice. | ||
* Live reloading of PICO-8 cartridge whenever code or spritesheet is updated. See your changes live! | ||
|
||
Future goals: | ||
* Importing of audio files to be used as SFX or music. | ||
|
||
## Installation | ||
|
||
```Shell | ||
npm install jspicl-cli | ||
``` | ||
|
||
Include `-g` option if you want it globally available instead of a local copy. | ||
|
||
## Usage | ||
|
||
To see what options are available simply run the CLI without any options: | ||
```Shell | ||
$ jspicl-cli | ||
Options: | ||
--input Path to entry point [required] | ||
--output Path the generated PICO-8 cardridge [required] | ||
--spritesheetImagePath Path to a spritesheet [required] | ||
--cartridgePath Path to existing cardridge [required] | ||
--includeBanner Include jspicl info in code | ||
--jsOutput Path to JavaScript output | ||
--luaOutput Path to LUA output | ||
--showStats Display build stats | ||
--pipeOutputToConsole Output console.log to terminal | ||
--reloadOnSave Re-run cartridge when updated | ||
--polyfillTransform Path to a module that exports a transformation method | ||
--customPicoPath Path to PICO-8 executable | ||
--prettify Format LUA code | ||
--watch Reload cartridge on rebuilds | ||
``` | ||
|
||
In order to generate a cartridge you need to supply at least four mandatory options: | ||
|
||
```Shell | ||
jspicl-cli | ||
--input <entryfile.js> | ||
--output <outputFile.p8> | ||
--spritesheetImagePath <pathToSpriteSheetFile.png> | ||
--cartridgePath <pathToExistingCartridge.p8> | ||
``` | ||
|
||
## Options | ||
| Name | Type | Description | | ||
|-------------------------|-|-| | ||
| input | string | Your game's entry point. This file can then import other modules. `[required]` | | ||
| output | string | Where to output the PICO-8 cardridge `[required]` | | ||
| spritesheetImagePath | string | Path to a spritesheet file. Only PNGs are supported. `[required]` | | ||
| cartridgePath | string | Path to an existing cardridge to reuse sound, music and state flags from. Normally you would point this to the generated cartridge so that you can save the assets directly and reuse them. `[required]`. | | ||
| includeBanner | boolean | Include a short comment at the very top of the generated LUA code that contains info about [jspicl](https://github.com/AgronKabashi/jspicl). Does not affect token count. | | ||
| jsOutput | string | Where to output the flattened and transpiled JavaScript code. You may use this with [astexplorer](https://astexplorer.net) to inspect the AST, just make sure to select Esprima as the parser. For debugging purposes. | | ||
| luaOutput | string | Where to output the transpiled LUA code. For debugging purposes. | | ||
| showStats | boolean | Display statistics about the generated cartridge. Useful for determining how much resources your game is using. | | ||
| pipeOutputToConsole | boolean | Output all console.log to terminal that launched PICO-8. For debugging purposes. | | ||
| reloadOnSave | boolean | Reload PICO-8 when the cartridge has been updated. | | ||
| customPicoPath | string | Custom path to the PICO-8 executable. | | ||
| prettify | boolean | Format the generated LUA code. | | ||
| watch | | Runs the cartridge in PICO-8 and rebuilds it when the source files change. | | ||
|
||
## Watch mode | ||
|
||
The CLI will listen for changes when the `--watch` option is passed. | ||
|
||
![](https://i.imgur.com/QYj4Xga.gif) | ||
|
||
This applies for the spritesheet aswell. Simply update and save the image to reload to see your changes in PICO-8. | ||
|
||
![](https://github.com/AgronKabashi/assets/raw/814f6efe24bc9aca5d9d6ca6259279733529e300/rollup-plugin-jspicl/spritesheetLiveReload.gif) | ||
|
||
## Other `jspicl` related projects | ||
* [jspicl](https://github.com/AgronKabashi/jspicl) | ||
* [Games](https://github.com/topics/jspicl-sample) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
#!/usr/bin/env node | ||
const buble = require("rollup-plugin-buble"); | ||
const includePaths = require("rollup-plugin-includepaths"); | ||
const path = require("path"); | ||
const yargs = require("yargs"); | ||
const rollup = require("rollup"); | ||
const jspiclPlugin = require("./plugin.js"); | ||
|
||
const options = { | ||
input: { | ||
description: "Path to entry point", | ||
demandOption: true, | ||
requiresArg: true | ||
}, | ||
output: { | ||
description: "Path the generated PICO-8 cardridge", | ||
demandOption: true, | ||
requiresArg: true | ||
}, | ||
spritesheetImagePath: { | ||
description: "Path to a spritesheet", | ||
demandOption: true, | ||
requiresArg: true | ||
}, | ||
cartridgePath: { | ||
demandOption: true, | ||
description: "Path to existing cardridge", | ||
requiresArg: true | ||
}, | ||
|
||
includeBanner: { | ||
description: "Include jspicl info in code", | ||
requiresArg: true | ||
}, | ||
jsOutput: { | ||
description: "Path to JavaScript output" | ||
}, | ||
luaOutput: { | ||
description: "Path to LUA output" | ||
}, | ||
showStats: { | ||
description: "Display build stats", | ||
requiresArg: true | ||
}, | ||
pipeOutputToConsole: { | ||
description: "Output console.log to terminal" | ||
}, | ||
reloadOnSave: { | ||
description: "Re-run cartridge when updated" | ||
}, | ||
|
||
polyfillTransform: { | ||
description: "Path to a module that exports a transformation method", | ||
requiresArg: true | ||
}, | ||
customPicoPath: { | ||
description: "Path to PICO-8 executable", | ||
requiresArg: true | ||
}, | ||
prettify: { | ||
description: "Format LUA code" | ||
}, | ||
watch: { | ||
description: "Reload cartridge on rebuilds" | ||
} | ||
// customMappers: { | ||
// | ||
// requiresArg: true, | ||
// coerce: p => require(path.resolve(p)).default | ||
// } | ||
}; | ||
|
||
const config = yargs | ||
.option(options) | ||
.strict() | ||
.help(false) | ||
.version(false) | ||
.wrap(null) | ||
.argv; | ||
|
||
if (config.jsOutput && typeof config.jsOutput === "boolean") { | ||
const filename = path.basename(config.output, path.extname(config.output)); | ||
config.jsOutput = path.resolve(path.join(path.dirname(config.output), `${filename}.js`)); | ||
} | ||
|
||
if (config.luaOutput && typeof config.luaOutput === "boolean") { | ||
const filename = path.basename(config.output, path.extname(config.output)); | ||
config.luaOutput = path.resolve(path.join(path.dirname(config.output), `${filename}.lua`)); | ||
} | ||
|
||
// console.dir(config); | ||
|
||
function getInputOptions ({ input, output, ...jspiclOptions }) { | ||
return { | ||
input, | ||
plugins: [ | ||
includePaths({ | ||
paths: [path.resolve(input)] | ||
}), | ||
buble(), | ||
{ | ||
renderChunk: source => source.replace(/\/\/ <!-- DEBUG[^//]*\/\/\s-->/g, "") | ||
}, | ||
jspiclPlugin(jspiclOptions) | ||
] | ||
}; | ||
} | ||
|
||
function getOutputOptions ({ output }) { | ||
return { | ||
file: output, | ||
format: "esm", | ||
freeze: false | ||
}; | ||
} | ||
|
||
function getWatchOptions (config) { | ||
return { | ||
...getInputOptions(config), | ||
output: [getOutputOptions(config)], | ||
watch: { | ||
clearScreen: true, | ||
chokidar: true, | ||
exclude: "node_modules/**" | ||
} | ||
}; | ||
} | ||
|
||
(async function build () { | ||
try { | ||
if (config.watch) { | ||
console.clear(); | ||
rollup.watch(getWatchOptions(config)); | ||
} | ||
else { | ||
const bundle = await rollup.rollup(getInputOptions(config)); | ||
await bundle.write(getOutputOptions(config)); | ||
} | ||
} | ||
catch (e) { | ||
console.error(e.message); | ||
} | ||
})(); |
Oops, something went wrong.