From 4d4bc04f4aff98620a303ac9cc45848c0f363d8a Mon Sep 17 00:00:00 2001 From: Yann Gouffon Date: Tue, 17 May 2016 13:06:48 +0200 Subject: [PATCH 1/7] fix path --- app/templates/assets/templates/page.html.swig | 2 +- .../styleguide/item-content.html.swig | 2 +- app/templates/tasks/metalsmith.js | 7 +++++- component/index.js | 22 ++++++++++--------- component/templates/_component.html | 3 ++- component/templates/_page.html | 3 ++- 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/app/templates/assets/templates/page.html.swig b/app/templates/assets/templates/page.html.swig index a894b26..dcc8d3c 100644 --- a/app/templates/assets/templates/page.html.swig +++ b/app/templates/assets/templates/page.html.swig @@ -1,7 +1,7 @@ {% extends "base.html.swig" %} {% block content %} - {% set path = '../components/pages/' + title + '.html.swig' %} + {% set path = '../components/pages/' + name + '.html.swig' %}
{% include path %}
diff --git a/app/templates/assets/templates/styleguide/item-content.html.swig b/app/templates/assets/templates/styleguide/item-content.html.swig index 1a7b646..1a3f325 100644 --- a/app/templates/assets/templates/styleguide/item-content.html.swig +++ b/app/templates/assets/templates/styleguide/item-content.html.swig @@ -1,5 +1,5 @@ {% macro default(type, content) %} - {% set path = '../../components/' + type + 's/' + content.title + '.html.swig' %} + {% set path = '../../components/' + type + 's/' + content.name + '.html.swig' %} {% if content.notes %}
{{content.notes|markdown|raw}} diff --git a/app/templates/tasks/metalsmith.js b/app/templates/tasks/metalsmith.js index 5649268..6cd481e 100644 --- a/app/templates/tasks/metalsmith.js +++ b/app/templates/tasks/metalsmith.js @@ -16,12 +16,17 @@ var path = require('path'), collections = require('metalsmith-collections'); var metadatas = []; -dotenv.load(); require('./filters.js')(); var contentful_key = ''; + if (process.env.CONTENTFUL_KEY) { contentful_key = process.env.CONTENTFUL_KEY; +} else { + dotenv.load(); + if (process.env.CONTENTFUL_KEY) { + contentful_key = process.env.CONTENTFUL_KEY; + } } module.exports = function() { diff --git a/component/index.js b/component/index.js index cbfb331..26c03b4 100644 --- a/component/index.js +++ b/component/index.js @@ -87,18 +87,20 @@ module.exports = yeoman.Base.extend({ this.log(chalk.red(slug(this.name).toLowerCase() + " already founded !") + "\nMake sure that your component doens't already exist."); } - var stylesheet = this.destinationPath(this.config.assets + 'sass/main.scss'), - importer = "@import '"+ this.type +"/"+ slug(this.name).toLowerCase() + "';"; - if(pathExists.sync(stylesheet)){ - var body = fs.readFileSync(stylesheet).toString(); - if (body.indexOf(importer) < 0 ) { - body = body.replace("// "+ this.type +":", "// "+ this.type +":\n"+importer); - fs.writeFileSync(stylesheet, body); + if (this.type !== 'doc') { + var stylesheet = this.destinationPath(this.config.assets + 'sass/main.scss'), + importer = "@import '"+ this.type +"/"+ slug(this.name).toLowerCase() + "';"; + if(pathExists.sync(stylesheet)){ + var body = fs.readFileSync(stylesheet).toString(); + if (body.indexOf(importer) < 0 ) { + body = body.replace("// "+ this.type +":", "// "+ this.type +":\n"+importer); + fs.writeFileSync(stylesheet, body); + } else { + this.log(chalk.red(importer + " already founded !") + "\nMake sure that your component doens't already exist."); + } } else { - this.log(chalk.red(importer + " already founded !") + "\nMake sure that your component doens't already exist."); + this.log(chalk.red("No main.sccs founded !") + "\nMake sure that your main.scss file is at the root of your sass folder."); } - } else { - this.log(chalk.red("No main.sccs founded !") + "\nMake sure that your main.scss file is at the root of your sass folder."); } } } diff --git a/component/templates/_component.html b/component/templates/_component.html index b6b2c47..a2ab1e4 100644 --- a/component/templates/_component.html +++ b/component/templates/_component.html @@ -1,5 +1,6 @@ --- -title: <%= slug(name).toLowerCase() %> +title: <%= name %> +name: <%= slug(name).toLowerCase() %> collection: <%= type %> notes: | ##### Usage : `<%= slug(name).toLowerCase() %>` diff --git a/component/templates/_page.html b/component/templates/_page.html index 4175a06..2119bd8 100644 --- a/component/templates/_page.html +++ b/component/templates/_page.html @@ -1,5 +1,6 @@ --- -title: <%= slug(name).toLowerCase() %> +title: <%= name %> +name: <%= slug(name).toLowerCase() %> collection: pages styleguide: false layout: page.html.swig From 4834731a0805e3a2b8dd620393bc85fd8ad2b79d Mon Sep 17 00:00:00 2001 From: Yann Gouffon Date: Tue, 17 May 2016 13:37:38 +0200 Subject: [PATCH 2/7] lowerify doc links --- app/templates/assets/templates/styleguide/menu.html.swig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/assets/templates/styleguide/menu.html.swig b/app/templates/assets/templates/styleguide/menu.html.swig index a1539e7..710e8b2 100644 --- a/app/templates/assets/templates/styleguide/menu.html.swig +++ b/app/templates/assets/templates/styleguide/menu.html.swig @@ -14,7 +14,7 @@ From 944ba73def552d18c2a7b2feea0c62bd3e4332d3 Mon Sep 17 00:00:00 2001 From: Yann Gouffon Date: Tue, 17 May 2016 14:30:26 +0200 Subject: [PATCH 3/7] better comment filter --- app/templates/assets/sass/styleguide-variables.scss | 10 +++++----- app/templates/assets/templates/base.html.swig | 8 +------- app/templates/assets/templates/page.html.swig | 10 ---------- app/templates/tasks/metalsmith.js | 7 +++++++ 4 files changed, 13 insertions(+), 22 deletions(-) diff --git a/app/templates/assets/sass/styleguide-variables.scss b/app/templates/assets/sass/styleguide-variables.scss index ff551bc..e5a7f67 100644 --- a/app/templates/assets/sass/styleguide-variables.scss +++ b/app/templates/assets/sass/styleguide-variables.scss @@ -1,5 +1,5 @@ -$accent-color: #f04c00; -$heading-color: #fff; -$text-color: #242426; -$menu-bg: #28313a; -$menu-fg: #e3eaf3; +$accent-color: #f04c00; +$heading-color: #fff; +$text-color: #242426; +$menu-bg: #28313a; +$menu-fg: #e3eaf3; diff --git a/app/templates/assets/templates/base.html.swig b/app/templates/assets/templates/base.html.swig index d37bc3d..3950b50 100644 --- a/app/templates/assets/templates/base.html.swig +++ b/app/templates/assets/templates/base.html.swig @@ -47,14 +47,8 @@ {% endblock %} diff --git a/app/templates/tasks/metalsmith.js b/app/templates/tasks/metalsmith.js index 6cd481e..75cf54d 100644 --- a/app/templates/tasks/metalsmith.js +++ b/app/templates/tasks/metalsmith.js @@ -73,6 +73,13 @@ module.exports = function() { accessToken : contentful_key }), layouts(config.metalsmith.plugins.layouts), + function(files, metalsmith, done){ + // Clean dirty front-matter comment + for (var file in files) { + files[file].contents = new Buffer(files[file].contents.toString().replace(/---[\s\S]*?---/g, '')); + } + done(); + }, permalinks(config.metalsmith.plugins.permalinks) ] })) From 35bbdeab52d201410accf3130aae28c65e906f67 Mon Sep 17 00:00:00 2001 From: Yann Gouffon Date: Thu, 19 May 2016 23:35:12 +0200 Subject: [PATCH 4/7] remove duplicated components page heading --- app/templates/assets/templates/atoms.html.swig | 6 ++---- app/templates/assets/templates/molecules.html.swig | 6 ++---- app/templates/assets/templates/organisms.html.swig | 6 ++---- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/app/templates/assets/templates/atoms.html.swig b/app/templates/assets/templates/atoms.html.swig index 5ab5a6f..ef4b915 100644 --- a/app/templates/assets/templates/atoms.html.swig +++ b/app/templates/assets/templates/atoms.html.swig @@ -7,16 +7,14 @@ {% if collections.atoms.length > 0 %}
-

Atoms

- {{contents|raw}} +
{{contents|raw}}
{% for atom in collections.atoms %} {{item.default('atom' ,atom, loop)}} {% endfor %} {% else %}
-

Atoms

- {{contents|raw}} +
{{contents|raw}}
{% endif %} diff --git a/app/templates/assets/templates/molecules.html.swig b/app/templates/assets/templates/molecules.html.swig index 81290fd..57b8242 100644 --- a/app/templates/assets/templates/molecules.html.swig +++ b/app/templates/assets/templates/molecules.html.swig @@ -7,16 +7,14 @@ {% if collections.molecules.length > 0 %}
-

Molecules

- {{contents|raw}} +
{{contents|raw}}
{% for molecule in collections.molecules %} {{item.default('molecule', molecule, loop)}} {% endfor %} {% else %}
-

molecules

- {{contents|raw}} +
{{contents|raw}}
{% endif %} diff --git a/app/templates/assets/templates/organisms.html.swig b/app/templates/assets/templates/organisms.html.swig index 88d93a2..c446e8a 100644 --- a/app/templates/assets/templates/organisms.html.swig +++ b/app/templates/assets/templates/organisms.html.swig @@ -7,16 +7,14 @@ {% if collections.organisms.length > 0 %}
-

Organisms

- {{contents|raw}} +
{{contents|raw}}
{% for organism in collections.organisms %} {{item.default('organism', organism, loop)}} {% endfor %} {% else %}
-

organisms

- {{contents|raw}} +
{{contents|raw}}
{% endif %} From d9979224ab84a68cdbdc74759edfafd5bb5b5cfb Mon Sep 17 00:00:00 2001 From: Yann Gouffon Date: Tue, 14 Jun 2016 17:29:06 +0200 Subject: [PATCH 5/7] small fixes --- app/templates/assets/templates/base.html.swig | 2 +- app/templates/tasks/filters.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/templates/assets/templates/base.html.swig b/app/templates/assets/templates/base.html.swig index 3950b50..9f6e279 100644 --- a/app/templates/assets/templates/base.html.swig +++ b/app/templates/assets/templates/base.html.swig @@ -5,7 +5,7 @@ - + diff --git a/app/templates/tasks/filters.js b/app/templates/tasks/filters.js index 618f225..45c5cf7 100644 --- a/app/templates/tasks/filters.js +++ b/app/templates/tasks/filters.js @@ -17,7 +17,7 @@ module.exports = function() { var obj = {}; if (array) { for (var i = 0; i < array.length; i++) { - if (array[i].data.sys.id == value) { + if (array[i].id == value) { obj = array[i]; } } From d59d0d010ee6fd9cee7fb39f9fee6234036b04a3 Mon Sep 17 00:00:00 2001 From: Yann Gouffon Date: Tue, 14 Jun 2016 17:36:48 +0200 Subject: [PATCH 6/7] move to a much modern way to write ES2015 with module import --- app/templates/_package.json | 5 ++ app/templates/assets/js/index.js | 2 + app/templates/assets/js/main.js | 5 -- app/templates/tasks/scripts.js | 86 ++++++++++++++++++++++++++------ 4 files changed, 79 insertions(+), 19 deletions(-) create mode 100644 app/templates/assets/js/index.js delete mode 100644 app/templates/assets/js/main.js diff --git a/app/templates/_package.json b/app/templates/_package.json index e014945..bcc4382 100644 --- a/app/templates/_package.json +++ b/app/templates/_package.json @@ -2,6 +2,7 @@ "name": "<%= slug(name).toLowerCase() %>", "version": "0.0.0", "main": "index.html", + "browserify-shim": {}, "dependencies": {<% if (bootstrap4) { %> "bootstrap": "git@github.com:twbs/bootstrap.git#v4-dev",<% } else if (bootstrapSass) { %> "bootstrap-sass": "~3.3.5",<% } %> @@ -15,7 +16,9 @@ "babel-core": "6.8.0", "babel-loader": "6.2.4", "babel-preset-es2015": "^6.6.0", + "babelify": "^7.3.0", "browser-sync": "^2.7.1", + "browserify-shim": "^3.8.12", "casperjs": "^1.1.0-beta3", "chai": "^3.4.1", "contentful-metalsmith": "^0.1.0", @@ -76,6 +79,8 @@ "stylelint": "^6.2.2", "swig": "^1.4.2", "toolbox-utils": "^0.0.2", + "vinyl-buffer": "^1.0.0", + "vinyl-source-stream": "^1.1.0", "yargs": "^4.3.2" } } diff --git a/app/templates/assets/js/index.js b/app/templates/assets/js/index.js new file mode 100644 index 0000000..51cb3c5 --- /dev/null +++ b/app/templates/assets/js/index.js @@ -0,0 +1,2 @@ +// You will use that file to import all your scripts +// Ex: import gallery from './gallery'; diff --git a/app/templates/assets/js/main.js b/app/templates/assets/js/main.js deleted file mode 100644 index 4871fae..0000000 --- a/app/templates/assets/js/main.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -(function(){ - -}()); diff --git a/app/templates/tasks/scripts.js b/app/templates/tasks/scripts.js index cd6f1b9..bd9c98d 100644 --- a/app/templates/tasks/scripts.js +++ b/app/templates/tasks/scripts.js @@ -1,35 +1,93 @@ 'use strict'; -var gulp = require('gulp'), - $ = require('gulp-load-plugins')(), - config = require('../gulp_config.json'), - argv = require('yargs').argv; +var gulp = require('gulp'), + $ = require('gulp-load-plugins')(), + config = require('../gulp_config.json'), + argv = require('yargs').argv, + browserify = require('browserify'), + babelify = require('babelify'), + browserifyshim = require('browserify-shim'), + source = require('vinyl-source-stream'), + buffer = require('vinyl-buffer'), + path = require('path'); + module.exports = function() { function errorAlert(error){ if (!argv.production) { - $.notify.onError({title: "JS Error", message: "Check your terminal", sound: "Sosumi"})(error); + $.notify.onError({title: 'JS Error', message: 'Check your terminal', sound: 'Sosumi'})(error); $.util.log(error.messageFormatted); } - this.emit("end"); + this.emit('end'); }; + function handleErrors() { + var args = Array.prototype.slice.call(arguments); + $.notify.onError({ + title: 'Compile Error', + message: '<%= error.message %>' + }).apply(this, args); + this.emit('end'); + } + /** * Build JS * With error reporting on compiling (so that there's no crash) * And jshint check to highlight errors as we go. */ - gulp.task('scripts', function() { - return gulp.src(config.assets + 'js/*.js') + gulp.task('scripts', ['scripts-lint'], function() { + if (argv.local) { + return browserify( + { + entries: ['./' + config.assets + 'js/index.js'], + debug: true + }) + .transform(babelify.configure({ + presets: ['es2015'], + sourceMaps: true + })) + .bundle() + .on('error', handleErrors) + .pipe(source('bundle.js')) + .pipe(buffer()) + .pipe($.sourcemaps.init({loadMaps: true})) + .pipe($.if(argv.production, $.uglify())) + .on('error', handleErrors) + .pipe(argv.production ? $.util.noop() : $.sourcemaps.write('./')) + .pipe(gulp.dest(config.build)); + } else { + return browserify( + { + entries: ['./' + config.assets + 'js/index.js'], + debug: true + }) + .transform(babelify.configure({ + presets: ['es2015'], + sourceMaps: true + })) + .transform(browserifyshim) + .bundle() + .on('error', handleErrors) + .pipe(source('bundle.js')) + .pipe(buffer()) + .pipe($.sourcemaps.init({loadMaps: true})) + .pipe($.if(argv.production, $.uglify())) + .on('error', handleErrors) + .pipe(argv.production ? $.util.noop() : $.sourcemaps.write('./')) + .pipe($.size({title: 'BUNDLE SIZE', showFiles: true})) + .pipe(gulp.dest(config.build)); + } + }); + + /** + * Lint JS + */ + gulp.task('scripts-lint', function() { + return gulp.src(config.assets + '**/*.{js,jsx}') .pipe($.plumber({errorHandler: errorAlert})) .pipe($.eslint()) - .pipe($.eslint.format()) - .pipe($.babel({presets: ['es2015']})) - .pipe($.concat('main.js')) - .pipe($.if(argv.production, $.uglify())) - .pipe($.size({title: 'JS SCRIPTS', showFiles: true})) - .pipe(gulp.dest(config.build + 'js')); + .pipe($.eslint.format()); }); }; From b158130b7be5bfae1dab8b1055991bec45a31aef Mon Sep 17 00:00:00 2001 From: Yann Gouffon Date: Tue, 14 Jun 2016 17:37:28 +0200 Subject: [PATCH 7/7] bump version to 0.5.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 26cb8ea..e7f9a31 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "generator-toolbox", - "version": "0.5.2", + "version": "0.5.3", "description": "Yeoman generator", "license": "MIT", "main": "app/index.js",