Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.

Commit

Permalink
Clean up boilerplate, get rid of unnecessary lib/ dir.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikermcneil committed Oct 10, 2016
1 parent fd2696c commit b410f8a
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 70 deletions.
10 changes: 9 additions & 1 deletion .editorconfig
@@ -1,4 +1,12 @@
# editorconfig.org
# ╔═╗╔╦╗╦╔╦╗╔═╗╦═╗┌─┐┌─┐┌┐┌┌─┐┬┌─┐
# ║╣ ║║║ ║ ║ ║╠╦╝│ │ ││││├┤ ││ ┬
# o╚═╝═╩╝╩ ╩ ╚═╝╩╚═└─┘└─┘┘└┘└ ┴└─┘
#
# This file (`.editorconfig`) exists to help maintain consistent formatting
# throughout this package, the Sails framework, and the Node-Machine project.
#
# To review what each of these options mean, see:
# http://editorconfig.org/
root = true

[*]
Expand Down
47 changes: 32 additions & 15 deletions .gitignore
@@ -1,17 +1,34 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
# ┌─┐┬┌┬┐╦╔═╗╔╗╔╔═╗╦═╗╔═╗
# │ ┬│ │ ║║ ╦║║║║ ║╠╦╝║╣
# o└─┘┴ ┴ ╩╚═╝╝╚╝╚═╝╩╚═╚═╝
#
# This file (`.gitignore`) exists to signify to `git` that certain files
# and/or directories should be ignored for the purposes of version control.
#
# This is primarily useful for excluding temporary files of all sorts; stuff
# generated by IDEs, build scripts, automated tests, package managers, or even
# end-users (e.g. file uploads). `.gitignore` files like this also do a nice job
# at keeping sensitive credentials and personal data out of version control systems.
#

pids
logs
results

npm-debug.log
############################
# npm
############################
node_modules
bower_components
.DS_Store
npm-debug.log


############################
# tmp, editor & OS files
############################
.tmp
*.swo
*.swp
*.swn
*.swm
.DS_STORE
*#
*~
.idea
nbproject

