5.0.7 • Published 8 months ago

build-strap v5.0.7

Weekly downloads
78
License
MIT
Repository
github
Last release
8 months ago

build-strap

A suite of functions to help with writing build scripts using javascript code (which run on node).

This project builds itself, so take a look in the tools/ folder for an example project. Run ./bs to build.

Build Status

Create a "zero dependency" bootstrapped build

You can set up your project to build with (practically) no pre-requisite dependencies. Simply: 1. Copy the *.sh, *.ps1, and *.bat files from the root of this repository into the root of your project. 2. Modify nodeBootstrap.sh and nodeBootstrap.ps1 to use the desired version of node.

Add the dependency reference

Add build-strap to your package.json (likely in the devDependencies section).

yarn add -D build-strap

Add meta information to your package.json

By default, the build tools read project-specific configuration from your package.json file. Add this information as needed for your specific project.

{
  "name": "your-project-name",
  "version": "1.2.3",
  "buildStrap": {
    "repoType": "git",
    "copyright": "your company",
    "releaseBranch": "master",
    "devBranch": "dev",
    "npm": {
      "publish": true,
    },
    "artifactory": {
      "root": "https://artifactory.your-company.com/artifactory/",
      "path": "com/your-company/your-project-name",
      "version-folders": false,
      "integration": "integration-repo",
      "integration-branch-folders": true,
      "integration-days-to-keep": 14,
      "integration-max-to-keep": 10,
      "release": "releases-repo",
      "release-branch": "master",
      "npm": "npm-repo",
      "npm-clean": "internal-npm-repo"
    },
    "docker": {
      "registry": "artifactory.your-company.com",
      "repository": "your-company",
      "name": "your-project-name"
    }
  }
}

artifactory

  • root: base URL for the artifactory server
  • path: path to project root in the artifactory tree.
  • version-folders: if true, artifacts will be organized into subfolders for each version number
  • integration: name of the artifactory repo in which to place integration (not official release) artifacts.
  • integration-branch-folders: if true, artifacts will be organized into subfolders for each branch.
  • integration-days-to-keep: for artifact cleanup, specifies the max age in days before an artifact will be deleted.
  • integration-max-to-keep: for artifact cleanup, specifies the maximum number of artifacts to keep, regardless of age. Only the newest N artifacts will be kept.
  • release: name of the artifactory repo in which to place release artifacts.
  • release-branch: name of the mercurial branch from which official releases are built/published. Defaults to master.
  • npm: name of the artifactory repo in which to publish npm artifacts.
  • npm-clean: for artifact cleanup, the name of the artifactory repo used to find and delete old npm artifacts.

