├── .editorconfig ├── .gitignore ├── index.js ├── lib ├── cloneRepo.js ├── color.js ├── copy.js ├── createDir.js ├── createFile.js ├── del.js ├── exists.js ├── installPackages.js ├── log.js ├── prefix.js └── questions.js ├── license ├── package.json ├── readme.md └── src ├── .babelrc ├── .browserslistrc ├── .editorconfig ├── .gitignore ├── README.md └── mconfig.json /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 4 7 | indent_style = space 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | 14 | [{*.yml,*.json}] 15 | indent_size = 2 16 | indent_style = space 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | package-lock.json 4 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const { spawn, spawnSync } = require('child_process'); 3 | const commander = require('commander'); 4 | const inquirer = require('inquirer'); 5 | const log = require('./lib/log'); 6 | const cloneRepo = require('./lib/cloneRepo'); 7 | const exists = require('./lib/exists'); 8 | const del = require('./lib/del'); 9 | const createFile = require('./lib/createFile'); 10 | const installPackages = require('./lib/installPackages'); 11 | const copy = require('./lib/copy'); 12 | const createDir = require('./lib/createDir'); 13 | const prefix = require('./lib/prefix'); 14 | let questions = require('./lib/questions'); 15 | 16 | const dependencies = { 17 | gulp: ['build', 'error', 'notify', 'serve', 'svg', 'watch'] 18 | }; 19 | 20 | commander 21 | .command('init [repo] [dest]') 22 | .action((repo, dest) => initQuestions(repo, dest)); 23 | 24 | commander.parse(process.argv); 25 | 26 | function initQuestions(repo, dest = '.') { 27 | log(`👋 Hey, let's init your project.`); 28 | 29 | if (repo) { 30 | cloneRepo(repo, dest); 31 | } 32 | 33 | let destFolder = ''; 34 | if (dest != '.') { 35 | destFolder = '/' + dest; 36 | } 37 | 38 | let config; 39 | if (exists(`${dest}/mconfig.json`)) { 40 | let newQuestions = []; 41 | config = require(process.cwd() + destFolder + '/mconfig.json'); 42 | 43 | if (config.modules) { 44 | for (let key in questions) { 45 | if(!(questions[key].name in config.modules)) { 46 | newQuestions.push(questions[key]); 47 | } 48 | } 49 | 50 | questions = newQuestions; 51 | } 52 | } 53 | 54 | if (questions.length != 0) { 55 | inquirer 56 | .prompt(questions) 57 | .then(answers => { 58 | if (config && config.modules) { 59 | answers = Object.assign(answers, config.modules); 60 | } 61 | init(config, answers, repo, dest); 62 | }); 63 | } else { 64 | init(config, config.modules, repo, dest); 65 | } 66 | } 67 | 68 | function init(config, answers, repo, dest) { 69 | log(`👌 All good, installing everything for you.`); 70 | 71 | if (exists(`${dest}/package.json`)) { 72 | installPackages(null, dest); 73 | } else { 74 | createFile(`${dest}/package.json`, '{}'); 75 | } 76 | 77 | installPackages('mbp', dest); 78 | 79 | const org = '@modularbp/' 80 | const build = answers.build; 81 | 82 | delete answers.build; 83 | 84 | let packages = []; 85 | let mjs = false; 86 | 87 | packages.push(org + build); 88 | 89 | Object.keys(answers).map(function(key) { 90 | let value = answers[key]; 91 | 92 | if (value == 'mjs') { 93 | packages.push(org + value); 94 | value = 'js'; 95 | mjs = true; 96 | } 97 | 98 | if (value) { 99 | packages.push(org + build + '-' + value); 100 | } 101 | }); 102 | 103 | if (dependencies[build]) { 104 | packages.push(...dependencies[build].map(value => org + build + '-' + value)); 105 | } 106 | 107 | copy([`${dest}/node_modules/mbp/src/**/*`, `${dest}/node_modules/mbp/src/**/.*`], `${dest}/`); 108 | 109 | if (!config) { 110 | let destFolder = ''; 111 | if (dest != '.') { 112 | destFolder = '/' + dest; 113 | } 114 | 115 | config = require(process.cwd() + destFolder + '/mconfig.json'); 116 | } 117 | 118 | installPackages(packages, dest); 119 | 120 | if (mjs) { 121 | installPackages('modujs', dest, false); 122 | } 123 | 124 | copy(`${dest}/node_modules/${org}${build}/src/*`, `${dest}/`); 125 | copy(`${dest}/node_modules/${org}${build}-*/src/*`, prefix(config.build, dest)); 126 | copy(`${dest}/node_modules/${org}mjs/src/*`, prefix(config.scripts.src, dest)); 127 | copy(`${dest}/node_modules/${org}mjs/src/modules/*`, prefix(`${config.scripts.src}/modules/`, dest)); 128 | 129 | createDir(prefix(config.styles.src, dest)); 130 | createDir(prefix(config.scripts.src, dest)); 131 | createDir(prefix(config.svgs.src, dest)); 132 | createDir(prefix(config.views.src, dest)); 133 | createDir(prefix(config.views.partials, dest)); 134 | 135 | log(`👊 Ready to go, you can now run ${build}`); 136 | } 137 | -------------------------------------------------------------------------------- /lib/cloneRepo.js: -------------------------------------------------------------------------------- 1 | const { spawnSync } = require('child_process'); 2 | const del = require('./del'); 3 | const log = require('./log'); 4 | 5 | function cloneRepo(repo, dest) { 6 | const spawn = spawnSync('git', ['clone', 'https://github.com/'+ repo, dest]); 7 | const message = spawn.stderr.toString().trim(); 8 | 9 | if (spawn.status == 0) { 10 | log(message, 'green'); 11 | del(dest + '/.git'); 12 | } else { 13 | log(message, 'red'); 14 | process.exit(); 15 | } 16 | } 17 | 18 | module.exports = cloneRepo; 19 | -------------------------------------------------------------------------------- /lib/color.js: -------------------------------------------------------------------------------- 1 | const styles = { 2 | reset: '\x1b[0m', 3 | bright: '\x1b[1m', 4 | dim: '\x1b[2m', 5 | underscore: '\x1b[4m', 6 | blink: '\x1b[5m', 7 | reverse: '\x1b[7m', 8 | hidden: '\x1b[8m', 9 | 10 | black: '\x1b[30m', 11 | red: '\x1b[31m', 12 | green: '\x1b[32m', 13 | yellow: '\x1b[33m', 14 | blue: '\x1b[34m', 15 | magenta: '\x1b[35m', 16 | cyan: '\x1b[36m', 17 | white: '\x1b[37m', 18 | 19 | bgblack: '\x1b[40m', 20 | bgred: '\x1b[41m', 21 | bggreen: '\x1b[42m', 22 | bgyellow: '\x1b[43m', 23 | bgblue: '\x1b[44m', 24 | bgmagenta: '\x1b[45m', 25 | bgcyan: '\x1b[46m', 26 | bgwhite: '\x1b[47m' 27 | } 28 | 29 | function color(message, style) { 30 | style = styles[style]; 31 | 32 | return style + message; 33 | } 34 | 35 | module.exports = color; 36 | -------------------------------------------------------------------------------- /lib/copy.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const path = require('path'); 3 | const glob = require('fast-glob'); 4 | const createDir = require('./createDir'); 5 | const exists = require('./exists'); 6 | 7 | function copy(src, dest) { 8 | createDir(dest); 9 | 10 | src = glob.sync(src); 11 | 12 | src.forEach((file) => { 13 | copyFile(file, dest); 14 | }) 15 | } 16 | 17 | function copyFile(src, dest) { 18 | const file = path.basename(src); 19 | const destFile = dest + file; 20 | let filePath = dest + file; 21 | 22 | if (!exists(filePath)) { 23 | fs.copyFileSync(src, destFile); 24 | } 25 | } 26 | 27 | module.exports = copy; 28 | -------------------------------------------------------------------------------- /lib/createDir.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const exists = require('./exists'); 3 | 4 | function createDir(path) { 5 | if (path) { 6 | const dirs = path.split('/'); 7 | let currentDirs = ''; 8 | 9 | dirs.forEach((dir) => { 10 | currentDirs += dir + '/'; 11 | 12 | if (!exists(currentDirs)) { 13 | fs.mkdirSync(currentDirs); 14 | } 15 | }) 16 | } 17 | } 18 | 19 | module.exports = createDir; 20 | -------------------------------------------------------------------------------- /lib/createFile.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const exists = require('./exists'); 3 | 4 | function createFile(path, data) { 5 | if (!exists(path)) { 6 | fs.writeFileSync(path, data); 7 | } 8 | } 9 | 10 | module.exports = createFile; 11 | -------------------------------------------------------------------------------- /lib/del.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const exists = require('./exists'); 3 | 4 | function del(path) { 5 | if (exists(path)) { 6 | const files = fs.readdirSync(path); 7 | 8 | files.forEach((file, index) => { 9 | var curPath = path + "/" + file; 10 | 11 | if(fs.lstatSync(curPath).isDirectory()) { 12 | del(curPath); 13 | } else { 14 | fs.unlinkSync(curPath); 15 | } 16 | }); 17 | 18 | fs.rmdirSync(path); 19 | } 20 | } 21 | 22 | module.exports = del; 23 | -------------------------------------------------------------------------------- /lib/exists.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | 3 | function exists(path) { 4 | if (fs.existsSync(path)) { 5 | return true; 6 | } else { 7 | return false; 8 | } 9 | } 10 | 11 | module.exports = exists; 12 | -------------------------------------------------------------------------------- /lib/installPackages.js: -------------------------------------------------------------------------------- 1 | const { spawnSync } = require('child_process'); 2 | 3 | function installPackages(packages, dest, dev) { 4 | let cmd = ['install']; 5 | 6 | if (packages) { 7 | cmd = cmd.concat(packages); 8 | 9 | if (dev !== false) { 10 | cmd.push('--save-dev'); 11 | } 12 | } 13 | 14 | if (dest != '.') { 15 | cmd.push('--prefix', './' + dest); 16 | } 17 | 18 | spawnSync('npm', cmd, { stdio: 'inherit' }); 19 | } 20 | 21 | module.exports = installPackages; 22 | -------------------------------------------------------------------------------- /lib/log.js: -------------------------------------------------------------------------------- 1 | const color = require('./color'); 2 | 3 | function log(message, style = 'yellow') { 4 | console.log(color(message, style)); 5 | } 6 | 7 | module.exports = log; 8 | -------------------------------------------------------------------------------- /lib/prefix.js: -------------------------------------------------------------------------------- 1 | function prefix(string, prefix) { 2 | if (string) { 3 | if (string.startsWith('.')) { 4 | string = string.substring(1); 5 | } 6 | 7 | return prefix + string; 8 | } 9 | } 10 | 11 | module.exports = prefix; 12 | -------------------------------------------------------------------------------- /lib/questions.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const color = require('./color'); 3 | 4 | const questions = [ 5 | { 6 | type: 'list', 7 | name: 'build', 8 | message: color('Which build module?', 'green'), 9 | choices: [ 10 | { 11 | name: 'gulp', 12 | value: 'gulp' 13 | } 14 | ] 15 | }, 16 | { 17 | type: 'list', 18 | name: 'style', 19 | message: color('Which style module?', 'green'), 20 | choices: [ 21 | { 22 | name: 'CSS (cssnext)', 23 | value: 'css' 24 | }, 25 | { 26 | name: 'Sass', 27 | value: 'sass' 28 | }, 29 | { 30 | name: 'Less', 31 | value: 'less' 32 | } 33 | ] 34 | }, 35 | { 36 | type: 'list', 37 | name: 'script', 38 | message: color('Which script module?', 'green'), 39 | choices: [ 40 | { 41 | name: 'modularJS', 42 | value: 'mjs' 43 | }, 44 | { 45 | name: 'JavaScript (ES6+)', 46 | value: 'js' 47 | } 48 | ] 49 | }, 50 | { 51 | type: 'list', 52 | name: 'view', 53 | message: color('Which view module?', 'green'), 54 | choices: [ 55 | { 56 | name: 'Handlebars', 57 | value: 'hbs' 58 | }, 59 | { 60 | name: 'Liquid', 61 | value: 'liquid' 62 | }, 63 | { 64 | name: 'Swig', 65 | value: 'swig' 66 | } 67 | ] 68 | 69 | } 70 | ] 71 | 72 | module.exports = questions; 73 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Antoine Boulanger 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mbp", 3 | "version": "1.3.0", 4 | "description": "Dead simple modular boilerplate.", 5 | "repository": "modularorg/modularbp", 6 | "author": "Antoine Boulanger (https://antoineboulanger.com)", 7 | "license": "MIT", 8 | "bin": "index.js", 9 | "engines": { 10 | "node": ">=8.5" 11 | }, 12 | "dependencies": { 13 | "commander": "^5.1.0", 14 | "fast-glob": "^3.2.2", 15 | "inquirer": "^7.1.0" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | 4 | 5 |

6 |

modularBP

7 |

Dead simple modular boilerplate.

8 | 9 | ## Installation 10 | ```sh 11 | npm install mbp -g 12 | ``` 13 | 14 | ## Usage 15 | ```sh 16 | # init your project 17 | mbp init 18 | 19 | # run the build system you chose 20 | gulp 21 | ``` 22 | 23 | ## Modules 24 | 25 | ### Build 26 | | Module | Description | 27 | | ------ | ----------- | 28 | | [modularbp-gulp] | Build tasks modules with [gulp] | 29 | 30 | ### Styles 31 | | Module | Description | 32 | | ------ | ----------- | 33 | | [modularbp-css] | CSS modules with [cssnext] and [PostCSS] | 34 | | [modularbp-sass] | SCSS modules with [Sass] | 35 | | [modularbp-less] | LESS modules with [Less] | 36 | 37 | ### Scripts 38 | | Module | Description | 39 | | ------ | ----------- | 40 | | [modularbp-mjs] | JavaScript modules with [modularJS] and [Babel] | 41 | | [modularbp-js] | JavaScript modules with [Babel] | 42 | 43 | ### Views 44 | | Module | Description | 45 | | ------ | ----------- | 46 | | [modularbp-hbs] | HTML modules with [Handlebars] | 47 | | [modularbp-liquid] | HTML modules with [Liquid] | 48 | | [modularbp-swig] | HTML modules with [Swig] | 49 | 50 | ## Customization 51 | 52 | ### Base 53 | 54 | If you want to further customize the boilerplate to your own structure and files, you can easily clone a GitHub repository with the init command, by specifying the repository name and optionally the destination directory. It will clone first, then install the mbp modules without overwriting your files. 55 | 56 | ```sh 57 | mbp init 58 | ``` 59 | 60 | ### Config 61 | 62 | You can create a `mconfig.json` file to change the default folders structure and set your modules choice to skip the cli questions. 63 | 64 | ```json 65 | { 66 | "src": "./src/", 67 | "dest": "./dist/", 68 | "build": "./build/", 69 | "styles": { 70 | "src": "./src/styles/", 71 | "dest": "./dist/styles/", 72 | "main": "main" 73 | }, 74 | "scripts": { 75 | "src": "./src/scripts/", 76 | "dest": "./dist/scripts/", 77 | "main": "main" 78 | }, 79 | "svgs": { 80 | "src": "./src/images/sprite/", 81 | "dest": "./dist/images/" 82 | }, 83 | "views": { 84 | "src": "./src/", 85 | "partials": "./src/partials/" 86 | }, 87 | "modules": { 88 | "build": "gulp", 89 | "style": "css", 90 | "script": "mjs", 91 | "view": "hbs" 92 | } 93 | } 94 | ``` 95 | 96 | [modularbp-gulp]: https://github.com/modularorg/modularbp-gulp 97 | [modularbp-css]: https://github.com/modularorg/modularbp-gulp/tree/master/modules/gulp-css 98 | [modularbp-sass]: https://github.com/modularorg/modularbp-gulp/tree/master/modules/gulp-sass 99 | [modularbp-less]: https://github.com/modularorg/modularbp-gulp/tree/master/modules/gulp-less 100 | [modularbp-mjs]: https://github.com/modularorg/modularbp-mjs 101 | [modularbp-js]: https://github.com/modularorg/modularbp-gulp/tree/master/modules/gulp-js 102 | [modularbp-hbs]: https://github.com/modularorg/modularbp-gulp/tree/master/modules/gulp-hbs 103 | [modularbp-liquid]: https://github.com/modularorg/modularbp-gulp/tree/master/modules/gulp-liquid 104 | [modularbp-swig]: https://github.com/modularorg/modularbp-gulp/tree/master/modules/gulp-swig 105 | 106 | [gulp]: https://github.com/gulpjs/gulp 107 | [cssnext]: https://github.com/MoOx/postcss-cssnext 108 | [Sass]: https://github.com/sass/libsass 109 | [Less]: https://github.com/less/less.js 110 | [PostCSS]: https://github.com/postcss/postcss 111 | [modularJS]: https://github.com/modularorg/modularjs 112 | [Babel]: https://github.com/babel/babel 113 | [Handlebars]: https://github.com/wycats/handlebars.js 114 | [Liquid]: https://github.com/Shopify/liquid 115 | [Swig]: https://github.com/node-swig/swig-templates 116 | -------------------------------------------------------------------------------- /src/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/preset-env"] 3 | } 4 | -------------------------------------------------------------------------------- /src/.browserslistrc: -------------------------------------------------------------------------------- 1 | defaults 2 | -------------------------------------------------------------------------------- /src/.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | end_of_line = lf 7 | indent_size = 4 8 | indent_style = space 9 | insert_final_newline = true 10 | trim_trailing_whitespace = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | 15 | [{*.yml,*.json}] 16 | indent_size = 2 17 | indent_style = space 18 | -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | Thumbs.db 4 | -------------------------------------------------------------------------------- /src/README.md: -------------------------------------------------------------------------------- 1 | # {{name}} 2 | -------------------------------------------------------------------------------- /src/mconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "src": "./src/", 3 | "dest": "./dist/", 4 | "build": "./build/", 5 | "styles": { 6 | "src": "./src/styles/", 7 | "dest": "./dist/styles/", 8 | "main": "main" 9 | }, 10 | "scripts": { 11 | "src": "./src/scripts/", 12 | "dest": "./dist/scripts/", 13 | "main": "main" 14 | }, 15 | "svgs": { 16 | "src": "./src/images/sprite/", 17 | "dest": "./dist/images/" 18 | }, 19 | "views": { 20 | "src": "./src/", 21 | "partials": "./src/partials/" 22 | } 23 | } 24 | --------------------------------------------------------------------------------