Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadim Demedes committed Jun 29, 2019
0 parents commit ce91fd2
Show file tree
Hide file tree
Showing 18 changed files with 333 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
yarn.lock
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js:
- '12'
- '10'
- '8'
16 changes: 16 additions & 0 deletions cli.js
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);
});
88 changes: 88 additions & 0 deletions index.js
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();
};
9 changes: 9 additions & 0 deletions license
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.
Binary file added media/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions package.json
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"
]
}
}
21 changes: 21 additions & 0 deletions readme.md
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)
12 changes: 12 additions & 0 deletions template/.editorconfig
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
1 change: 1 addition & 0 deletions template/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
2 changes: 2 additions & 0 deletions template/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
yarn.lock
31 changes: 31 additions & 0 deletions template/_package.json
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"
}
}
22 changes: 22 additions & 0 deletions template/cli.js
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));
27 changes: 27 additions & 0 deletions template/readme.md
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
```
17 changes: 17 additions & 0 deletions template/test.js
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}`);
});
20 changes: 20 additions & 0 deletions template/ui.js
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;

0 comments on commit ce91fd2

Please sign in to comment.