diff options
| author | Florian Dold <florian.dold@gmail.com> | 2017-05-03 15:35:00 +0200 | 
|---|---|---|
| committer | Florian Dold <florian.dold@gmail.com> | 2017-05-03 15:35:00 +0200 | 
| commit | de98e0b232509d5f40c135d540a70e415272ff85 (patch) | |
| tree | a79222a5b58484ab3b80d18efcaaa7ccc4769b33 /node_modules/ts-loader/examples/webpack1-gulp-react-flux-babel-karma/gulp | |
| parent | e0c9d480a73fa629c1e4a47d3e721f1d2d345406 (diff) | |
node_modules
Diffstat (limited to 'node_modules/ts-loader/examples/webpack1-gulp-react-flux-babel-karma/gulp')
6 files changed, 331 insertions, 0 deletions
diff --git a/node_modules/ts-loader/examples/webpack1-gulp-react-flux-babel-karma/gulp/.eslintrc b/node_modules/ts-loader/examples/webpack1-gulp-react-flux-babel-karma/gulp/.eslintrc new file mode 100644 index 000000000..f7aa388ad --- /dev/null +++ b/node_modules/ts-loader/examples/webpack1-gulp-react-flux-babel-karma/gulp/.eslintrc @@ -0,0 +1,73 @@ +{
 +  "root": true,
 +  "env": {
 +    "commonjs": true,
 +  },
 +  "rules": {
 +    "camelcase": 2,
 +    "comma-spacing": 1,
 +    "consistent-return": 2,
 +    "curly": [ 2, "all" ],
 +    "dot-notation": [
 +      2,
 +      { "allowKeywords": true }
 +    ],
 +    "eol-last": 2,
 +    "eqeqeq": 2,
 +    "keyword-spacing": 2,
 +    "new-cap": 2,
 +    "new-parens": 2,
 +    "no-alert": 2,
 +    "no-array-constructor": 2,
 +    "no-caller": 2,
 +    "no-catch-shadow": 2,
 +    "no-eval": 2,
 +    "no-extend-native": 2,
 +    "no-extra-bind": 2,
 +    "no-extra-parens": [ 2, "functions" ],
 +    "no-implied-eval": 2,
 +    "no-iterator": 2,
 +    "no-labels": 2,
 +    "no-label-var": 2,
 +    "no-lone-blocks": 2,
 +    "no-loop-func": 2,
 +    "no-multi-str": 2,
 +    "no-native-reassign": 2,
 +    "no-new": 2,
 +    "no-new-func": 2,
 +    "no-new-object": 2,
 +    "no-new-wrappers": 2,
 +    "no-octal-escape": 2,
 +    "no-proto": 2,
 +    "no-return-assign": 2,
 +    "no-script-url": 2,
 +    "no-sequences": 2,
 +    "no-shadow": 2,
 +    "no-shadow-restricted-names": 2,
 +    "no-spaced-func": 2,
 +    "no-trailing-spaces": 1,
 +    "no-undef-init": 2,
 +    "no-unused-expressions": 2,
 +    "no-use-before-define": [ 2, "nofunc" ],
 +    "no-with": 2,
 +    "quotes": [ 1, "single" ],
 +    "semi": 2,
 +    "semi-spacing": [
 +      2,
 +      {
 +        "before": false,
 +        "after": true
 +      }
 +    ],
 +    "space-infix-ops": 2,
 +    "space-unary-ops": [
 +      2,
 +      {
 +        "words": true,
 +        "nonwords": false
 +      }
 +    ],
 +    "strict": [ 2, "global" ],
 +    "yoda": [ 2, "never" ]
 +  }
 +}
 diff --git a/node_modules/ts-loader/examples/webpack1-gulp-react-flux-babel-karma/gulp/clean.js b/node_modules/ts-loader/examples/webpack1-gulp-react-flux-babel-karma/gulp/clean.js new file mode 100644 index 000000000..c51b4e416 --- /dev/null +++ b/node_modules/ts-loader/examples/webpack1-gulp-react-flux-babel-karma/gulp/clean.js @@ -0,0 +1,29 @@ +'use strict'; + +var del = require('del'); +var gutil = require('gulp-util'); +var fs = require('fs'); + +function run(done) { +  fs.stat('./dist', function(err){ +    if (err) { +      // Never existed +      done(); +    } +    else { +      del(['./dist'], { force: true }) +        .then(function(paths) { +          gutil.log('Deleted files/folders:\n', paths.join('\n')); +          done(); +        }) +        .catch(function(error) { +          gutil.log('Problem deleting:\n', error); +          done(); +        }); +    } +  }); +} + +module.exports = { +  run: function(done) { return run(done); } +}; diff --git a/node_modules/ts-loader/examples/webpack1-gulp-react-flux-babel-karma/gulp/inject.js b/node_modules/ts-loader/examples/webpack1-gulp-react-flux-babel-karma/gulp/inject.js new file mode 100644 index 000000000..e4133e565 --- /dev/null +++ b/node_modules/ts-loader/examples/webpack1-gulp-react-flux-babel-karma/gulp/inject.js @@ -0,0 +1,55 @@ +'use strict'; + +var gulp = require('gulp'); +var inject = require('gulp-inject'); +var glob = require('glob'); + +function injectIndex(options) { +  function run() { +    var target = gulp.src('./src/index.html'); +    var sources = gulp.src([ +      //'./dist/styles/main*.css', +      './dist/scripts/vendor*.js', +      './dist/scripts/main*.js' +    ], { read: false }); + +    return target +      .pipe(inject(sources, { ignorePath: '/dist/', addRootSlash: false, removeTags: true })) +      .pipe(gulp.dest('./dist')); +  } + +  var jsCssGlob = 'dist/**/*.{js,css}'; + +  function checkForInitialFilesThenRun() { +    glob(jsCssGlob, function (er, files) { +      var filesWeNeed = ['dist/scripts/main', 'dist/scripts/vendor'/*, 'dist/styles/main'*/]; + +      function fileIsPresent(fileWeNeed) { +        return files.some(function(file) { +          return file.indexOf(fileWeNeed) !== -1; +        }); +      } + +      if (filesWeNeed.every(fileIsPresent)) { +        run('initial build'); +      } else { +        checkForInitialFilesThenRun(); +      } +    }); +  } + +  checkForInitialFilesThenRun(); + +  if (options.shouldWatch) { +    gulp.watch(jsCssGlob, function(evt) { +      if (evt.path && evt.type === 'changed') { +        run(evt.path); +      } +    }); +  } +} + +module.exports = { +  build: function() { return injectIndex({ shouldWatch: false }); }, +  watch: function() { return injectIndex({ shouldWatch: true  }); } +}; diff --git a/node_modules/ts-loader/examples/webpack1-gulp-react-flux-babel-karma/gulp/staticFiles.js b/node_modules/ts-loader/examples/webpack1-gulp-react-flux-babel-karma/gulp/staticFiles.js new file mode 100644 index 000000000..20327f272 --- /dev/null +++ b/node_modules/ts-loader/examples/webpack1-gulp-react-flux-babel-karma/gulp/staticFiles.js @@ -0,0 +1,31 @@ +'use strict'; + +var gulp = require('gulp'); +var cache = require('gulp-cached'); + +var targets = [ +  { description: 'INDEX', src: './src/index.html', dest: './dist' } +]; + +function copy(options) { +  function run(target) { +    gulp.src(target.src) +      .pipe(cache(target.description)) +      .pipe(gulp.dest(target.dest)); +  } + +  function watch(target) { +    gulp.watch(target.src, function() { run(target); }); +  } + +  targets.forEach(run); + +  if (options.shouldWatch) { +    targets.forEach(watch); +  } +} + +module.exports = { +  build: function() { return copy({ shouldWatch: false }); }, +  watch: function() { return copy({ shouldWatch: true }); } +}; diff --git a/node_modules/ts-loader/examples/webpack1-gulp-react-flux-babel-karma/gulp/tests.js b/node_modules/ts-loader/examples/webpack1-gulp-react-flux-babel-karma/gulp/tests.js new file mode 100644 index 000000000..05af0a551 --- /dev/null +++ b/node_modules/ts-loader/examples/webpack1-gulp-react-flux-babel-karma/gulp/tests.js @@ -0,0 +1,45 @@ +'use strict'; + +var Server = require('karma').Server; +var path = require('path'); +var gutil = require('gulp-util'); + +function runTests(options) { +  // Documentation: https://karma-runner.github.io/0.13/dev/public-api.html +  var karmaConfig = { +    configFile: path.join(__dirname, '../karma.conf.js'), +    singleRun: !options.shouldWatch, + +    plugins: ['karma-webpack', 'karma-jasmine', 'karma-mocha-reporter', 'karma-sourcemap-loader', 'karma-phantomjs-launcher'], +    reporters: ['mocha'] +  }; + +  if (options.done) { +    karmaConfig.plugins.push('karma-junit-reporter'); +    karmaConfig.reporters.push('junit'); +  } else { +    karmaConfig.plugins.push('karma-notify-reporter'); +    karmaConfig.reporters.push('notify'); +  } + +  new Server(karmaConfig, karmaCompleted).start(); + +  function karmaCompleted(exitCode) { +    if (options.done) { +      if (exitCode === 1) { +        gutil.log('Karma: tests failed with code ' + exitCode); +      } else { +        gutil.log('Karma completed!'); +      } +      options.done(); +    } +    else { +      process.exit(exitCode); +    } +  } +} + +module.exports = { +  run:   function(done) { return runTests({ shouldWatch: false, done: done }); }, +  watch: function()     { return runTests({ shouldWatch: true  }); } +}; diff --git a/node_modules/ts-loader/examples/webpack1-gulp-react-flux-babel-karma/gulp/webpack.js b/node_modules/ts-loader/examples/webpack1-gulp-react-flux-babel-karma/gulp/webpack.js new file mode 100644 index 000000000..b0de5c558 --- /dev/null +++ b/node_modules/ts-loader/examples/webpack1-gulp-react-flux-babel-karma/gulp/webpack.js @@ -0,0 +1,98 @@ +'use strict'; + +var gulp = require('gulp'); +var gutil = require('gulp-util'); +var webpack = require('webpack'); +var WebpackNotifierPlugin = require('webpack-notifier'); +var failPlugin = require('webpack-fail-plugin'); +var webpackConfig = require('../webpack.config.js'); +var packageJson = require('../package.json'); + +function buildProduction(done) { +   // modify some webpack config options +   var myProdConfig = Object.create(webpackConfig); +   myProdConfig.output.filename = '[name].[hash].js'; + +   myProdConfig.plugins = myProdConfig.plugins.concat( +      new webpack.DefinePlugin({ +          'process.env': { +              'NODE_ENV': JSON.stringify('production') +         } +      }), +      new webpack.optimize.CommonsChunkPlugin({ name: 'vendor', filename: 'vendor.[hash].js' }), +      new webpack.optimize.DedupePlugin(), +      new webpack.optimize.UglifyJsPlugin(), +      failPlugin +   ); + +   // run webpack +   webpack(myProdConfig, function (err, stats) { +      if (err) { throw new gutil.PluginError('webpack:build', err); } +      gutil.log('[webpack:build]', stats.toString({ +         colors: true +      })); + +      if (done) { done(); } +   }); +} + +function createDevCompiler() { +   // modify some webpack config options +   var myDevConfig = Object.create(webpackConfig); +   myDevConfig.devtool = 'inline-source-map'; +   myDevConfig.debug = true; + +   myDevConfig.plugins = myDevConfig.plugins.concat( +      new webpack.optimize.CommonsChunkPlugin({ name: 'vendor', filename: 'vendor.js' }), +      new WebpackNotifierPlugin({ title: 'Webpack build', excludeWarnings: true }) +   ); + +   // create a single instance of the compiler to allow caching +   return webpack(myDevConfig); +} + +function build() { +   return new Promise(function (resolve, reject) { +      buildProduction(function (err) { +         if (err) { +            reject(err); +         } else { +            resolve('webpack built'); +         } +      }); +   }); +} + +function watch() { +   var firstBuildDone = false; + +   return new Promise(function (resolve, reject) { +      var devCompiler = createDevCompiler(); +      devCompiler.watch({ // watch options: +         aggregateTimeout: 300 // wait so long for more changes +      }, function (err, stats) { +         if (err) { +            if (!firstBuildDone) { +               firstBuildDone = true; +               reject(err); +            } +            throw new gutil.PluginError('webpack:build-dev', err); +         } else { +            if (!firstBuildDone) { +               firstBuildDone = true; +               resolve('webpack built'); +            } +         } + +         gutil.log('[webpack:build-dev]', stats.toString({ +            chunks: false, +            colors: true +         })); +      }); +   }); +} + +module.exports = { +   build: function () { return build(); }, +   watch: function () { return watch(); } +};  | 
