-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
Vadim Demedes
committed
Jun 29, 2019
0 parents
commit ce91fd2
Showing
18 changed files
with
333 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,12 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = tab | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.yml] | ||
indent_style = space | ||
indent_size = 2 |
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 @@ | ||
* text=auto eol=lf |
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,2 @@ | ||
node_modules | ||
yarn.lock |
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 @@ | ||
language: node_js | ||
node_js: | ||
- '12' | ||
- '10' | ||
- '8' |
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,16 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
const meow = require('meow'); | ||
const createInkApp = require('.'); | ||
|
||
meow(` | ||
Usage | ||
$ mkdir my-cli | ||
$ cd my-cli | ||
$ create-ink-app | ||
`); | ||
|
||
createInkApp().catch(error => { | ||
console.error(error.stack); | ||
process.exit(1); | ||
}); |
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,88 @@ | ||
'use strict'; | ||
const {promisify} = require('util'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const replaceString = require('replace-string'); | ||
const slugify = require('slugify'); | ||
const execa = require('execa'); | ||
const Listr = require('listr'); | ||
const cpy = require('cpy'); | ||
|
||
const readFile = promisify(fs.readFile); | ||
const writeFile = promisify(fs.writeFile); | ||
|
||
const copyWithTemplate = async (from, to, variables) => { | ||
const source = await readFile(from, 'utf8'); | ||
let generatedSource = source; | ||
|
||
if (typeof variables === 'object') { | ||
generatedSource = replaceString(source, '%NAME%', variables.name); | ||
} | ||
|
||
await writeFile(to, generatedSource); | ||
}; | ||
|
||
const fromPath = file => path.join(__dirname, 'template', file); | ||
const toPath = file => path.join(process.cwd(), file); | ||
|
||
module.exports = () => { | ||
const pkgName = slugify(path.basename(process.cwd())); | ||
|
||
const tasks = new Listr([ | ||
{ | ||
title: 'Copy files', | ||
task: async () => { | ||
const variables = { | ||
name: pkgName | ||
}; | ||
|
||
return Promise.all([ | ||
copyWithTemplate(fromPath('_package.json'), toPath('package.json'), variables), | ||
copyWithTemplate(fromPath('readme.md'), toPath('readme.md'), variables), | ||
copyWithTemplate(fromPath('cli.js'), toPath('cli.js'), variables), | ||
cpy(fromPath('ui.js'), process.cwd()), | ||
cpy(fromPath('test.js'), process.cwd()), | ||
cpy([ | ||
fromPath('.editorconfig'), | ||
fromPath('.gitattributes'), | ||
fromPath('.gitignore') | ||
], process.cwd()) | ||
]); | ||
} | ||
}, | ||
{ | ||
title: 'Install dependencies', | ||
task: async () => { | ||
await execa('npm', [ | ||
'install', | ||
'meow', | ||
'ink', | ||
'react', | ||
'prop-types', | ||
'import-jsx' | ||
]); | ||
|
||
return execa('npm', [ | ||
'install', | ||
'--save-dev', | ||
'xo', | ||
'ava', | ||
'ink-testing-library', | ||
'chalk', | ||
'@babel/preset-react', | ||
'@babel/register', | ||
'eslint-config-xo-react', | ||
'eslint-plugin-react', | ||
'eslint-plugin-react-hooks' | ||
]); | ||
} | ||
}, | ||
{ | ||
title: 'Link executable', | ||
task: () => execa('npm', ['link']) | ||
} | ||
]); | ||
|
||
console.log(); | ||
return tasks.run(); | ||
}; |
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) Vadim Demedes <[email protected]> (vadimdemedes.com) | ||
|
||
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. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
{ | ||
"name": "create-ink-app", | ||
"version": "0.0.0", | ||
"description": "Generate a starter Ink app", | ||
"license": "MIT", | ||
"repository": "vadimdemedes/create-ink-app", | ||
"author": { | ||
"name": "Vadim Demedes", | ||
"email": "[email protected]", | ||
"url": "vadimdemedes.com" | ||
}, | ||
"bin": "cli.js", | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"scripts": { | ||
"test": "xo" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"cli.js", | ||
"template" | ||
], | ||
"keywords": [ | ||
"ink", | ||
"ink-app", | ||
"ink", | ||
"ink-app", | ||
"cli" | ||
], | ||
"dependencies": { | ||
"cpy": "^7.2.0", | ||
"execa": "^1.0.0", | ||
"listr": "^0.14.3", | ||
"meow": "^5.0.0", | ||
"replace-string": "^3.0.0", | ||
"slugify": "^1.3.4" | ||
}, | ||
"devDependencies": { | ||
"xo": "^0.21.0" | ||
}, | ||
"xo": { | ||
"ignores": [ | ||
"template" | ||
] | ||
} | ||
} |
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 @@ | ||
# create-ink-app [![Build Status](https://travis-ci.org/vadimdemedes/create-ink-app.svg?branch=master)](https://travis-ci.org/vadimdemedes/create-ink-app) | ||
|
||
> Generate a starter [Ink](https://github.com/vadimdemedes/ink) app | ||
|
||
## Usage | ||
|
||
This helper tool scaffolds out basic project structure for Ink apps and lets you avoid the boilerplate and get to building beautiful CLIs in no time. | ||
|
||
```bash | ||
$ mkdir my-fancy-cli | ||
$ cd my-fancy-cli | ||
$ npx create-ink-app | ||
``` | ||
|
||
![](media/demo.gif) | ||
|
||
|
||
## License | ||
|
||
MIT © [Vadim Demedes](https://vadimdemedes.com) |
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,12 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = tab | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.yml] | ||
indent_style = space | ||
indent_size = 2 |
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 @@ | ||
* text=auto eol=lf |
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,2 @@ | ||
node_modules | ||
yarn.lock |
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,31 @@ | ||
{ | ||
"name": "%NAME%", | ||
"version": "0.0.0", | ||
"license": "MIT", | ||
"bin": "cli.js", | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"cli.js", | ||
"ui.js" | ||
], | ||
"dependencies": {}, | ||
"devDependencies": {}, | ||
"ava": { | ||
"require": [ | ||
"@babel/register" | ||
] | ||
}, | ||
"babel": { | ||
"presets": [ | ||
"@babel/preset-react" | ||
] | ||
}, | ||
"xo": { | ||
"extends": "xo-react" | ||
} | ||
} |
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,22 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
const React = require('react'); | ||
const importJsx = require('import-jsx'); | ||
const {render} = require('ink'); | ||
const meow = require('meow'); | ||
|
||
const ui = importJsx('./ui'); | ||
|
||
const cli = meow(` | ||
Usage | ||
$ %NAME% | ||
Options | ||
--name Your name | ||
Examples | ||
$ %NAME% --name=Jane | ||
Hello, Jane | ||
`); | ||
|
||
render(React.createElement(ui, cli.flags)); |
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,27 @@ | ||
# %NAME% | ||
|
||
> This readme is automatically generated by [create-ink-app](https://github.com/vadimdemedes/create-ink-app) | ||
|
||
## Install | ||
|
||
```bash | ||
$ npm install --global %NAME% | ||
``` | ||
|
||
|
||
## CLI | ||
|
||
``` | ||
$ %NAME% --help | ||
Usage | ||
$ %NAME% | ||
Options | ||
--name Your name | ||
Examples | ||
$ %NAME% --name=Jane | ||
Hello, Jane | ||
``` |
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,17 @@ | ||
import React from 'react'; | ||
import chalk from 'chalk'; | ||
import test from 'ava'; | ||
import {render} from 'ink-testing-library'; | ||
import App from './ui'; | ||
|
||
test('greet unknown user', t => { | ||
const {lastFrame} = render(<App/>); | ||
|
||
t.is(lastFrame(), chalk`Hello, {green Stranger}`); | ||
}); | ||
|
||
test('greet user with a name', t => { | ||
const {lastFrame} = render(<App name="Jane"/>); | ||
|
||
t.is(lastFrame(), chalk`Hello, {green Jane}`); | ||
}); |
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,20 @@ | ||
'use strict'; | ||
const React = require('react'); | ||
const PropTypes = require('prop-types'); | ||
const {Text, Color} = require('ink'); | ||
|
||
const App = ({name}) => ( | ||
<Text> | ||
Hello, <Color green>{name}</Color> | ||
</Text> | ||
); | ||
|
||
App.propTypes = { | ||
name: PropTypes.string | ||
}; | ||
|
||
App.defaultProps = { | ||
name: 'Stranger' | ||
}; | ||
|
||
module.exports = App; |