Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
build-tools
Advanced tools
A set of CLI commands to develop, package, and release web apps that use ES6
This package makes it easy to develop web applications that use the latest ES6 syntax. It can also work for smaller projects like libraries and NPM packages. It does this by exposing a small set of easy-to-use CLI commands to quickly compile files, test, deploy, and even create releases for your entire project.
This package requires Node >=7.0.
You can install Node.js via the package provided on their site. Installing node will also install the Node Package Manager (NPM) to download and install node modules.
You can provide the commands configuration options for you specific needs. Although you can pass many configuration options directly through the command-line, it may not be as intuitive and the command (with a lot of arguments) can get rather long, making them harder to maintain over time. As an alternative, you can create and use a bt-config.js
configuration file for your project's configurations when running commands. This allows you to be explicit about your projects needs and give you more overall flexibility.
To use a configuration file, just create a new file and name it bt-config.js
and put it at the root level of your github project. Then module.export
any configurations required by the commands below, then you can just run associated commands with no arguments and it will use the values from the bt-config.js
file.
Installing Build Tools as a global module will give you command-line access to all tasks available.
You can install globally by typing the following in your terminal:
npm install build-tools -g
To start a local server on port 8200 that serves the "blah" directory in your project using your own custom middleware myServer.js file, just run the following command (all arguments are optional):
bt server --port=8200 --staticDir=./blah middleware=./myServer.js
Providing no arguments will serve the root directory of your project on localhost via port 7000, and use express's standard middleware by default.
You can also start a server based on configuration that you specify in your bt-config.js file.
module.exports = {
production: {
server: {
hostname: 'localhost',
staticDir: './blah',
middleware: './myServer.js',
port: 8200
}
},
};
Then you can just run bt server production
.
The build
command builds all of your files into a distribution folder for deployment.
It will do things like compile all of your application's javascript files into single files using browserify (ES6 files are supported),
sassify all of your scss files, minify files, and even add banners to your files if desired.
First you need to specify the files you want the build command to use in your bt-config.js
file. For instance,
if you wanted to build both a main.js file and a scss file into a folder called dist
, then minify the js file, your bt-config.js
file would look a little like this:
module.exports = {
production: {
build: {
files: {
'dist/app.js': ['src/main.js'],
'dist/styles.css': ['src/styles/main.scss']
},
minifyFiles: {
'dist/app.js': ['dist/app.js']
},
requires: {
"my-code": "./app/my-script" // makes 'my-code' as a global package name in your bundle
},
bannerFiles: ['dist/*'],
"browserifyOptions": {},
watch: false
}
},
};
Option | Type | Description |
---|---|---|
files | Object | An object containing a mapping of output files (keys) to their source files (values) |
minifyFiles | Object | An object containing a mapping of output files (keys) to the files that should be minified (values) |
requires | Array | Object |
bannerFiles | Array | Files that a banner will be added to (after build has completed) |
browserifyOptions | Object | Browserify options. |
watch | Boolean | Whether to watch the built files for changes and rebuilt afterwards. Defaults to false. |
Then you can run the build command in your terminal:
bt build
By default, the build
command assumes a "production" build, will run production tests (if specified in your bt-config.js file)
and does not watch your files as you edit them.
If you want your files to be "watched" and built on the fly as you edit them, pass the local
option when running the
terminal command like this:
bt build local
And of course you can pass the same build arguments as mentioned above:
bt build local --port=6500 --staticDir=./build
Arguments allowed are:
Argument | Type | Description |
---|---|---|
port | Number | The port number to start the server on (if local is passed) |
staticDir | String | The path (relative to he project root) containing the files that should be served when the server starts |
watch | Boolean | Whether to watch the files and rebuild if necessary. Defaults to true. |
Because the bt build
command compiles before being available in the browser, this command will inject your current
environment variable into the process.env.NODE_ENV
variable in your javascript. So you can do things like the
following, even in your client-side files!
if (process.env.NODE_ENV === 'production') {
// do things for production environment
} else {
// do things for non-production environment
}
Remember that this variable will be either the env
variable you pass into your bt build
call or the REAL NODE_ENV
variable
in your environment.
The test
command will run all tests in any given environment. The following test files are supported:
Make sure you have the tests
configuration setup in your bt-config.js
file like below:
module.exports = {
production: {
"tests": {
"qunit": {
"files": ["tests/**/*"],
},
"mocha": {
"files": ["path/to/mocha/tests/*"],
},
"browserifyOptions": {}
}
}
};
Option | Type | Description |
---|---|---|
qunit | Object | Options to use for qunit test compiling |
qunit.files | Array | An array of file paths (or glob patterns) to be compiled and tested using QUnit |
mocha | Object | Options to use for mocha tests |
mocha.files | Array | An array of file paths (or glob patterns) to be compiled and tested using Mocha |
browserifyOptions | Object | Browserify options. |
Once that's done, just run the following in your terminal:
bt test
The command will run all test files you have specified in your production configuration, headlessly.
If you want to run tests for another environment (and you have that environment set up in your configuration file), you can do:
bt test --env=development
You also have the option of running tests in the browser by doing:
bt test qunit server
Which will run your tests in the browser located at http://localhost:7755.
The release
command offers a quick way to create, package, and publish a version of your project to both Github and NPM.
NOTE: Before using the release
command, you must be logged into NPM if you'd like your package to automatically be published.
bt release [SEMVER]
Replacing [SEMVER] with (major
, minor
or patch
) (patch
is the default if nothing is supplied).
The bt release
command does the following:
package.json
(and any associated lock files) to the new versionbt release
arguments can be passed with command:
bt release --draft=true
Argument | Type | Description |
---|---|---|
draft | Boolean | true to upload release to Github as "unpublished", false otherwise (defaults to false ) |
prerelease | Boolean | true to mark release as "pre" (defaults to false ) |
It is recommended to only run this command when you're on a production-ready branch, since that is where all relevant commits have already been committed, and is less likely to have convoluted commits that you might not want in your new version.
In order to have your release published on github, you must generate a github token
and add it under the github
property of your bt-config file:
module.exports = {
"github": {
"token": "s65495jkgljkgskjfdigf", // the generated github token
"user": "githubUserName", // the github username that contains the access token
"repo": "my-repo", // the github repo name (optional, assumes local repository)
}
};
You can also pass github arguments to the cli command:
bt release --user=githubUserName --repo=my-repo --token=s65495jkgljkgskjfdigf
The bt deploy
command allows you to upload files to a server of your choosing.
You can pass options as arguments to your cli command:
bt deploy --hostname=555.555.555.55 --port=22 --path=dist --username=user --password=secret
or you can specify the options in your bt-config.js
file
module.exports = {
deploy: {
hostname: '555.555.555.55',
username: 'user',
password: 'secret',
path: 'dist',
protocol: 'sftp',
remoteDir: '/', // defaults to home directory
port: 22,
exclude: [
'.gitignore',
'node_modules/**'
]
}
};
Then you can just run bt deploy
.
If you need to have a deploy configuration for multiple environments, you can just nest your configuration under
the id of the environment. The example below assigns the deploy configuration to the production
environment.
module.exports = {
deploy: {
production: {
hostname: '555.555.555.55',
username: 'user',
password: 'secret',
path: 'dist',
protocol: 'sftp',
port: 22,
}
}
};
Then just run bt deploy production
.
When running any of the commands that package your project (i.e. bt build
, bt release
, etc), this lib takes care
of determining what file types are a part of your build and spawns off different compilation tasks outlined below.
When detecting a file with a .scss extension, it is compiled into the new css file that you specify in your bt-config file. It will also do some small but helpful tasks like add any necessary vendor prefixes to your css and minify it for performance. It does also make a css.map file which you can use when debugging or viewing the source.
npm install
npm test
FAQs
A set of CLI commands to develop, package, and release web apps that use ES6
We found that build-tools demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.