@@ -13,12 +13,14 @@ const jest = require('jest');
1313const json = require ( 'rollup-plugin-json' ) ;
1414const logError = require ( './logError' ) ;
1515const path = require ( 'path' ) ;
16- const prog = sade ( 'tsdx ') ;
16+ const mkdirp = require ( 'mkdirp ') ;
1717const replace = require ( 'rollup-plugin-replace' ) ;
1818const resolve = require ( 'rollup-plugin-node-resolve' ) ;
1919const sourceMaps = require ( 'rollup-plugin-sourcemaps' ) ;
2020const typescript = require ( 'rollup-plugin-typescript2' ) ;
21+ const execa = require ( 'execa' ) ;
2122
23+ const prog = sade ( 'tsdx' ) ;
2224// Make sure any symlinks in the project folder are resolved:
2325// https://github.com/facebookincubator/create-react-app/issues/637
2426const appDirectory = fs . realpathSync ( process . cwd ( ) ) ;
@@ -226,6 +228,62 @@ prog
226228 }
227229 } ) ;
228230
231+ prog
232+ . command ( 'create <pkg>' )
233+ . describe ( 'Create a new package with TSDX' )
234+ . action ( async pkg => {
235+ try {
236+ console . log ( 'Bootstrapping new project...' ) ;
237+ const projectPath = process . cwd ( ) + '/' + pkg ;
238+ // copy the template
239+ await fs . copy ( path . resolve ( __dirname , './template' ) , projectPath , {
240+ overwrite : true ,
241+ } ) ;
242+ // fix gitignore
243+ await fs . move (
244+ path . resolve ( projectPath , './gitignore' ) ,
245+ path . resolve ( projectPath , './.gitignore' )
246+ ) ;
247+ // Install deps
248+ process . chdir ( projectPath ) ;
249+ const safeName = safeVariableName ( pkg ) ;
250+ const pkgJson = {
251+ name : safeName ,
252+ version : '0.1.0' ,
253+ source : 'src/index.ts' ,
254+ main : 'index.js' ,
255+ 'umd:main' : `dist/${ safeName } .umd.production.js` ,
256+ module : `dist/${ safeName } .es.production.js` ,
257+ typings : 'dist/index.d.ts' ,
258+ scripts : {
259+ start : 'tsdx watch' ,
260+ build : 'tsdx build' ,
261+ test : 'tsdx test' ,
262+ } ,
263+ } ;
264+ await fs . outputJSON ( path . resolve ( projectPath , 'package.json' ) , pkgJson ) ;
265+
266+ console . log ( 'Installing dependencies...' ) ;
267+
268+ await execa ( `yarn` , [
269+ 'add' ,
270+ '@types/jest' ,
271+ 'tsdx' ,
272+ 'typescript' ,
273+ '--dev' ,
274+ ] ) ;
275+ console . log ( `
276+ Success!! TSDX just bootstrapped a brand new project for you. To get started, run:
277+
278+ cd ${ pkg }
279+ yarn start
280+
281+ ` ) ;
282+ } catch ( error ) {
283+ logError ( error ) ;
284+ }
285+ } ) ;
286+
229287prog
230288 . command ( 'test' )
231289 . describe (
0 commit comments