Skip to content
This repository has been archived by the owner on May 20, 2022. It is now read-only.

Commit

Permalink
refactor code to be more modular and add passing tests (#18)
Browse files Browse the repository at this point in the history
*makefile

* refactor tests

* remove unnecessary logs

* add root dir to tests and npm link to docker file

* refactor symlink

* Refactor symlink code with tests (#24)

* Add CircleCI & codecov (#20)

* add node 4 & 6 in circle

* add codecov

* add codecov badge

* Add Linter (#21)
  • Loading branch information
millzpaugh authored Feb 21, 2018
1 parent 9c31d40 commit 1d87da4
Show file tree
Hide file tree
Showing 90 changed files with 32,730 additions and 277 deletions.
110 changes: 110 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
version: 2

step-library:
- &install-node-4
run:
name: Install node
command: |
set +e
curl -o- https://github.com/raw/creationix/nvm/v0.33.8/install.sh | bash
[ -s "${NVM_DIR}/nvm.sh" ] && \. "${NVM_DIR}/nvm.sh"
nvm install v4
nvm alias default v4
echo "[ -s \"${NVM_DIR}/nvm.sh\" ] && . \"${NVM_DIR}/nvm.sh\"" >> $BASH_ENV
- &install-node-6
run:
name: Install node
command: |
set +e
curl -o- https://github.com/raw/creationix/nvm/v0.33.8/install.sh | bash
[ -s "${NVM_DIR}/nvm.sh" ] && \. "${NVM_DIR}/nvm.sh"
nvm install v6
nvm alias default v6
echo "[ -s \"${NVM_DIR}/nvm.sh\" ] && . \"${NVM_DIR}/nvm.sh\"" >> $BASH_ENV
- &build-and-test
run:
name: Build and test
command: |
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
node -v
npm -v
npm install
npm link
npm test
- &build-and-test-codecov
run:
name: Build and test
command: |
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
node -v
npm -v
npm install
npm link
npm run report-coverage
jobs:
build-osx-node-4:
macos:
xcode: "9.0"
steps:
- checkout
- run: echo 'export NVM_DIR=${HOME}/.nvm' >> $BASH_ENV
- *install-node-4
- *build-and-test-codecov

build-osx-node-6:
macos:
xcode: "9.0"
steps:
- checkout
- run: echo 'export NVM_DIR=${HOME}/.nvm' >> $BASH_ENV
- *install-node-6
- *build-and-test

build-linux-docker-node-4:
docker:
- image: ubuntu:trusty
steps:
- checkout
- run:
name: libstdc++ upgrade
command: |
apt-get update -y
apt-get install -y software-properties-common python-software-properties || true
add-apt-repository -y ppa:ubuntu-toolchain-r/test
apt-get update -y
apt-get install -y libstdc++6 curl bash git
- run: echo 'export NVM_DIR=/opt/circleci/.nvm' >> $BASH_ENV
- *install-node-4
- *build-and-test

build-linux-docker-node-6:
docker:
- image: ubuntu:trusty
steps:
- checkout
- run:
name: libstdc++ upgrade
command: |
apt-get update -y
apt-get install -y software-properties-common python-software-properties || true
add-apt-repository -y ppa:ubuntu-toolchain-r/test
apt-get update -y
apt-get install -y libstdc++6 curl bash git
- run: echo 'export NVM_DIR=/opt/circleci/.nvm' >> $BASH_ENV
- *install-node-6
- *build-and-test

workflows:
version: 2
build-and-deploy:
jobs:
- build-osx-node-4
- build-osx-node-6
- build-linux-docker-node-4
- build-linux-docker-node-6
18 changes: 18 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"rules": {
"indent": [2, 2],
"quotes": [2, "single", { "allowTemplateLiterals": true }],
"no-console": [0],
"semi": [2, "always"],
},
"env": {
"node": true,
"es6": true
},
"globals": {
"process": true,
"module": true,
"require": true
},
"extends": "eslint:recommended"
}
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
.DS_Store
node_modules/
npm-debug.log
.env
.test-env
mason_packages/
mason.ini
include/
mason-versions.ini
.nyc_output/
coverage.lcov


notes.txt
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ RUN mkdir -p /tmp/mason-js-src
WORKDIR /tmp/mason-js-src
COPY . /tmp/mason-js-src

RUN npm install
RUN npm install
RUN npm link
CMD npm test
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
SHELL = /bin/bash

build:
docker build \
--build-arg NPMAccessToken="${NPMAccessToken}" \
--tag mason-js:latest .

bash:
docker run \
-it mason-js:latest bash

run: build
docker run \
-it mason-js:latest

test: build
docker run \
--tty \
--rm \
mason-js:latest \
npm test
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# mason-js
[![Build status](https://ci.appveyor.com/api/projects/status/ri4jpnad6fbhfna5?svg=true)](https://ci.appveyor.com/project/Mapbox/mason-js)

[![codecov](https://codecov.io/gh/mapbox/mason-js/branch/master/graph/badge.svg)](https://codecov.io/gh/mapbox/mason-js)

A Javascript client for Mason


19 changes: 19 additions & 0 deletions bin/help
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Usage:
mason-js install

or

mason-js install <package> <package type>

Description:
mason-js is a JS client for mason that installs c++ packages locally (both header-only and compiled). mason-js can install all packages declared in a mason-versions.ini file or it can install a single package.

Example:
mason-js install

OR

mason-js install protozero=1.5.1 --type=header

Options:
--type [header or compiled]
65 changes: 48 additions & 17 deletions bin/mason-js
Original file line number Diff line number Diff line change
@@ -1,36 +1,67 @@
#!/usr/bin/env node
var loader = require('../lib/retrieve_package.js');
var reader = require('../lib/ini_file_reader.js');
var sym = require('../lib/symlink.js');
var log = require('npmlog');
var fse = require('fs-extra');
var fs = require('fs');
var path = require('path');
var args = require('minimist')(process.argv.slice(2));

global.appRoot = process.cwd();
var masonPath = path.join(global.appRoot, '/mason-versions.ini');
var symlinkPath = path.join(global.appRoot, '/mason_packages/.link');

var filterFunc = (src, dest) => {
if (src.indexOf('mason.ini') > -1) {
return false;
} else if (fs.lstatSync(src).isFile()){
fs.symlinkSync(src,dest);
return false;
}else{
return true;
}
}

loader.install(masonPath, function(err, packageLists){
if (err) throw err;
function download(packages, callback){
log.info('Mason Package Install Starting');
loader.install(packages, function(err, packageLists){
if (err) throw err;

sym.buildLinkPaths(packageLists, function(err, symLinkPaths){
log.info('Creating Symlinks');
symLinkPaths.forEach(function(p){
fse.copySync(p[0], p[1], { clobber: true, filter:filterFunc });

var paths = sym.buildLinkPaths(packageLists,symlinkPath);
sym.symLink(paths, function(err, result){
if (err) return callback(err);
});
});
});
}

if (require.main === module) {
var install = args['_'][0];
var singlePackage = args['_'][1];
var type = args.type;

if (!install) {
console.error('missing mason-js args');
process.stdout.write(fs.readFileSync(__dirname + '/help', 'utf8'));
process.exit(1);
}

if (install === 'install' && !singlePackage){
reader.fileReader(masonPath, function(err, packages){
download(packages, function(err, result){
if (err) return callback(err);
log.info('Finished downloading packages')
});
});
}

// add more validation here
if (singlePackage && !args.type) {
console.error('include package type with package info: example protozero=1.5.1 --type=header');
process.stdout.write(fs.readFileSync(__dirname + '/help', 'utf8'));
process.exit(1);
}

if (install === 'install' && singlePackage && args.type){
var package = reader.buildParams(singlePackage, type);
download(package, function(err, result){
if (err) return callback(err);
});
}
}





Expand Down
12 changes: 0 additions & 12 deletions config.js

This file was deleted.

Loading

0 comments on commit 1d87da4

Please sign in to comment.