-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rebuild CLI functionality with Gluegun framework (#5)
* chore: scaffold gluegun CLI project * chore: upgrade deps, use eslint * feat: setup command * feat: add mac setup * feat: add wasm setup * feat: add esp32 setup * refactor: split up setup commands * feat: add esp8266 setup * refactor: create file upsert helper * feat: add init command * feat: add run command * feat: add python server for running wasm sim * refactor: replace python server with node server * feat(run): select, list example project * feat: add include, remove commands for manifest modules * feat: add update command w/ mac support * docs: update README for new CLI reference * refactor: prettier format * chore(package): update yarn -> pnpm references * chore(deps): downgrade to v12 of node types * chore(deps): use v12 of node types again * chore: skipLibCheck in tsconfig * chore: prettier formatting * chore: remove private field from package.json * refactor: remove legacy zx script * docs: add dev instructions to README
- Loading branch information
1 parent
a7004af
commit 9b718a3
Showing
39 changed files
with
5,524 additions
and
505 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,6 @@ | ||
module.exports = { | ||
extends: ['standard-with-typescript', 'prettier'], | ||
parserOptions: { | ||
project: './tsconfig.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,8 @@ | ||
.DS_Store | ||
node_modules | ||
npm-debug.log | ||
coverage | ||
.nyc_output | ||
dist | ||
build | ||
.vscode |
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
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,29 @@ | ||
const { system, filesystem } = require('gluegun') | ||
|
||
const src = filesystem.path(__dirname, '..') | ||
|
||
const cli = async (cmd: string) => | ||
system.run('node ' + filesystem.path(src, 'bin', 'xs-dev') + ` ${cmd}`) | ||
|
||
test('outputs version', async () => { | ||
const output = await cli('--version') | ||
expect(output).toContain('0.0.1') | ||
}) | ||
|
||
test('outputs help', async () => { | ||
const output = await cli('--help') | ||
expect(output).toContain('0.0.1') | ||
}) | ||
|
||
test('generates file', async () => { | ||
const output = await cli('generate foo') | ||
|
||
expect(output).toContain('Generated file at models/foo-model.ts') | ||
const foomodel = filesystem.read('models/foo-model.ts') | ||
|
||
expect(foomodel).toContain(`module.exports = {`) | ||
expect(foomodel).toContain(`name: 'foo'`) | ||
|
||
// cleanup artifact | ||
filesystem.remove('models') | ||
}) |
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 @@ | ||
#!/usr/bin/env node | ||
|
||
|
||
/* tslint:disable */ | ||
// check if we're running in dev mode | ||
var devMode = require('fs').existsSync(`${__dirname}/../src`) | ||
// or want to "force" running the compiled version with --compiled-build | ||
var wantsCompiled = process.argv.indexOf('--compiled-build') >= 0 | ||
|
||
if (wantsCompiled || !devMode) { | ||
// this runs from the compiled javascript source | ||
require(`${__dirname}/../build/cli`).run(process.argv) | ||
} else { | ||
// this runs from the typescript source (for dev only) | ||
// hook into ts-node so we can run typescript on the fly | ||
require('ts-node').register({ project: `${__dirname}/../tsconfig.json` }) | ||
// run the CLI with the current process arguments | ||
require(`${__dirname}/../src/cli`).run(process.argv) | ||
} | ||
|
||
|
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,3 @@ | ||
# Command Reference for xs-dev | ||
|
||
TODO: Add your command reference here |
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,47 @@ | ||
# Plugin guide for xs-dev | ||
|
||
Plugins allow you to add features to xs-dev, such as commands and | ||
extensions to the `toolbox` object that provides the majority of the functionality | ||
used by xs-dev. | ||
|
||
Creating a xs-dev plugin is easy. Just create a repo with two folders: | ||
|
||
``` | ||
commands/ | ||
extensions/ | ||
``` | ||
|
||
A command is a file that looks something like this: | ||
|
||
```js | ||
// commands/foo.js | ||
|
||
module.exports = { | ||
run: (toolbox) => { | ||
const { print, filesystem } = toolbox | ||
|
||
const desktopDirectories = filesystem.subdirectories(`~/Desktop`) | ||
print.info(desktopDirectories) | ||
} | ||
} | ||
``` | ||
|
||
An extension lets you add additional features to the `toolbox`. | ||
|
||
```js | ||
// extensions/bar-extension.js | ||
|
||
module.exports = (toolbox) => { | ||
const { print } = toolbox | ||
|
||
toolbox.bar = () => { print.info('Bar!') } | ||
} | ||
``` | ||
|
||
This is then accessible in your plugin's commands as `toolbox.bar`. | ||
|
||
# Loading a plugin | ||
|
||
To load a particular plugin (which has to start with `xs-dev-*`), | ||
install it to your project using `npm install --save-dev xs-dev-PLUGINNAME`, | ||
and xs-dev will pick it up automatically. |
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,69 @@ | ||
{ | ||
"name": "xs-dev", | ||
"version": "0.0.1", | ||
"description": "CLI for automating the setup and usage of Moddable XS tools", | ||
"types": "build/types/types.d.ts", | ||
"bin": { | ||
"xs-dev": "bin/xs-dev" | ||
}, | ||
"scripts": { | ||
"format": "prettier --write **/*.{js,ts,json}", | ||
"lint": "eslint src/", | ||
"clean-build": "rm -rf ./build", | ||
"compile": "tsc -p .", | ||
"copy-templates": "if [ -e ./src/templates ]; then cp -a ./src/templates ./build/; fi", | ||
"build": "pnpm run format && pnpm run lint && pnpm run clean-build && pnpm run compile && pnpm run copy-templates", | ||
"prepublishOnly": "pnpm run build", | ||
"test": "jest", | ||
"watch": "jest --watch", | ||
"snapupdate": "jest --updateSnapshot", | ||
"coverage": "jest --coverage" | ||
}, | ||
"files": [ | ||
"tsconfig.json", | ||
"build", | ||
"LICENSE", | ||
"README.md", | ||
"docs", | ||
"bin" | ||
], | ||
"license": "MIT", | ||
"dependencies": { | ||
"axios": "^0.24.0", | ||
"gluegun": "latest", | ||
"serve-handler": "^6.1.3", | ||
"tar-fs": "^2.1.1", | ||
"unzip-stream": "^0.3.1" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^27.4.0", | ||
"@types/node": "^16.11.0", | ||
"@types/serve-handler": "^6.1.1", | ||
"@types/tar-fs": "^2.0.1", | ||
"@types/unzip-stream": "^0.3.1", | ||
"@typescript-eslint/eslint-plugin": "^4.0.1", | ||
"@typescript-eslint/parser": "^4.0.0", | ||
"eslint": "^7.12.1", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-config-standard-with-typescript": "^21.0.1", | ||
"eslint-plugin-import": "^2.22.1", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-promise": "^5.0.0", | ||
"jest": "^27.4.0", | ||
"prettier": "^2.5.1", | ||
"ts-jest": "^27.1.0", | ||
"ts-node": "^10.4.0", | ||
"typescript": "^4.5.x" | ||
}, | ||
"jest": { | ||
"preset": "ts-jest", | ||
"testEnvironment": "node" | ||
}, | ||
"volta": { | ||
"node": "16.2.0" | ||
}, | ||
"prettier": { | ||
"semi": false, | ||
"singleQuote": true | ||
} | ||
} |
Oops, something went wrong.