Skip to content

Commit

Permalink
improved init command with typescript scaffolding (#24)
Browse files Browse the repository at this point in the history
improved init command with typescript scaffolding
  • Loading branch information
osdevisnot authored Dec 23, 2019
2 parents e958e7b + 47b959c commit 7465019
Show file tree
Hide file tree
Showing 45 changed files with 812 additions and 632 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ First, setup your project using `klap init`:
npx klap init
```

**Prefer Typescript Setup ?** `init` using `ts` argument:

```bash
npx klap init ts
```

**Want to use JSX with Typescript?** `init` using `tsx` argument:

```bash
npx klap init tsx
```

This will create a minimal `package.json` with `source`, `main`, `module` and `browser` entries and the `build`, `watch` and `start` scripts.

```jsonc
Expand Down
32 changes: 16 additions & 16 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#!/usr/bin/env node
const path = require('path')
const { init, klap, read, log, error, info } = require('./dist')
const { name, version } = require('./package.json')
const command = process.argv[2]
const path = require('path');
const { init, klap, read, log, error, info } = require('./dist');
const { name, version } = require('./package.json');
const command = process.argv[2];

;(async () => {
(async () => {
switch (command) {
case 'init':
log(`${name}@${version} - Initializing your package...`)
await init(command)
break
log(`${name}@${version} - Initializing your package...`);
await init(command);
break;
case 'build':
case 'watch':
case 'start':
log(`${name}@${version} - Working on ${command}...`)
log(`${name}@${version} - Working on ${command}...`);
const pkg = JSON.parse(
await read(path.join(process.cwd(), 'package.json'))
)
await klap(command, pkg)
break
);
await klap(command, pkg);
break;
case 'help':
info(`
${name}@${version} - Usage
Expand All @@ -27,9 +27,9 @@ ${name}@${version} - Usage
klap build - bundle your package, in production mode.
klap watch - bundle your package and watch for changes.
klap start - start a development server.
`)
break
`);
break;
default:
error('No Such Command !!')
error('No Such Command !!');
}
})()
})();
4 changes: 2 additions & 2 deletions examples/react-component/dist/index.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions examples/react-component/dist/index.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions examples/react-component/dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

150 changes: 75 additions & 75 deletions examples/react-component/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 25 additions & 25 deletions examples/react-component/package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
{
"name": "react-component",
"version": "0.0.0",
"private": true,
"files": [
"dist"
],
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"source": "src/index.js",
"browser": "dist/index.js",
"scripts": {
"build": "klap build",
"start": "klap start",
"watch": "klap watch"
},
"dependencies": {
"react": "*",
"react-dom": "*"
},
"devDependencies": {
"klap": "2.1.0"
},
"klap": {
"example": "public/index.js"
}
"name": "react-component",
"version": "0.0.0",
"private": true,
"files": [
"dist"
],
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"source": "src/index.js",
"browser": "dist/index.js",
"scripts": {
"build": "klap build",
"start": "klap start",
"watch": "klap watch"
},
"dependencies": {
"react": "*",
"react-dom": "*"
},
"devDependencies": {
"klap": "2.1.0"
},
"klap": {
"example": "public/index.js"
}
}
11 changes: 7 additions & 4 deletions examples/react-component/public/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import React from 'react'
import { render } from 'react-dom'
import { Button } from '../src'
import React from 'react';
import { render } from 'react-dom';
import { Button } from '../src';

render(<Button onClick={e => console.log(e)} />, document.getElementById('root'))
render(
<Button onClick={e => console.log(e)} />,
document.getElementById('root')
);
8 changes: 4 additions & 4 deletions examples/react-component/src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react'
import React from 'react';

const Button = ({ onClick }) => {
return (
<button class="button" onClick={onClick}>
Hello Button
</button>
)
}
);
};

export { Button }
export { Button };
16 changes: 8 additions & 8 deletions examples/react-sc-typescript/dist/index.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7465019

Please sign in to comment.