116 changes: 102 additions & 14 deletions .jshintrc
@@ -1,34 +1,122 @@
{
// To fix column positions for JSHint errors you may want to add `"indent": 1` to your
// **User** "jshint_options". This issue affects users with tabs for indentation.
// This fix was reverted due to a conflict with using the `"white": true` option.
// "indent": 1,
// ┬┌─┐╦ ╦╦╔╗╔╔╦╗┬─┐┌─┐
// │└─┐╠═╣║║║║ ║ ├┬┘│
// o└┘└─┘╩ ╩╩╝╚╝ ╩ ┴└─└─┘
//
// This file (`.jshintrc`) exists to help with consistency of code
// throughout this package, and throughout Sails and the Node-Machine project.
//
// To review what each of these options mean, see:
// http://jshint.com/docs/options
//
// (or: https://github.com/jshint/jshint/blob/master/examples/.jshintrc)



//////////////////////////////////////////////////////////////////////
// NOT SUPPORTED IN SOME JSHINT VERSIONS SO LEAVING COMMENTED OUT:
//////////////////////////////////////////////////////////////////////
// Prevent overwriting prototypes of native classes like `Array`.
// (doing this is _never_ ok in any of our packages that are intended
// to be used as dependencies of other developers' modules and apps)
// "freeze": true,
//////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////
// EVERYTHING ELSE:
//////////////////////////////////////////////////////////////////////

// Allow the use of `eval` and `new Function()`
// (we sometimes actually need to use these things)
"evil": true,

// Tolerate funny-looking dashes in RegExp literals.
// (see https://github.com/jshint/jshint/issues/159#issue-903547)
"regexdash": true,

// The potential runtime "Environments" (as defined by jshint)
// that the _style_ of code written in this package should be
// compatible with (not the code itself, of course).
"browser": true,
"node": true,
"wsh": true,

// Tolerate the use `[]` notation when dot notation would be possible.
// (this is sometimes preferable for readability)
"sub": true,

// Suppress warnings about mixed tabs and spaces
"smarttabs": true,
// Do NOT suppress warnings about mixed tabs and spaces
// (two spaces always, please; see `.editorconfig`)
"smarttabs": false,

// Suppress warnings about trailing whitespace
// (this is already enforced by the .editorconfig, so no need to warn as well)
"trailing": false,

// Suppress warnings about the use of expressions where fn calls or assignments are expected
// Suppress warnings about the use of expressions where fn calls or assignments
// are expected, and about using assignments where conditionals are expected.
// (while generally a good idea, without this setting, JSHint needlessly lights up warnings
// in existing, working code that really shouldn't be tampered with. Pandora's box and all.)
"expr": true,

// Suppress warnings about using functions inside loops (useful for inifinityCounters)
"loopfunc": true,

// Suppress warnings about using assignments where conditionals are expected
"boss": true,

// Do NOT suppress warnings about using functions inside loops
// (in the general case, we should be using iteratee functions with `_.each()`
// or `Array.prototype.forEach()` instead of `for` or `while` statements
// anyway. This warning serves as a helpful reminder.)
"loopfunc": false,

// Suppress warnings about "weird constructions"
// i.e. allow code like:
// ```
// (new (function OneTimeUsePrototype () { } ))
// ```
//
// (sometimes order of operations in JavaScript can be scary. There is
// nothing wrong with using an extra set of parantheses when the mood
// strikes or you get "that special feeling".)
"supernew": true,

// Allow backwards, node-dependency-style commas
"laxcomma": true
// Do NOT allow backwards, node-dependency-style commas.
// (while this code style choice was used by the project in the past,
// we have since standardized these practices to make code easier to
// read, albeit a bit less exciting)
"laxcomma": false,

// Strictly enforce the consistent use of single quotes.
// (this is a convention that was established primarily to make it easier
// to grep [or FIND+REPLACE in Sublime] particular string literals in
// JavaScript [.js] files. Note that JSON [.json] files are, of course,
// still written exclusively using double quotes around key names and
// around string literals.)
"quotmark": "single",

// Do NOT suppress warnings about the use of `==null` comparisons.
// (please be explicit-- use Lodash or `require('util')` and call
// either `.isNull()` or `.isUndefined()`)
"eqnull": false,

// Strictly enforce the use of curly braces with `if`, `else`, and `switch`
// as well as, much less commonly, `for` and `while` statements.
// (this is just so that all of our code is consistent, and to avoid bugs)
"curly": true,

// Strictly enforce the use of `===` and `!==`.
// (this is always a good idea. Check out "Truth, Equality, and JavaScript"
// by Angus Croll [the author of "If Hemmingway Wrote JavaScript"] for more
// explanation as to why.)
"eqeqeq": true,

// Allow initializing variables to `undefined`.
// For more information, see:
// • https://jslinterrors.com/it-is-not-necessary-to-initialize-a-to-undefined
// • https://github.com/jshint/jshint/issues/1484
//
// (it is often very helpful to explicitly clarify the initial value of
// a local variable-- especially for folks new to more advanced JavaScript
// and who might not recognize the subtle, yet critically important differences between our seemingly
// between `null` and `undefined`, and the impact on `typeof` checks)
"-W080": true

}
21 changes: 21 additions & 0 deletions .npmignore
@@ -0,0 +1,21 @@
*#
node_modules
ssl
.DS_STORE
*.swo
*.swp
*.swn
*.swm
*~
.idea
nbproject
.git
.gitignore
.tmp
.jshintrc
.editorconfig
CONTRIBUTING.md
*.md
**/*.md
test
.github
17 changes: 10 additions & 7 deletions README.md
Expand Up @@ -4,20 +4,23 @@ Default generator for frontend code files in new Sails projects. Creates the def

> You can read more about how all that works in [docs/](./docs/overview.md).
[![NPM](https://nodei.co/npm/sails-generate-frontend.png?downloads=true&stars=true)](https://nodei.co/npm/sails-generate-frontend/)
## Bugs   [![NPM version](https://badge.fury.io/js/sails-generate-frontend.svg)](http://npmjs.com/package/sails-generate-frontend)

To report a bug, [click here](http://sailsjs.com/bugs).

## Contributing
> This is a built-in module in the Sails command-line tool. It is installed automatically when you run `npm install sails -g`.
Please observe the guidelines and conventions laid out in the [Sails project contribution guide](https://github.com/balderdashy/sails/blob/master/CONTRIBUTING.md) when opening issues or submitting pull requests.
## Getting Help

First, please [read the docs on generators](http://sailsjs.com/documentation/concepts/extending-sails/generators). If you have lingering questions, see the <a href="http://sailsjs.com/support" target="_blank" title="Node.js framework for building realtime APIs.">support section of our website</a> for more information, or [tweet](https://twitter.com/sailsjs) at us.

## Getting Help

First, please [read the docs on generators](http://sailsjs.org/documentation/concepts/extending-sails/generators). If you have lingering questions, see the <a href="http://sailsjs.org/support" target="_blank" title="Node.js framework for building realtime APIs.">support section of our website</a> for more information, or [tweet](https://twitter.com/sailsjs) at us.
## Contributing &nbsp; [![Build Status](https://travis-ci.org/balderdashy/sails-generate-frontend.svg?branch=master)](https://travis-ci.org/balderdashy/sails-generate-frontend)

Please observe the guidelines and conventions laid out in the [Sails project contribution guide](http://sailsjs.com/contribute) when opening issues or submitting pull requests.

## License
[![NPM package info](https://nodei.co/npm/sails-generate-frontend.png?downloads=true)](http://npmjs.com/package/sails-generate-frontend)

[Sails](http://sailsjs.org) is free and open-source under the [MIT License](http://sails.mit-license.org/).
## License

The [Sails framework](http://sailsjs.com) is free and open-source under the [MIT License](http://sailsjs.com/license).
18 changes: 10 additions & 8 deletions docs/overview.md
@@ -1,16 +1,16 @@
# Sails Frontend Generator Overview
## Overview

This generator creates asset files and directories as grunt configuration and tasks files. The grunt files handle the managing of client side assets in a sails projects.

## Generation of front end assets
### Generation of front end assets
The front end asset are simply copied over from this generators `/template` directory. They are placed in your sails projects at the `/assets` directory.

## Generation of Grunt Config and Task Files
### Generation of Grunt Config and Task Files
There is another [sails generator](https://github.com/balderdashy/sails-generate-gruntfile) that generates a gruntfile that is configured to look for grunt config and tasks in a `/tasks/config` and `/tasks/register` directories respectively. Knowing this, the frontend generator will create a tasks folder and populate it with config and register directories that include the grunt files to set up configuation and registering tasks.

There are three tasks that are accessable to developers via the terminal. This is the default behavior for each one:

### sails lift
#### sails lift
1. Empties out contents of the `/.tmp/public` folder. This folder is where sails looks to serve static assets and where all of your assets will be placed.
2. Takes HTML files from `/assets/templates` directory and precompiles underscore templates into a JST file. These precompiled templates are placed in `/.tmp/public/jst.js`
3. Takes an `importer.less` file found in `/assets/styles` and compiles your less files into css based on what's in this file. Having one less file importing all of your other less files is a convention that many front end developers use, and the name of this file can be changed in the `/tasks/config/less.js` file. The compiled css will be placed in `/.tmp/public/styles/importer.css'
Expand All @@ -20,18 +20,20 @@ There are three tasks that are accessable to developers via the terminal. This i
The important thing to understand is that this asset injection should be placed in files that act as a layout file for your app. For single page apps this would be something like an `index.html` file and for apps that send server side views this should be something like a `layout.ejs` or `layout.jade` file. Usage for how to injet files is showin in `tasks/config/sails-linker.js` or can be found [here](https://github.com/Zolmeister/grunt-sails-linker). A more detailed description of this task can be found below.
7. Sets up a watch task that will run this entire task again if there are changes detected in the `/assets` directory or the `tasks/pipeline.js` file. This task is optimized so that instead of deleting entire directories and files, it just syncs changes that were made.

### sails build
#### sails build
1. Runs the exact same as sails lift from steps 1-4.
2. Links the same as sails linker but now all the links are relative. This is important since we will be generating a web accessable ready folder that has the ability to work as a standalone.
3. Deletes the `www` directory if it exists.
4. Copies the assets form `/.tmp/public` into a `www` directory. You now have a web accessable directory containing all assets. You can take this folder, open up index.html, and your client app will work. This is useful if you need to show clients the client side app without having to spin up a sails server.

### sails build --production
#### sails build --production
This is the same as sails build, except the assets are concatenated and minified.

## A Litte Bit More About Sails Linking
#### A little bit more about `sails-linker`

The sails linker can be a confusing concept at first glance, but it's really a simple notion. Lets take a look at a practical example of sails-linker being used in a project.
The more you talk about the sails-linker, the more confusing or capricious it might seem. A much better idea is to look at how it works from userland-- in practice.

Lets take a look at a practical example of sails-linker being used in a project.

Lets say we are working on a single page app in our sails project. Since it is a single page app, when a user requests the root of our app, we want to send users an `index.html` file. With this file, the client will be responsible for rendering the page correctly. The first thing we want to do is create an `index.html` file in out `/assets` directory. Lets say its very simple and looks like this:

Expand Down
48 changes: 24 additions & 24 deletions lib/index.js → index.js
Expand Up @@ -9,13 +9,13 @@

module.exports = {

templatesDirectory: require('path').resolve(__dirname,'../templates'),
templatesDirectory: require('path').resolve(__dirname,'../templates'),

/**
* The targets to generate.
* @type {Dictionary}
*/
targets: {
targets: {

// █████╗ ███████╗███████╗███████╗████████╗███████╗ ██╗
// ██╔══██╗██╔════╝██╔════╝██╔════╝╚══██╔══╝██╔════╝ ██╔╝
Expand Down Expand Up @@ -43,9 +43,9 @@ module.exports = {

// Call sails.io.js sub-generator to create the browser sdk at the conventional location
// (in `assets/js/dependencies/sails.io.js`)
'./': ['sails.io.js'],
'./': ['sails.io.js'],

// Example for folks creating custom front-end generators:
// Example for folks creating custom front-end generators:
// > (i.e. how to inject other client-side dependencies)
// ====================================================================================
// './assets/js/dependencies/angular.min.js': { exec: function (scope, cb) {
Expand All @@ -66,36 +66,36 @@ module.exports = {
//
// Default tasks/ folder and contents:

// asset pipeline setup
'./tasks/pipeline.js': { template: 'tasks/pipeline.js' },
// asset pipeline setup
'./tasks/pipeline.js': { template: 'tasks/pipeline.js' },


// grunt task configurations (`tasks/config`)
'./tasks/config/clean.js': { copy: 'tasks/config/clean.js' },
'./tasks/config/coffee.js': { copy: 'tasks/config/coffee.js' },
'./tasks/config/concat.js': { copy: 'tasks/config/concat.js' },
'./tasks/config/copy.js': { copy: 'tasks/config/copy.js' },
'./tasks/config/cssmin.js': { copy: 'tasks/config/cssmin.js' },
'./tasks/config/jst.js': { copy: 'tasks/config/jst.js' },
'./tasks/config/less.js': { copy: 'tasks/config/less.js' },
'./tasks/config/sails-linker.js': { copy: 'tasks/config/sails-linker.js' },
'./tasks/config/sync.js': { copy: 'tasks/config/sync.js' },
'./tasks/config/uglify.js': { copy: 'tasks/config/uglify.js' },
// grunt task configurations (`tasks/config`)
'./tasks/config/clean.js': { copy: 'tasks/config/clean.js' },
'./tasks/config/coffee.js': { copy: 'tasks/config/coffee.js' },
'./tasks/config/concat.js': { copy: 'tasks/config/concat.js' },
'./tasks/config/copy.js': { copy: 'tasks/config/copy.js' },
'./tasks/config/cssmin.js': { copy: 'tasks/config/cssmin.js' },
'./tasks/config/jst.js': { copy: 'tasks/config/jst.js' },
'./tasks/config/less.js': { copy: 'tasks/config/less.js' },
'./tasks/config/sails-linker.js': { copy: 'tasks/config/sails-linker.js' },
'./tasks/config/sync.js': { copy: 'tasks/config/sync.js' },
'./tasks/config/uglify.js': { copy: 'tasks/config/uglify.js' },

'./tasks/config/watch.js': { template: 'tasks/config/watch.js.template' },
'./tasks/config/watch.js': { template: 'tasks/config/watch.js.template' },


// built-in grunt tasks which are automatically called by Sails (`tasks/register`)
'./tasks/register/build.js': { copy: 'tasks/register/build.js' },
'./tasks/register/buildProd.js': { copy: 'tasks/register/buildProd.js' },
'./tasks/register/compileAssets.js': { copy: 'tasks/register/compileAssets.js' },
// built-in grunt tasks which are automatically called by Sails (`tasks/register`)
'./tasks/register/build.js': { copy: 'tasks/register/build.js' },
'./tasks/register/buildProd.js': { copy: 'tasks/register/buildProd.js' },
'./tasks/register/compileAssets.js': { copy: 'tasks/register/compileAssets.js' },
'./tasks/register/linkAssets.js': { copy: 'tasks/register/linkAssets.js' },
'./tasks/register/linkAssetsBuild.js': { copy: 'tasks/register/linkAssetsBuild.js' },
'./tasks/register/linkAssetsBuildProd.js': { copy: 'tasks/register/linkAssetsBuildProd.js' },
'./tasks/register/prod.js': { copy: 'tasks/register/prod.js' },
'./tasks/register/syncAssets.js': { copy: 'tasks/register/syncAssets.js' },

'./tasks/register/default.js': { template: 'tasks/register/default.js.template' },
}
'./tasks/register/default.js': { template: 'tasks/register/default.js.template' },
}
};

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"name": "sails-generate-frontend",
"version": "0.12.3",
"description": "Default generator for frontend code files in new Sails projects. Creates the default contents of the `assets/` folder when you run `sails new` on the command-line. Also creates a subset of the boilerplate Grunt task files (in `tasks/`); specifically, the files make up the conventional asset pipeline.",
"main": "lib/index.js",
"main": "index.js",
"scripts": {
"test": "mocha"
},
Expand Down

0 comments on commit b410f8a

Please sign in to comment.