Skip to content

Commit

Permalink
Add create command
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredpalmer committed Jan 26, 2019
1 parent a246365 commit 9010ecb
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ TSDX comes with the "battery-pack included" and is part of a complete TypeScript
## Quick Start

```
npx tsdx create my-lib
yarn tsdx create my-lib
cd my-lib
npm start
yarn start
```

That's it. You don't need to worry about setting up Typescript or Rollup or Jest or other plumbing. Just start editing `src/index.ts` and go!
Expand Down
60 changes: 59 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ const jest = require('jest');
const json = require('rollup-plugin-json');
const logError = require('./logError');
const path = require('path');
const prog = sade('tsdx');
const mkdirp = require('mkdirp');
const replace = require('rollup-plugin-replace');
const resolve = require('rollup-plugin-node-resolve');
const sourceMaps = require('rollup-plugin-sourcemaps');
const typescript = require('rollup-plugin-typescript2');
const execa = require('execa');

const prog = sade('tsdx');
// Make sure any symlinks in the project folder are resolved:
// https://github.com/facebookincubator/create-react-app/issues/637
const appDirectory = fs.realpathSync(process.cwd());
Expand Down Expand Up @@ -226,6 +228,62 @@ prog
}
});

prog
.command('create <pkg>')
.describe('Create a new package with TSDX')
.action(async pkg => {
try {
console.log('Bootstrapping new project...');
const projectPath = process.cwd() + '/' + pkg;
// copy the template
await fs.copy(path.resolve(__dirname, './template'), projectPath, {
overwrite: true,
});
// fix gitignore
await fs.move(
path.resolve(projectPath, './gitignore'),
path.resolve(projectPath, './.gitignore')
);
// Install deps
process.chdir(projectPath);
const safeName = safeVariableName(pkg);
const pkgJson = {
name: safeName,
version: '0.1.0',
source: 'src/index.ts',
main: 'index.js',
'umd:main': `dist/${safeName}.umd.production.js`,
module: `dist/${safeName}.es.production.js`,
typings: 'dist/index.d.ts',
scripts: {
start: 'tsdx watch',
build: 'tsdx build',
test: 'tsdx test',
},
};
await fs.outputJSON(path.resolve(projectPath, 'package.json'), pkgJson);

console.log('Installing dependencies...');

await execa(`yarn`, [
'add',
'@types/jest',
'tsdx',
'typescript',
'--dev',
]);
console.log(`
Success!! TSDX just bootstrapped a brand new project for you. To get started, run:
cd ${pkg}
yarn start
`);
} catch (error) {
logError(error);
}
});

prog
.command('test')
.describe(
Expand Down
3 changes: 3 additions & 0 deletions lib/template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# TSDX Bootstrap

This project was bootstrapped with [TSDX](https://github.com/jaredpalmer/tsdx).
7 changes: 7 additions & 0 deletions lib/template/gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*.log
.DS_Store
node_modules
.rts2_cache_cjs
.rts2_cache_es
.rts2_cache_umd
dist
6 changes: 6 additions & 0 deletions lib/template/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const sum = (a: number, b: number) => {
if ('development' === process.env.NODE_ENV) {
console.log('fuck');
}
return a + b;
};
7 changes: 7 additions & 0 deletions lib/template/test/blah.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { sum } from '../src';

describe('fuck', () => {
it('works', () => {
expect(sum(1, 1)).toEqual(2);
});
});
29 changes: 29 additions & 0 deletions lib/template/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"compilerOptions": {
"target": "es5",
"module": "ESNext",
"lib": ["dom", "esnext"],
"declaration": true,
"sourceMap": true,
"rootDir": "./",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"baseUrl": "./",
"paths": {
"*": ["src/*", "node_modules/*"]
},
"jsx": "react",
"esModuleInterop": true
},
"include": ["src", "types"],
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
"camelcase": "^5.0.0",
"chalk": "^2.4.2",
"cross-env": "5.0.5",
"execa": "^1.0.0",
"fs-extra": "^7.0.1",
"jest": "23.6.0",
"mkdirp": "^0.5.1",
"rollup": "^0.66.4",
"rollup-plugin-babel": "^4.0.3",
"rollup-plugin-commonjs": "^9.1.8",
Expand Down

0 comments on commit 9010ecb

Please sign in to comment.