|
| 1 | +/****************************************************** |
| 2 | + * PATTERN LAB NODE |
| 3 | + * EDITION-NODE-GRUNT |
| 4 | + * The grunt wrapper around patternlab-node core, providing tasks to interact with the core library and move supporting frontend assets. |
| 5 | +******************************************************/ |
| 6 | + |
| 7 | +module.exports = function (grunt) { |
| 8 | + |
| 9 | + var path = require('path'), |
| 10 | + argv = require('minimist')(process.argv.slice(2)); |
| 11 | + |
| 12 | + // load all grunt tasks |
| 13 | + grunt.loadNpmTasks('grunt-contrib-copy'); |
| 14 | + grunt.loadNpmTasks('grunt-contrib-watch'); |
| 15 | + grunt.loadNpmTasks('grunt-browser-sync'); |
| 16 | + |
| 17 | + /****************************************************** |
| 18 | + * PATTERN LAB CONFIGURATION |
| 19 | + ******************************************************/ |
| 20 | + |
| 21 | + //read all paths from our namespaced config file |
| 22 | + var config = require('./patternlab-config.json'), |
| 23 | + pl = require('patternlab-node')(config); |
| 24 | + |
| 25 | + function paths() { |
| 26 | + return config.paths; |
| 27 | + } |
| 28 | + |
| 29 | + function getConfiguredCleanOption() { |
| 30 | + return config.cleanPublic; |
| 31 | + } |
| 32 | + |
| 33 | + grunt.registerTask('patternlab', 'create design systems with atomic design', function (arg) { |
| 34 | + |
| 35 | + if (arguments.length === 0) { |
| 36 | + pl.build(function(){}, getConfiguredCleanOption()); |
| 37 | + } |
| 38 | + |
| 39 | + if (arg && arg === 'version') { |
| 40 | + pl.version(); |
| 41 | + } |
| 42 | + |
| 43 | + if (arg && arg === "patternsonly") { |
| 44 | + pl.patternsonly(function(){},getConfiguredCleanOption()); |
| 45 | + } |
| 46 | + |
| 47 | + if (arg && arg === "help") { |
| 48 | + pl.help(); |
| 49 | + } |
| 50 | + |
| 51 | + if (arg && arg === "starterkit-list") { |
| 52 | + pl.liststarterkits(); |
| 53 | + } |
| 54 | + |
| 55 | + if (arg && arg === "starterkit-load") { |
| 56 | + pl.loadstarterkit(argv.kit); |
| 57 | + } |
| 58 | + |
| 59 | + if (arg && (arg !== "version" && arg !== "patternsonly" && arg !== "help" && arg !== "starterkit-list" && arg !== "starterkit-load")) { |
| 60 | + pl.help(); |
| 61 | + } |
| 62 | + }); |
| 63 | + |
| 64 | + |
| 65 | + grunt.initConfig({ |
| 66 | + |
| 67 | + /****************************************************** |
| 68 | + * COPY TASKS |
| 69 | + ******************************************************/ |
| 70 | + copy: { |
| 71 | + main: { |
| 72 | + files: [ |
| 73 | + { expand: true, cwd: path.resolve(paths().source.js), src: '**/*.js', dest: path.resolve(paths().public.js) }, |
| 74 | + { expand: true, cwd: path.resolve(paths().source.css), src: '*.css', dest: path.resolve(paths().public.css) }, |
| 75 | + { expand: true, cwd: path.resolve(paths().source.images), src: '*', dest: path.resolve(paths().public.images) }, |
| 76 | + { expand: true, cwd: path.resolve(paths().source.fonts), src: '*', dest: path.resolve(paths().public.fonts) }, |
| 77 | + { expand: true, cwd: path.resolve(paths().source.root), src: 'favicon.ico', dest: path.resolve(paths().public.root) }, |
| 78 | + { expand: true, cwd: path.resolve(paths().source.styleguide), src: ['*', '**'], dest: path.resolve(paths().public.root) }, |
| 79 | + // slightly inefficient to do this again - I am not a grunt glob master. someone fix |
| 80 | + { expand: true, flatten: true, cwd: path.resolve(paths().source.styleguide, 'styleguide', 'css', 'custom'), src: '*.css)', dest: path.resolve(paths().public.styleguide, 'css') } |
| 81 | + ] |
| 82 | + } |
| 83 | + }, |
| 84 | + /****************************************************** |
| 85 | + * SERVER AND WATCH TASKS |
| 86 | + ******************************************************/ |
| 87 | + watch: { |
| 88 | + all: { |
| 89 | + files: [ |
| 90 | + path.resolve(paths().source.css + '**/*.css'), |
| 91 | + path.resolve(paths().source.styleguide + 'css/*.css'), |
| 92 | + path.resolve(paths().source.patterns + '**/*'), |
| 93 | + path.resolve(paths().source.fonts + '/*'), |
| 94 | + path.resolve(paths().source.images + '/*'), |
| 95 | + path.resolve(paths().source.data + '*.json'), |
| 96 | + path.resolve(paths().source.js + '/*.js'), |
| 97 | + path.resolve(paths().source.root + '/*.ico') |
| 98 | + ], |
| 99 | + tasks: ['default', 'bsReload:css'] |
| 100 | + } |
| 101 | + }, |
| 102 | + browserSync: { |
| 103 | + dev: { |
| 104 | + options: { |
| 105 | + server: path.resolve(paths().public.root), |
| 106 | + watchTask: true, |
| 107 | + watchOptions: { |
| 108 | + ignoreInitial: true, |
| 109 | + ignored: '*.html' |
| 110 | + }, |
| 111 | + snippetOptions: { |
| 112 | + // Ignore all HTML files within the templates folder |
| 113 | + blacklist: ['/index.html', '/', '/?*'] |
| 114 | + }, |
| 115 | + plugins: [ |
| 116 | + { |
| 117 | + module: 'bs-html-injector', |
| 118 | + options: { |
| 119 | + files: [path.resolve(paths().public.root + '/index.html'), path.resolve(paths().public.styleguide + '/styleguide.html')] |
| 120 | + } |
| 121 | + } |
| 122 | + ], |
| 123 | + notify: { |
| 124 | + styles: [ |
| 125 | + 'display: none', |
| 126 | + 'padding: 15px', |
| 127 | + 'font-family: sans-serif', |
| 128 | + 'position: fixed', |
| 129 | + 'font-size: 1em', |
| 130 | + 'z-index: 9999', |
| 131 | + 'bottom: 0px', |
| 132 | + 'right: 0px', |
| 133 | + 'border-top-left-radius: 5px', |
| 134 | + 'background-color: #1B2032', |
| 135 | + 'opacity: 0.4', |
| 136 | + 'margin: 0', |
| 137 | + 'color: white', |
| 138 | + 'text-align: center' |
| 139 | + ] |
| 140 | + } |
| 141 | + } |
| 142 | + } |
| 143 | + }, |
| 144 | + bsReload: { |
| 145 | + css: path.resolve(paths().public.root + '**/*.css') |
| 146 | + } |
| 147 | + }); |
| 148 | + |
| 149 | + /****************************************************** |
| 150 | + * COMPOUND TASKS |
| 151 | + ******************************************************/ |
| 152 | + |
| 153 | + grunt.registerTask('default', ['patternlab', 'copy:main']); |
| 154 | + grunt.registerTask('patternlab:watch', ['patternlab', 'copy:main', 'watch:all']); |
| 155 | + grunt.registerTask('patternlab:serve', ['patternlab', 'copy:main', 'browserSync', 'watch:all']); |
| 156 | + |
| 157 | +}; |
0 commit comments