Skip to content

Commit

Permalink
Remove .ts support ahead of adding ES6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveSanderson committed Oct 12, 2015
1 parent d88af3a commit 355035a
Show file tree
Hide file tree
Showing 24 changed files with 13 additions and 5,486 deletions.
32 changes: 4 additions & 28 deletions app/index.js
Expand Up @@ -4,11 +4,6 @@ var path = require('path');
var yeoman = require('yeoman-generator');
var chalk = require('chalk');

var languageChoice = {
js: 'JavaScript',
ts: 'TypeScript'
};

var KoGenerator = yeoman.generators.Base.extend({
init: function () {
this.pkg = require('../package.json');
Expand Down Expand Up @@ -54,11 +49,6 @@ var KoGenerator = yeoman.generators.Base.extend({
name: 'name',
message: 'What\'s the name of your new site?',
default: path.basename(process.cwd())
}, {
type: 'list',
name: 'codeLanguage',
message: 'What language do you want to use?',
choices: [languageChoice.js, languageChoice.ts]
}, {
type: 'confirm',
name: 'includeTests',
Expand All @@ -69,15 +59,13 @@ var KoGenerator = yeoman.generators.Base.extend({
this.prompt(prompts, function (props) {
this.longName = props.name;
this.slugName = this._.slugify(this.longName);
this.usesTypeScript = props.codeLanguage === languageChoice.ts;
this.includeTests = props.includeTests;
done();
}.bind(this));
},

templating: function () {
var excludeExtension = this.usesTypeScript ? '.js' : '.ts';
this._processDirectory('src', 'src', excludeExtension);
this._processDirectory('src', 'src');
this.template('_package.json', 'package.json');
this.template('_bower.json', 'bower.json');
this.template('_gulpfile.js', 'gulpfile.js');
Expand All @@ -86,27 +74,15 @@ var KoGenerator = yeoman.generators.Base.extend({

if (this.includeTests) {
// Set up tests
this._processDirectory('test', 'test', excludeExtension);
this._processDirectory('test', 'test');
this.copy('bowerrc_test', 'test/.bowerrc');
this.copy('karma.conf.js');
}

// Explicitly copy the .js files used by the .ts output, since they're otherwise excluded
if (this.usesTypeScript) {
this.copy('src/app/require.config.js');
this._processDirectory('definitions', 'definitions');

if (this.includeTests) {
this.copy('test/require.config.js');
}
}
},

_processDirectory: function(source, destination, excludeExtension) {
_processDirectory: function(source, destination) {
var root = this.isPathAbsolute(source) ? source : path.join(this.sourceRoot(), source);
var files = this.expandFiles('**', { dot: true, cwd: root }).filter(function(filename) {
return !excludeExtension || path.extname(filename) !== excludeExtension;
});
var files = this.expandFiles('**', { dot: true, cwd: root });

for (var i = 0; i < files.length; i++) {
var f = files[i];
Expand Down
9 changes: 0 additions & 9 deletions app/templates/_gitignore
Expand Up @@ -4,12 +4,3 @@ bower_modules/

# Don't track build output
dist/
<% if(usesTypeScript) { %>
# Don't track .js/.js.map files (typically they are generated by the TypeScript compiler)
src/**/*.js
src/**/*.js.map

# ... except specific ones, which should be tracked
!src/app/require.config.js
!src/app/lib/*.js*
<% } %>
32 changes: 5 additions & 27 deletions app/templates/_gulpfile.js
Expand Up @@ -3,7 +3,7 @@ var fs = require('fs'), vm = require('vm'), merge = require('deeply'), chalk = r

// Gulp and plugins
var gulp = require('gulp'), rjs = require('gulp-requirejs-bundler'), concat = require('gulp-concat'), clean = require('gulp-clean'),
replace = require('gulp-replace'), uglify = require('gulp-uglify'), htmlreplace = require('gulp-html-replace')<% if(usesTypeScript) { %>, typescript = require('gulp-tsc')<% } %>;
replace = require('gulp-replace'), uglify = require('gulp-uglify'), htmlreplace = require('gulp-html-replace');

// Config
var requireJsRuntimeConfig = vm.runInNewContext(fs.readFileSync('src/app/require.config.js') + '; require;');
Expand All @@ -28,20 +28,9 @@ var requireJsRuntimeConfig = vm.runInNewContext(fs.readFileSync('src/app/require
// 'another-bundle-name': [ 'yet-another-module' ]
}
});
<% if (usesTypeScript) { %>
// Compile all .ts files, producing .js and source map files alongside them
gulp.task('ts', function() {
return gulp.src(['**/*.ts'])
.pipe(typescript({
module: 'amd',
sourcemap: true,
outDir: './'
}))
.pipe(gulp.dest('./'));
});
<% } %>

// Discovers all AMD dependencies, concatenates together all required .js files, minifies them
gulp.task('js', <% if (usesTypeScript) { %>['ts'], <% } %>function () {
gulp.task('js', function () {
return rjs(requireJsOptimizerConfig)
.pipe(uglify({ preserveComments: 'some' }))
.pipe(gulp.dest('./dist/'));
Expand All @@ -67,24 +56,13 @@ gulp.task('html', function() {
}))
.pipe(gulp.dest('./dist/'));
});
<% if (!usesTypeScript) { %>

// Removes all files from ./dist/
gulp.task('clean', function() {
return gulp.src('./dist/**/*', { read: false })
.pipe(clean());
});
<% } else { %>
// Removes all files from ./dist/, and the .js/.js.map files compiled from .ts
gulp.task('clean', function() {
var distContents = gulp.src('./dist/**/*', { read: false }),
generatedJs = gulp.src(['src/**/*.js', 'src/**/*.js.map'<% if(includeTests) { %>, 'test/**/*.js', 'test/**/*.js.map'<% } %>], { read: false })
.pipe(es.mapSync(function(data) {
// Include only the .js/.js.map files that correspond to a .ts file
return fs.existsSync(data.path.replace(/\.js(\.map)?$/, '.ts')) ? data : undefined;
}));
return es.merge(distContents, generatedJs).pipe(clean());
});
<% } %>

gulp.task('default', ['html', 'js', 'css'], function(callback) {
callback();
console.log('\nPlaced optimized files in ' + chalk.magenta('dist/\n'));
Expand Down
4 changes: 0 additions & 4 deletions app/templates/_package.json
Expand Up @@ -10,10 +10,6 @@
"gulp-replace": "~0.2.0",
"gulp-uglify": "~0.2.1",
"gulp-html-replace": "~1.0.0",
<% if(usesTypeScript) { %>
"gulp-tsc": "^0.7.0",
"typescript": "1.0.1",
<% } %>
<% if(includeTests) { %>
"karma": "^0.12.15",
"karma-chrome-launcher": "^0.1.3",
Expand Down
112 changes: 0 additions & 112 deletions app/templates/definitions/bootstrap/bootstrap.d.ts

This file was deleted.

1 comment on commit 355035a

@Sojborg
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why no more TS support? Adding support for ES6 is great but having the option for TS would still be nice.

Please sign in to comment.