diff --git a/.babelrc b/.babelrc index b0b9a96..eaf3238 100644 --- a/.babelrc +++ b/.babelrc @@ -1,3 +1,3 @@ { - "stage": 0 + "presets": ["es2015", "stage-0"] } diff --git a/.eslintignore b/.eslintignore index 3236cba..805af30 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ template +lib diff --git a/.gitignore b/.gitignore index 3c3629e..491fc35 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +lib diff --git a/bin/sagui b/bin/sagui index 78e5161..4c4e852 100755 --- a/bin/sagui +++ b/bin/sagui @@ -1,9 +1,22 @@ #!/usr/bin/env node +try { + /** + * Try loading the compiled code. + */ + require('../lib/cli').default(process.argv) +} catch (e) { + /** + * If the compiled code is not available, + * use the babel-registery and load from source. + */ + try { + require('babel-register')({ + only: /(sagui\/src)/ + }) -require('babel/register')({ - only: /(sagui\/src)/ -}) - - -require('../src/cli')(process.argv) + require('../src/cli').default(process.argv) + } catch (e) { + throw e + } +} diff --git a/package.json b/package.json index 7dc6a5c..beb69e0 100644 --- a/package.json +++ b/package.json @@ -6,14 +6,21 @@ "bin": { "sagui": "./bin/sagui" }, - "main": "src/index.js", + "main": "lib/index.js", + "files": [ + "bin", + "lib", + "template", + ".eslintrc" + ], "scripts": { + "build": "rm -rf lib && babel src --out-dir lib --ignore *.spec.js", "test": "npm run test:lint && npm run test:unit", "test:lint": "eslint .", - "test:unit": "mocha --compilers js:babel/register --recursive --reporter spec ./src", + "test:unit": "mocha --compilers js:babel-register --recursive --reporter spec ./src", "test:unit-watch": "npm run test:unit -- --watch", - "test:integration": "./bin/test-integration.sh", - "prepublish": "npm prune && npm test", + "test:integration": "npm run build && ./bin/test-integration.sh", + "prepublish": "not-in-install && npm prune && npm test && npm run build || in-install", "postinstall": "./bin/sagui install" }, "repository": { @@ -27,12 +34,16 @@ }, "homepage": "https://github.com/pirelenito/sagui#readme", "dependencies": { - "babel": "^5.8.23", - "babel-core": "^5.0.0", - "babel-eslint": "^4.1.3", - "babel-loader": "^5.1.2", - "babel-plugin-react-transform": "^1.1.1", - "babel-runtime": "^5.8.25", + "babel-core": "^6.4.0", + "babel-eslint": "^5.0.0", + "babel-loader": "^6.2.1", + "babel-plugin-react-transform": "^2.0.2", + "babel-plugin-transform-es2015-modules-commonjs": "^6.7.0", + "babel-plugin-transform-runtime": "^6.4.3", + "babel-preset-es2015": "^6.5.0", + "babel-preset-react": "^6.5.0", + "babel-preset-stage-0": "^6.5.0", + "babel-register": "^6.7.2", "chai": "^3.3.0", "chalk": "^1.1.1", "commander": "^2.8.1", @@ -60,7 +71,7 @@ "phantomjs-prebuilt": "^2.1.4", "postcss-loader": "^0.8.0", "postcss-modules-values": "^1.1.1", - "react-transform-hmr": "^1.0.0", + "react-transform-hmr": "^1.0.4", "resolve-url-loader": "^1.3.0", "rimraf": "^2.4.3", "sass-loader": "^3.0.0", @@ -72,5 +83,9 @@ "webpack-dev-middleware": "^1.2.0", "webpack-hot-middleware": "^2.0.0", "webpack-merge": "^0.7.3" + }, + "devDependencies": { + "babel-cli": "^6.6.5", + "in-publish": "^2.0.0" } } diff --git a/src/configure/webpack/plugins/archetype-library.spec.js b/src/configure/webpack/plugins/archetype-library.spec.js index 438c1dc..84ee3c5 100644 --- a/src/configure/webpack/plugins/archetype-library.spec.js +++ b/src/configure/webpack/plugins/archetype-library.spec.js @@ -1,6 +1,6 @@ import { join } from 'path' import { expect } from 'chai' -import { configure } from './archetype-library' +import plugin from './archetype-library' const saguiPath = join(__dirname, '../../../../') const projectPath = join(saguiPath, 'spec/fixtures/library-project') @@ -14,38 +14,38 @@ describe('configure webpack library', function () { } it('should have a single entry pointing to index.js', function () { - const webpackConfig = configure(baseConfiguration) + const webpackConfig = plugin.configure(baseConfiguration) expect(webpackConfig.entry).eql('./index.js') }) it('should have the default exporting target of commonjs2 (module.exports = xxx)', function () { - const webpackConfig = configure(baseConfiguration) + const webpackConfig = plugin.configure(baseConfiguration) expect(webpackConfig.output.libraryTarget).eql('commonjs2') }) it('should NOT SET the exporting target if buildTarget is test (a browser wont understand commonjs modules)', function () { - const webpackConfig = configure({ ...baseConfiguration, buildTarget: 'test' }) + const webpackConfig = plugin.configure({ ...baseConfiguration, buildTarget: 'test' }) expect(webpackConfig.output.libraryTarget).undefined }) it('should have the filename as index.js', function () { - const webpackConfig = configure(baseConfiguration) + const webpackConfig = plugin.configure(baseConfiguration) expect(webpackConfig.output.filename).eql('index.js') }) it('should have the output path configured as the dist folder', function () { - const webpackConfig = configure(baseConfiguration) + const webpackConfig = plugin.configure(baseConfiguration) expect(webpackConfig.output.path).eql(join(projectPath, 'dist')) }) describe('externals', function () { it('should infer the externals based on the packgage.json peerDependencies', function () { - const webpackConfig = configure(baseConfiguration) + const webpackConfig = plugin.configure(baseConfiguration) expect(webpackConfig.externals).eql(['react', 'react-dom']) }) it('should have an empty externals if the packgage.json does not have a peerDependencies', function () { - const webpackConfig = configure({ ...baseConfiguration, projectPath: projectWithoutPeerDependenciesPath }) + const webpackConfig = plugin.configure({ ...baseConfiguration, projectPath: projectWithoutPeerDependenciesPath }) expect(webpackConfig.externals).eql([]) }) }) diff --git a/src/configure/webpack/plugins/archetype-pages.spec.js b/src/configure/webpack/plugins/archetype-pages.spec.js index 23f1d55..d0d26f1 100644 --- a/src/configure/webpack/plugins/archetype-pages.spec.js +++ b/src/configure/webpack/plugins/archetype-pages.spec.js @@ -2,21 +2,21 @@ import HtmlWebpackPlugin from 'html-webpack-plugin' import { optimize } from 'webpack' import { expect } from 'chai' -import { configure } from './archetype-pages' +import plugin from './archetype-pages' const projectPath = '/tmp/projec-path' describe('configure webpack pages', function () { describe('undefined pages', function () { it('should return an empty configuration', function () { - const webpackConfig = configure({}) + const webpackConfig = plugin.configure({}) expect(webpackConfig).eql({}) }) }) describe('empty pages', function () { it('should return an empty configuration', function () { - const webpackConfig = configure({ pages: [] }) + const webpackConfig = plugin.configure({ pages: [] }) expect(webpackConfig).eql({}) }) }) @@ -25,12 +25,12 @@ describe('configure webpack pages', function () { const baseConfig = { pages: ['index'], projectPath } it('should have the output path configured as the dist folder', function () { - const webpackConfig = configure(baseConfig) + const webpackConfig = plugin.configure(baseConfig) expect(webpackConfig.output.path).eql('/tmp/projec-path/dist') }) it('should have the entrypoints setup with the index', function () { - const webpackConfig = configure(baseConfig) + const webpackConfig = plugin.configure(baseConfig) expect(webpackConfig.entry).eql({ index: ['./index'] @@ -38,7 +38,7 @@ describe('configure webpack pages', function () { }) it('should have a plugin seting up the HTML template', function () { - const webpackConfig = configure(baseConfig) + const webpackConfig = plugin.configure(baseConfig) const html = webpackConfig.plugins.filter(plugin => plugin instanceof HtmlWebpackPlugin) expect(html.length).equal(1) @@ -51,17 +51,17 @@ describe('configure webpack pages', function () { }) it('should setup the output filename of entrypoints based on the name of the page and hash', function () { - const webpackConfig = configure(baseConfig) + const webpackConfig = plugin.configure(baseConfig) expect(webpackConfig.output.filename).eql('[name]-[hash].js') }) it('should setup the output filename of other files based on their name and hash', function () { - const webpackConfig = configure(baseConfig) + const webpackConfig = plugin.configure(baseConfig) expect(webpackConfig.output.chunkFilename).eql('[name]-[hash].chunk.js') }) it('should NOT have the CommonsChunkPlugin enabled (not needed)', function () { - const webpackConfig = configure(baseConfig) + const webpackConfig = plugin.configure(baseConfig) const commons = webpackConfig.plugins.filter(plugin => plugin instanceof optimize.CommonsChunkPlugin) expect(commons.length).equal(0) @@ -72,7 +72,7 @@ describe('configure webpack pages', function () { const baseConfig = { pages: ['index', 'demo'], projectPath } it('should have two distinct entrypoints', function () { - const webpackConfig = configure(baseConfig) + const webpackConfig = plugin.configure(baseConfig) expect(webpackConfig.entry).eql({ index: ['./index'], @@ -81,7 +81,7 @@ describe('configure webpack pages', function () { }) it('should have a plugin seting up the HTML template for each chunk', function () { - const webpackConfig = configure(baseConfig) + const webpackConfig = plugin.configure(baseConfig) const html = webpackConfig.plugins.filter(plugin => plugin instanceof HtmlWebpackPlugin) expect(html.length).equal(2) @@ -98,7 +98,7 @@ describe('configure webpack pages', function () { }) it('should have the CommonsChunkPlugin enabled', function () { - const webpackConfig = configure(baseConfig) + const webpackConfig = plugin.configure(baseConfig) const commons = webpackConfig.plugins.filter(plugin => plugin instanceof optimize.CommonsChunkPlugin) expect(commons.length).equal(1) @@ -107,7 +107,7 @@ describe('configure webpack pages', function () { // Karma has an issue with the CommonsChunk plugin // see: https://github.com/webpack/karma-webpack/issues/24 it('should NOT have the CommonsChunkPlugin enabled if buildTarget is test (breaks Karma)', function () { - const webpackConfig = configure({ ...baseConfig, buildTarget: 'test' }) + const webpackConfig = plugin.configure({ ...baseConfig, buildTarget: 'test' }) const commons = webpackConfig.plugins.filter(plugin => plugin instanceof optimize.CommonsChunkPlugin) expect(commons.length).equal(0) diff --git a/src/configure/webpack/plugins/babel.js b/src/configure/webpack/plugins/babel.js index eb43cb2..c65c021 100644 --- a/src/configure/webpack/plugins/babel.js +++ b/src/configure/webpack/plugins/babel.js @@ -1,4 +1,7 @@ import reactTransform from 'babel-plugin-react-transform' +import es2015 from 'babel-preset-es2015' +import stage0 from 'babel-preset-stage-0' +import react from 'babel-preset-react' export default { name: 'webpack-babel', @@ -20,8 +23,7 @@ export default { return { babel: { - optional: ['runtime'], - stage: 0, + presets: [es2015, stage0, react], env: buildTarget === 'develop' ? hmrEnv : {} }, diff --git a/src/configure/webpack/plugins/base.spec.js b/src/configure/webpack/plugins/base.spec.js index 6f5bfeb..ef847d0 100644 --- a/src/configure/webpack/plugins/base.spec.js +++ b/src/configure/webpack/plugins/base.spec.js @@ -2,7 +2,7 @@ import { expect } from 'chai' import { join } from 'path' import { HotModuleReplacementPlugin, optimize } from 'webpack' -import { configure } from './base' +import plugin from './base' const saguiPath = join(__dirname, '../../../../') const projectPath = join(saguiPath, 'spec/fixtures/simple-project') @@ -10,14 +10,14 @@ const projectPath = join(saguiPath, 'spec/fixtures/simple-project') describe('configure webpack base', function () { describe('targets', function () { it('should have the UglifyJsPlugin enabled while distributing', function () { - const config = configure({ projectPath, saguiPath, buildTarget: 'dist' }) + const config = plugin.configure({ projectPath, saguiPath, buildTarget: 'dist' }) const commons = config.plugins.filter(plugin => plugin instanceof optimize.UglifyJsPlugin) expect(commons.length).equal(1) }) it('should have the HotModuleReplacementPlugin enabled while developing', function () { - const config = configure({ projectPath, saguiPath, buildTarget: 'develop' }) + const config = plugin.configure({ projectPath, saguiPath, buildTarget: 'develop' }) const commons = config.plugins.filter(plugin => plugin instanceof HotModuleReplacementPlugin) expect(commons.length).equal(1) diff --git a/src/configure/webpack/plugins/json.spec.js b/src/configure/webpack/plugins/json.spec.js index 26e3567..60bcad3 100644 --- a/src/configure/webpack/plugins/json.spec.js +++ b/src/configure/webpack/plugins/json.spec.js @@ -1,10 +1,10 @@ import { expect } from 'chai' -import { configure } from './json' +import plugin from './json' describe('configure webpack json', function () { it('should have a JSON loader', function () { - const webpackConfig = configure({}) + const webpackConfig = plugin.configure({}) const loader = webpackConfig.module.loaders.find(loader => loader.loader === 'json-loader') expect(loader.test).eql(/\.(json)$/) })