├── templates ├── tasks │ ├── config │ │ └── .gitkeep │ ├── register │ │ └── .gitkeep │ └── README.md └── Gruntfile.js ├── .editorconfig ├── .gitignore ├── lib ├── index.js └── before.js ├── package.json ├── bin └── index.js ├── CONTRIBUTING.md ├── LICENSE ├── .jshintrc ├── README.md └── FAQ.md /templates/tasks/config/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /templates/tasks/register/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = tab 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | *.seed 3 | *.log 4 | *.csv 5 | *.dat 6 | *.out 7 | *.pid 8 | *.gz 9 | 10 | pids 11 | logs 12 | results 13 | 14 | npm-debug.log 15 | node_modules 16 | generated 17 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * sails-generate-gruntfile 3 | * 4 | * Usage: 5 | * `sails generate gruntfile` 6 | * 7 | * @type {Object} 8 | */ 9 | module.exports = { 10 | 11 | templatesDirectory: require('path').resolve(__dirname,'../templates'), 12 | 13 | before: require('./before'), 14 | 15 | targets: { 16 | 17 | './Gruntfile.js': { template: './Gruntfile.js' }, 18 | 19 | // Tasks folder, subfolders, and README. 20 | './tasks': { folder: {} }, 21 | './tasks/config': { folder: {} }, 22 | './tasks/register': { folder: {} }, 23 | './tasks/README.md': { template: './tasks/README.md' } 24 | } 25 | }; 26 | 27 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sails-generate-gruntfile", 3 | "version": "0.10.10", 4 | "description": "Generate a gruntfile for Sails.", 5 | "main": "lib/index.js", 6 | "scripts": { 7 | "test": "mocha" 8 | }, 9 | "keywords": [ 10 | "gruntfile", 11 | "generator", 12 | "sails", 13 | "generate", 14 | "plugin" 15 | ], 16 | "author": "balderdashy", 17 | "license": "MIT", 18 | "dependencies": { 19 | "lodash": ">=2.4.x", 20 | "merge-defaults": ">=0.1.0" 21 | }, 22 | "devDependencies": { 23 | "sails-generate": "*", 24 | "reportback": "*", 25 | "fs-extra": "~0.8.1" 26 | }, 27 | "sailsGenerator": { 28 | "type": "gruntfile", 29 | "behavior": "overrides `sails generate gruntfile`", 30 | "sailsVersion": "~0.10.0" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /bin/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Module dependencies 3 | */ 4 | 5 | var sailsgen = require('sails-generate') 6 | , path = require('path'); 7 | 8 | 9 | 10 | // 11 | // This script exists so we can run our generator 12 | // directly from the command-line for convenience 13 | // during development. 14 | // 15 | 16 | // Make sure a "generated" dir exists for testing 17 | require('fs-extra').mkdirp(path.resolve(process.cwd(), 'generated')); 18 | 19 | var scope = { 20 | generatorType: 'gruntfile', 21 | rootPath: path.resolve(process.cwd(), 'generated'), 22 | modules: { 23 | 'gruntfile': path.resolve(__dirname, '../lib') 24 | }, 25 | 26 | // For the NEW generator we're generating: 27 | generatorName: process.argv[2], 28 | }; 29 | sailsgen(scope, function (err) { 30 | if (err) throw err; 31 | 32 | // It worked. 33 | console.log('Done.'); 34 | }); 35 | 36 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to sails-generate-gruntfile 2 | 3 | 4 | ## Opening Issues 5 | 6 | Please observe the same conventions as you would opening issues in the main Sails repo. 7 | 8 | See [Opening Issues](https://github.com/balderdashy/sails/blob/master/CONTRIBUTING.md#opening-issues) for more information. 9 | 10 | 11 | 12 | ## Submitting Pull Requests 13 | 14 | Please observe the same conventions as you would submitting pull requests to the Sails core. 15 | 16 | See [Submitting Pull Requests](https://github.com/balderdashy/sails/blob/master/CONTRIBUTING.md#submitting-pull-requests). 17 | 18 | 19 | 20 | ## Need more help? 21 | 22 | Please see the [contribution guide](https://github.com/balderdashy/sails/blob/v0.10/CONTRIBUTING.md#contributing-to-a-generator) in the Sails repo for more general guidelines. 23 | 24 | 25 | [![githalytics.com alpha](https://cruel-carlota.pagodabox.com/8acf2fc2ca0aca8a3018e355ad776ed7 "githalytics.com")](http://githalytics.com/balderdashy/sails-generate-gruntfile/CONTRIBUTING.md) 26 | 27 | 28 | # Overriding a generator 29 | 30 | 31 | # Authoring custom generators 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 balderdashy & contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | 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, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | // To fix column positions for JSHint errors you may want to add `"indent": 1` to your 3 | // **User** "jshint_options". This issue affects users with tabs for indentation. 4 | // This fix was reverted due to a conflict with using the `"white": true` option. 5 | // "indent": 1, 6 | "evil": true, 7 | "regexdash": true, 8 | "browser": true, 9 | "wsh": true, 10 | "sub": true, 11 | 12 | // Suppress warnings about mixed tabs and spaces 13 | "smarttabs": true, 14 | 15 | // Suppress warnings about trailing whitespace 16 | "trailing": false, 17 | 18 | // Suppress warnings about the use of expressions where fn calls or assignments are expected 19 | "expr": true, 20 | 21 | // Suppress warnings about using functions inside loops (useful for inifinityCounters) 22 | "loopfunc": true, 23 | 24 | // Suppress warnings about using assignments where conditionals are expected 25 | "boss": true, 26 | 27 | // Suppress warnings about "weird constructions" 28 | // i.e. allow code like: 29 | // (new (function OneTimeUsePrototype () { } )) 30 | "supernew": true, 31 | 32 | // Allow backwards, node-dependency-style commas 33 | "laxcomma": true 34 | } 35 | -------------------------------------------------------------------------------- /lib/before.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Module dependencies 3 | */ 4 | 5 | var util = require('util') 6 | , _ = require('lodash'); 7 | 8 | // Make _.defaults recursive 9 | _.defaults = require('merge-defaults'); 10 | 11 | 12 | 13 | 14 | /** 15 | * This `before` function is run before generating targets. 16 | * Validate, configure defaults, get extra dependencies, etc. 17 | * 18 | * @param {Object} scope 19 | * @param {Function} cb [callback] 20 | */ 21 | 22 | module.exports = function(scope, cb) { 23 | 24 | // 25 | // scope.args are the raw command line arguments. 26 | // 27 | // e.g. if you run: 28 | // sails generate controlller user find create update 29 | // then: 30 | // scope.args = ['user', 'find', 'create', 'update'] 31 | // 32 | 33 | _.defaults(scope, { 34 | // foo: scope.args[0] 35 | }); 36 | 37 | 38 | 39 | 40 | // 41 | // Validate custom scope variables which 42 | // are required by this generator. 43 | // 44 | 45 | if ( !scope.rootPath ) { 46 | return cb(new Error( 47 | 'Missing scope variable: `rootPath`\n' + 48 | 'Please make sure it is specified and try again.' 49 | )); 50 | } 51 | 52 | 53 | // 54 | // Determine default values based on the 55 | // available scope. 56 | // 57 | 58 | _.defaults(scope, { 59 | currentTime: new Date() 60 | }); 61 | 62 | 63 | 64 | // 65 | // Take multiple "passes" if necessary. 66 | // 67 | 68 | _.defaults(scope, { 69 | rootPath: scope.rootPath 70 | }); 71 | 72 | 73 | 74 | // 75 | // Trigger callback with no error to proceed. 76 | // 77 | 78 | cb(); 79 | }; 80 | -------------------------------------------------------------------------------- /templates/Gruntfile.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Gruntfile 3 | * 4 | * This Node script is executed when you run `grunt` or `sails lift`. 5 | * It's purpose is to load the Grunt tasks in your project's `tasks` 6 | * folder, and allow you to add and remove tasks as you see fit. 7 | * For more information on how this works, check out the `README.md` 8 | * file that was generated in your `tasks` folder. 9 | * 10 | * WARNING: 11 | * Unless you know what you're doing, you shouldn't change this file. 12 | * Check out the `tasks` directory instead. 13 | */ 14 | 15 | module.exports = function(grunt) { 16 | 17 | 18 | // Load the include-all library in order to require all of our grunt 19 | // configurations and task registrations dynamically. 20 | var includeAll; 21 | try { 22 | includeAll = require('include-all'); 23 | } catch (e0) { 24 | try { 25 | includeAll = require('sails/node_modules/include-all'); 26 | } 27 | catch(e1) { 28 | console.error('Could not find `include-all` module.'); 29 | console.error('Skipping grunt tasks...'); 30 | console.error('To fix this, please run:'); 31 | console.error('npm install include-all --save`'); 32 | console.error(); 33 | 34 | grunt.registerTask('default', []); 35 | return; 36 | } 37 | } 38 | 39 | 40 | /** 41 | * Loads Grunt configuration modules from the specified 42 | * relative path. These modules should export a function 43 | * that, when run, should either load/configure or register 44 | * a Grunt task. 45 | */ 46 | function loadTasks(relPath) { 47 | return includeAll({ 48 | dirname: require('path').resolve(__dirname, relPath), 49 | filter: /(.+)\.js$/ 50 | }) || {}; 51 | } 52 | 53 | /** 54 | * Invokes the function from a Grunt configuration module with 55 | * a single argument - the `grunt` object. 56 | */ 57 | function invokeConfigFn(tasks) { 58 | for (var taskName in tasks) { 59 | if (tasks.hasOwnProperty(taskName)) { 60 | tasks[taskName](grunt); 61 | } 62 | } 63 | } 64 | 65 | 66 | 67 | 68 | // Load task functions 69 | var taskConfigurations = loadTasks('./tasks/config'), 70 | registerDefinitions = loadTasks('./tasks/register'); 71 | 72 | // (ensure that a default task exists) 73 | if (!registerDefinitions.default) { 74 | registerDefinitions.default = function (grunt) { grunt.registerTask('default', []); }; 75 | } 76 | 77 | // Run task functions to configure Grunt. 78 | invokeConfigFn(taskConfigurations); 79 | invokeConfigFn(registerDefinitions); 80 | 81 | }; 82 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![image_squidhome@2x.png](http://i.imgur.com/RIvu9.png) 2 | 3 | # sails-generate-gulpfile (WIP) 4 | 5 | 6 | A `gulpfile` generator for use with the Sails command-line interface. 7 | 8 | 9 | ### Installation 10 | 11 | Certain generators are installed by default in Sails, but they can be overridden. Check the [Sails docs](http://sailsjs.org/#!documentation) for information on installing generator overrides / custom generators. 12 | 13 | 18 | 19 | 20 | ### Production Usage 21 | 22 | ##### On the command line 23 | 24 | ```sh 25 | $ sails generate gulpfile 26 | ``` 27 | 28 | ##### In a node script 29 | 30 | ```javascript 31 | var path = require('path'); 32 | var sailsgen = require('sails-generate'); 33 | var scope = { 34 | rootPath: path.resolve(__dirname) 35 | }; 36 | sailsgen(require('sails-generate-gulpfile'), scope, function (err) { 37 | if (err) throw err; 38 | 39 | // It worked. 40 | }); 41 | ``` 42 | 43 | 44 | ### Development 45 | 46 | To get started quickly and see this generator in action, run the `bin/index.js` script: 47 | 48 | ```sh 49 | $ git clone YOUR_FORK_OF_THIS_REPO sails-generate-gulpfile-fork 50 | $ cd sails-generate-gulpfile-fork 51 | $ npm install 52 | $ node ./bin 53 | ``` 54 | 55 | `bin/index.js` is a simple script, bundled only for convenience, that runs the generator with hard-coded scope variables. Please feel free to modify that file however you like! Also see `CONTRIBUTING.md` for more information on overriding/enhancing generators. 56 | 57 | 58 | 59 | ### Questions? 60 | 61 | See `FAQ.md`. 62 | 63 | 64 | 65 | ### More Resources 66 | 67 | - [Stackoverflow](http://stackoverflow.com/questions/tagged/sails.js) 68 | - [#sailsjs on Freenode](http://webchat.freenode.net/) (IRC channel) 69 | - [Twitter](https://twitter.com/sailsjs) 70 | - [Professional/enterprise](https://github.com/balderdashy/sails-docs/blob/master/FAQ.md#are-there-professional-support-options) 71 | - [Tutorials](https://github.com/balderdashy/sails-docs/blob/master/FAQ.md#where-do-i-get-help) 72 | - Sails.js logo (small) 73 | 74 | 75 | ### License 76 | 77 | **[MIT](./LICENSE)** 78 | © 2014 [balderdashy](http://github.com/balderdashy) & [contributors] 79 | [Mike McNeil](http://michaelmcneil.com), [Balderdash](http://balderdash.co) & contributors 80 | 81 | [Sails](http://sailsjs.org) is free and open-source under the [MIT License](http://sails.mit-license.org/). 82 | 83 | -------------------------------------------------------------------------------- /templates/tasks/README.md: -------------------------------------------------------------------------------- 1 | # About the `tasks` folder 2 | 3 | The `tasks` directory is a suite of Grunt tasks and their configurations, bundled for your convenience. The Grunt integration is mainly useful for bundling front-end assets, (like stylesheets, scripts, & markup templates) but it can also be used to run all kinds of development tasks, from browserify compilation to database migrations. 4 | 5 | If you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, read on! 6 | 7 | 8 | ### How does this work? 9 | 10 | The asset pipeline bundled in Sails is a set of Grunt tasks configured with conventional defaults designed to make your project more consistent and productive. 11 | 12 | The entire front-end asset workflow in Sails is completely customizable-- while it provides some suggestions out of the box, Sails makes no pretense that it can anticipate all of the needs you'll encounter building the browser-based/front-end portion of your application. Who's to say you're even building an app for a browser? 13 | 14 | 15 | 16 | ### What tasks does Sails run automatically? 17 | 18 | Sails runs some of these tasks (the ones in the `tasks/register` folder) automatically when you run certain commands. 19 | 20 | ###### `sails lift` 21 | 22 | Runs the `default` task (`tasks/register/default.js`). 23 | 24 | ###### `sails lift --prod` 25 | 26 | Runs the `prod` task (`tasks/register/prod.js`). 27 | 28 | ###### `sails www` 29 | 30 | Runs the `build` task (`tasks/register/build.js`). 31 | 32 | ###### `sails www --prod` (production) 33 | 34 | Runs the `buildProd` task (`tasks/register/buildProd.js`). 35 | 36 | 37 | ### Can I customize this for SASS, Angular, client-side Jade templates, etc? 38 | 39 | You can modify, omit, or replace any of these Grunt tasks to fit your requirements. You can also add your own Grunt tasks- just add a `someTask.js` file in the `grunt/config` directory to configure the new task, then register it with the appropriate parent task(s) (see files in `grunt/register/*.js`). 40 | 41 | 42 | ### Do I have to use Grunt? 43 | 44 | Nope! To disable Grunt integration in Sails, just delete your Gruntfile or disable the Grunt hook. 45 | 46 | 47 | ### What if I'm not building a web frontend? 48 | 49 | That's ok! A core tenant of Sails is client-agnosticism-- it's especially designed for building APIs used by all sorts of clients; native Android/iOS/Cordova, serverside SDKs, etc. 50 | 51 | You can completely disable Grunt by following the instructions above. 52 | 53 | If you still want to use Grunt for other purposes, but don't want any of the default web front-end stuff, just delete your project's `assets` folder and remove the front-end oriented tasks from the `grunt/register` and `grunt/config` folders. You can also run `sails new myCoolApi --no-frontend` to omit the `assets` folder and front-end-oriented Grunt tasks for future projects. You can also replace your `sails-generate-frontend` module with alternative community generators, or create your own. This allows `sails new` to create the boilerplate for native iOS apps, Android apps, Cordova apps, SteroidsJS apps, etc. 54 | 55 | -------------------------------------------------------------------------------- /FAQ.md: -------------------------------------------------------------------------------- 1 | # FAQ (Frequently Asked Questions) 2 | 3 | 4 | ### Which version should I use? 5 | 6 | The latest stable version in npm is always a safe bet. 7 | 8 | ```sh 9 | $ npm install sails-generate-gruntfile 10 | ``` 11 | 12 | [![NPM](https://nodei.co/npm/sails-generate-gruntfile.png?downloads=true&stars=true)](https://nodei.co/npm/sails-generate-gruntfile/) 13 | 14 | 15 | 16 | ### Where is the documentation? 17 | + Documentation for this module is in the README.md file. 18 | + [Docs for the latest stable npm release of Sails are on the website](http://sailsjs.org/#!documentation) 19 | 20 | 21 | 22 | ### What is a generator? 23 | 24 | A generator is one of the three main types of Sails plugins. It allows you to extend or override a generator in the Sails command-line interface (i.e. when a user runs `sails new` and/or `sails generate`. 25 | 26 | Out of all the types of plugins, generators involve the fewest lines of code, and are probably the best way to get your hands dirty without getting buried. 27 | 28 | 29 | ### What kind of things can I do in a generator? 30 | 31 | Generators are mainly about creating files. There are built-in helpers for: 32 | 33 | + creating folders 34 | + copying files 35 | + EJS template 36 | + running other generators 37 | 38 | 39 | 40 | ### How do I get involved? 41 | 42 | + [Contributing to this module](./CONTRIBUTING.md) 43 | + If you find a bug with this module, please submit an issue to the tracker in this repository. Better yet, send a pull request :) 44 | 45 | 46 | ### Where do I get help? 47 | 48 | + [Ask a question on StackOverflow](http://stackoverflow.com/questions/tagged/sailsjs?sort=newest&days=30) 49 | + Get help from the [Google Group](https://groups.google.com/forum/#!forum/sailsjs) 50 | + Get help on IRC ([#sailsjs on freenode](http://irc.netsplit.de/channels/details.php?room=%23sailsjs&net=freenode)) 51 | + [Tweet @sailsjs](http://twitter.com/sailsjs) 52 | 53 | 54 | ### Why haven't I gotten a response to my feature request? 55 | 56 | When people see something working in practice, they're usually a lot more down to get on board with it! That's even more true in the open-source community, since most of us are not getting paid to do this (myself included). The best feature request is a pull request-- even if you can't do the whole thing yourself, if you blueprint your thoughts, it'll help everyone understand what's going on. 57 | 58 | ### I want to make a sweeping change / add a major feature 59 | It's always a good idea to contact the maintainer(s) of a module before doing a bunch of work. This is even more true when it affects how things work / breaks backwards compatibility. 60 | 61 | ### The maintainer of this module won't merge my pull request. 62 | 63 | Most of the time, when PRs don't get merged, a scarcity of time is to blame. I can almost guarantee you it's nothing personal :) And I can only speak for myself here, but in most cases, when someone follows up on a PR that's been sitting for a little while on Twitter, I don't mind the reminder at all. 64 | 65 | The best thing about maintaining lots of small modules is that it's trivial to override any one of them on their own. If you need some changes merged, please feel empowered to fork this model and release your own version. 66 | 67 | If you feel that yours is the better approach, and should be the default, share it with the community via IRC, Twitter, Google Groups, etc. Also, feel free to let the core Sails/Waterline team know and we'll take it into consideration. 68 | 69 | 70 | 71 | ### More questions? 72 | 73 | > If you have an unanswered question that isn't covered here, and that you feel would add value for the community, please feel free to send a PR adding it to this section. 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | [![githalytics.com alpha](https://cruel-carlota.pagodabox.com/8acf2fc2ca0aca8a3018e355ad776ed7 "githalytics.com")](http://githalytics.com/balderdashy/sails-generate-gruntfile/FAQ.md) 82 | --------------------------------------------------------------------------------