2.0.0-alpha6 • Published 8 years ago

basis-gen v2.0.0-alpha6

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

Basis Generator

npm version node version license

npm install -g basis-gen
basis-gen [project-name]

A template project and generator for full-stack TypeScript projects.

Basis has the following goals:

  • Flexible configuration
  • Intuitive organization
  • Isolated builds
  • Automated deployments

These goals are accomplished with the following technologies:

  • TypeScript
  • Browserify
  • Sass (libsass)
  • Gulp
  • Docker (production)

Sass compiled via Basis has globbing and single-import enabled.

See CHANGES for a complete changelog.

Requirements

  • node >=5.0

Generator

Run basis-gen [project-name] to generate a new Basis-enabled project. A wizard will guide you through your setup.

Usage

The build system can be run in its default configuration with gulp. This loads the default preset defined in the configuration.

Flags can be set with the following syntax:

  • --flag: enable
  • --flag=yes, --flag=true: enable
  • --flag=no, --flag=false: disable

Flags

flagdefaultfunction
watchnoWatch the filesystem for changes
sourcemapsyesBuild sourcemaps for client code
minifynoMinify client code
notifynoNotify on build completion

Default values are used if the configuration does not specify a value and value was given on the CLI.

Parameters

parameterfunction
--out=PATHOutputs result into PATH
--preset=PRESETSets build preset to PRESET
--only=MODULE[,MODULE2,...]Build only these modules
--except=MODULE[,MODULE2,...]Don't build these modules
--gray=MODULE[,MODULE2,...]Build these modules even if disabled

Presets

Presets set default values for many of these flags and parameters.

Debug

keyvalue
out./debug
watchyes
sourcemapsyes
minifyno

Production

keyvalue
out./production
watchno
sourcemapsno
minifyyes

The default production preset also adds an extra transform, copying package.json and Dockerfile to the build directory.

Examples

To build a production build:

gulp --preset=production

To build just stylesheets once in debug mode:

gulp --watch=no --only=stylesheets

To build a debug build without sourcemaps, but with minification to ./derp, try

gulp --sourcemaps=no --minify --out=derp

Files

The default transforms are:

typeinputoutput
stylesnode_modules/@client/main.scssstatic/bundle.css
staticnode_modules/@staticstatic
staticDockerfile, package.json.
servernode_modules/@server.
clientnode_modules/@client/main.tsstatic/bundle.js

In debug mode (the default), the output is contained in debug. In production mode, it can be found in production.

Configuration

The primary configuration is located inside build.conf.js. Basis will also load build.user.conf.js if it exists, which will take precedence over the primary configuration.

It's recommended that the user config file stays out of version control. It should be based on the following code to patch the primary config:

"use strict";

let conf = require("./build.conf");

// modify conf

module.exports = conf;

Top-Level Configuration

The configuration object has a number of fields that affect compilation globally.

keyvalue
browerSyncA configuration object passed directly to browserSync. Omit the object to turn off browserSync.
presetThe default preset name to use.
presetsA hashmap of defined presets.
transformsThe list of transforms to apply when building.

Transforms

All transforms are plain JS objects with some specific keys.

Every transform may specify these keys:

keyvalue
type(required) The type of transform to use.
idAn optional unique ID for this transform. Duplicates are removed.
nameA friendly name for the transform.
source(required) This transform's input files.
dest(required) This transform's output location.
disabledWhether this transform is turned off by default. Defaults to false.
configExtra parameters specific to the transform.

By specifying the same id in two transforms, values can be overridden in more specific contexts. Defining a transform with id of "test" in the base configuration, then defining another transform with the same id in a preset will allow the preset to override values.

For example:

{
	presets: {
		production: {
			out: "production",
			transforms: [
				{
					id: "test",
					disabled: true
				}
			]
		}
	},
	transforms: [
		{
			id: "test",
			name: "Test the Things!",
			type: "static",
			source: "src",
			dest: ""
		}
	]
}

Here, when running in most any preset, the test transform will copy some files around. When the production preset is activated, the transform will be disabled.

type server

The server transform compiles TypeScript files recursively, targeted at server environments.

The config parameter is passed directly to the TypeScript compiler.

keyvalue
extraEntriesExtra entries to pass to the TS compiler, usually typings (.d.ts) files

type browser

The browser transform compiles an entry point TypeScript file and its dependencies into a Browserify bundle.

The config parameter is passed directly to the TypeScript compiler.

keyvalue
extraEntriesExtra entries to pass to the TS compiler, usually typings (.d.ts) files
rootDirThe root to resolve absolute paths from. Only relevant with 'classic' resolution.

type styles

The styles transform compiles an entry point Sass file into a single CSS bundle.

The config parameter is an object with the following keys:

keyvalue
sassPassed directly to node-sass
autoprefixerPassed directly to autoprefixer
stylelintPassed directly to stylelint

type static

The static transform copies files as-is and applies no changes to them.

The config parameter is an object with the following keys:

keyvalue
renameRename the output to this file name. Only works if the input is a single file.

License

Basis is available under the MIT license. See LICENSE for more details.