docker

  • registry: base URL for the docker registry, as needed by docker push.
  • repository: the name of the (organization's) docker repository, in which to put this project
  • name: the name of the project, used as the docker image name.

Write Your Build Script

See the reference implementations (below) for a complete example of a robust build environment. The library exports many useful functions. Here are some of the most important (see source for more):

setPkg

This function must be called for much of the functionality (that reads configuration from the package.json) to work. Pass it a javascript object containing the parsed content of package.json (or construct the object config directly in code).

import { setPkg } from 'build-strap';
import pkg from '../package.json';

// Call this before anything else.
setPkg(pkg);
...

runCli

Useful when building your own build from scratch. Helps to interpret CLI arguments and invoke js files as build targets. Uses buildLog to timestamp everything.

This example should serve as your entrypoint (from yarn run).

import { run, runCli, setPkg } from 'build-strap';
import pkg from '../package.json';

setPkg(pkg);

if (require.main === module) {
  delete require.cache[__filename];
  runCli(path => require(`./${path}`).default);
}

publish

Takes the contents of a directory, gzips it up, and publishes to various artifact repositories (as configured in your package.json, see above).

import { publish } from 'build-strap';

publish(
  'path/to/dist/folder',
  'path/to/output.tgz',
  reallyPublish, // `true` to actually publish, otherwise just make the bundle
);

buildLog

Write out to the console in a timestamp prefixed format consistent with the rest of the build output.

import { buildLog } from 'build-strap';

buildLog('Hello world');

NPM Credentials

In order to publish to NPM, proper credentials must be provided to the script. By default, these are read from the NPM_CREDS environment variable, but it is also possible to pass them as an argument to most functions. This is expected to be a JSON encoded string in the following format:

{ "email": "builder@your-company.com", "username":"builder", "password":"abc123" }

Artifactory Credentials

In order to publish and/or delete things from Artifactory, proper credentials must be provided to the script. By default, these are read from the ARTIFACTORY_CREDS environment variable, but it is also possible to pass them as an argument to most functions. This is expected to be a JSON encoded string in the following format:

{ "email": "builder@your-company.com", "username":"builder", "password":"abc123" }
5.0.7-dev.116

8 months ago

5.0.4-dev.115

8 months ago

5.0.7

8 months ago

5.0.6

1 year ago

5.0.5

1 year ago

5.0.4-dev.106

1 year ago

5.0.4-dev.105

1 year ago

5.0.4

1 year ago

5.0.3-dev.92

2 years ago

5.0.3-dev.95

2 years ago

5.0.3

2 years ago

3.0.0-dev.45

2 years ago

4.1.1-dev.64

2 years ago

5.0.0-dev.70

2 years ago

5.0.0-dev.71

2 years ago

4.0.0-dev.46

2 years ago

5.0.0-dev.77

2 years ago

5.0.0-dev.78

2 years ago

3.0.0-dev.42

2 years ago

5.0.0-dev.72

2 years ago

5.0.0-dev.73

2 years ago

5.0.0-dev.74

2 years ago

5.0.0-dev.69

2 years ago

4.0.0-dev.1

2 years ago

4.1.0-dev.58

2 years ago

4.0.0-dev.2

2 years ago

4.1.0-dev.59

2 years ago

4.0.0-dev.3

2 years ago

4.0.0-dev.4

2 years ago

4.0.0-dev.5

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

5.0.0-dev.65

2 years ago

5.0.0-dev.66

2 years ago

5.0.0-dev.67

2 years ago

5.0.0-dev.68

2 years ago

5.0.2

2 years ago

5.0.1

2 years ago

5.0.0

2 years ago

4.1.0-dev.61

2 years ago

4.1.0-dev.62

2 years ago

4.1.0-dev.60

2 years ago

4.0.0-dev.55

2 years ago

4.0.0-dev.56

2 years ago

4.0.0-dev.53

2 years ago

4.0.0-dev.54

2 years ago

4.0.0-dev.52

2 years ago

5.0.2-dev.83

2 years ago

4.1.0

2 years ago

3.0.0-dev.40

3 years ago

3.0.0-dev.37

3 years ago

3.0.0-dev.34

3 years ago

3.0.0-dev.31

3 years ago

3.0.0-dev.27

3 years ago

3.0.0

3 years ago

2.1.0-dev.26

3 years ago

2.1.0-dev.23

3 years ago

2.1.0-dev.20

3 years ago

2.1.0-dev.17

3 years ago

2.1.0-dev.14

3 years ago

2.1.0-dev.11

4 years ago

2.0.1

4 years ago

2.1.0-dev.9

4 years ago

2.1.0-dev.8

4 years ago

2.1.0-dev.7

4 years ago

2.1.0-dev.5

4 years ago

2.0.0

4 years ago

2.0.0-dev.3

4 years ago

2.0.0-dev.1

4 years ago

2.0.0-dev.2

4 years ago

2.0.0-dev.47

4 years ago

2.0.0-dev.48

4 years ago

2.0.0-dev.45

4 years ago

2.0.0-dev.46

4 years ago

1.2.1-dev.44

4 years ago

1.2.1-dev.43

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago