VOOZH about

URL: https://qiita.com/akameco/items/e0af9e3cdf1cdb6fca61

⇱ 名刺の代わりにCLIアプリを書く #JavaScript - Qiita


👁 Image
589

Go to list of users who liked

391

Share on X(Twitter)

Share on Facebook

Add to Hatena Bookmark

More than 5 years have passed since last update.

@akameco(akameco)

名刺の代わりにCLIアプリを書く

589
Last updated at Posted at 2018-05-15

ここ1週間自己紹介用のCLIアプリを書くのが流行ってる。
はじまりはいつものSindre Sorhus。

My new business card pic.twitter.com/koVIsUT5np

— Sindre Sorhus (@sindresorhus) May 10, 2018

nodeが入っていれば

npx sindresorhus

すると自己紹介CLIアプリが起動。

```
$ npx sindresorhus
```https://t.co/QO3ogKmu1d pic.twitter.com/xZdQSzFLAq

— Sindre Sorhus (@sindresorhus) May 9, 2018

基本的には、このレポジトリを適当に書き換えれば簡単にできる。
はじめてのnpmライブラリにちょうどいいかも知れない。

また、使っている技術がちょっとおもしろくて、inkを使っている。
これは何かとCLIのためのReactだ。

普通にReactでCLIを書くことができる。
なお、v0.5がちょっと壊れている雰囲気あってエラーが出るのでv0.4推奨です。

const {h, render, Component, Color } = require('ink');

class Counter extends Component {
	constructor() {
		super();

		this.state = {
			i: 0
		};
	}

	render() {
		return (
			<Color green>
				{this.state.i} tests passed
			</Color>
		);
	}

	componentDidMount() {
		this.timer = setInterval(() => {
			this.setState({
				i: this.state.i + 1
			});
		}, 100);
	}

	componentWillUnmount() {
		clearInterval(this.timer);
	}
}

render(<Counter/>);

👁 Image

また、本家では、import-jsxを使って実行時にばべっているのだけど、これだとインストールに時間かかるので、普通にバベるのがいいと思う。

それでは、よいCLIライフを。

流行に乗るオタクなのでnpx akamecoつくってしまった https://t.co/CkdYHj2NGA pic.twitter.com/f8kGNT6FKk

— あかめ@社会性.js (@akameco) May 15, 2018
589

Go to list of users who liked

391
1

Go to list of comments

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
589

Go to list of users who liked

391