@@ -15,6 +15,7 @@ import tap from 'gulp-tap';
1515import filter from 'gulp-filter' ;
1616import eslint from 'gulp-eslint' ;
1717import semver from 'semver' ;
18+ import jscodeshift from 'jscodeshift' ;
1819
1920export class Generator extends Base {
2021 constructor ( ...args ) {
@@ -461,52 +462,47 @@ export class Generator extends Base {
461462 get writing ( ) {
462463 return {
463464 generateProject : function ( ) {
464- /**
465- * var tap = require('gulp-tap');
466- this.registerTransformStream([
467- extensionFilter,
468- tap(function(file, t) {
469- var contents = file.contents.toString();
470- contents = beautify_js(contents, config);
471- file.contents = new Buffer(contents);
472- }),
473- //prettifyJs(config),
474- extensionFilter.restore
475- ]);
476- */
477-
478465 const flow = this . filters . flow ;
479466
480- let babelPlugins = [
481- 'babel-plugin-syntax-flow' ,
482- 'babel-plugin-syntax-class-properties' ,
483- 'babel-plugin-syntax-decorators' ,
484- 'babel-plugin-syntax-export-extensions' ,
485- ] ;
486-
487- if ( this . filters . babel && ! flow ) {
488- babelPlugins . push ( 'babel-plugin-transform-flow-strip-types' ) ;
489- }
490-
491467 const genDir = path . join ( __dirname , '../../' ) ;
492468
469+ // TODO: remove babel stuff from dependencies
470+ const codeshiftStream = tap ( function ( file , t ) {
471+ var contents = file . contents . toString ( ) ;
472+
473+ // remove `implements Foo` from class declarations
474+ contents = jscodeshift ( contents )
475+ . find ( jscodeshift . ClassDeclaration )
476+ . forEach ( path => {
477+ path . value . implements = null ;
478+ } )
479+ . toSource ( ) ;
480+
481+ // remove any type annotations
482+ contents = jscodeshift ( contents )
483+ . find ( jscodeshift . TypeAnnotation )
484+ . remove ( )
485+ . toSource ( ) ;
486+
487+ // remove any `type Foo = { .. }` declarations
488+ contents = jscodeshift ( contents )
489+ . find ( jscodeshift . TypeAlias )
490+ . remove ( )
491+ . toSource ( ) ;
492+
493+ // remove any flow directive comments
494+ contents = jscodeshift ( contents )
495+ . find ( jscodeshift . Comment , path => path . type === 'CommentLine' && path . value . includes ( '@flow' ) )
496+ . forEach ( path => path . prune ( ) )
497+ . toSource ( ) ;
498+
499+ file . contents = new Buffer ( contents ) ;
500+ } ) ;
501+
493502 let clientJsFilter = filter ( [ 'client/**/*.js' ] , { restore : true } ) ;
494503 this . registerTransformStream ( [
495504 clientJsFilter ,
496- babelStream ( {
497- plugins : babelPlugins . map ( require . resolve ) ,
498- /* Babel get's confused about these if you're using an `npm link`ed
499- generator-angular-fullstack, thus the `require.resolve` */
500- shouldPrintComment ( commentContents ) {
501- if ( flow ) {
502- return true ;
503- } else {
504- // strip `// @flow` comments if not using flow
505- return ! ( / @ f l o w / . test ( commentContents ) ) ;
506- }
507- } ,
508- babelrc : false // don't grab the generator's `.babelrc`
509- } ) ,
505+ codeshiftStream ,
510506 eslint ( {
511507 fix : true ,
512508 configFile : path . join ( genDir , 'templates/app/client/.eslintrc(babel)' )
0 commit comments