Skip to content
Permalink
Browse files

prepare the development environment

  • Loading branch information...
openql-org committed Sep 29, 2017
1 parent 96aaf12 commit 5b6395827c680b0df9c4c235b025286ac6955d9d
Showing with 293 additions and 0 deletions.
  1. +18 −0 .travis.yml
  2. +126 −0 gulpfile.js
  3. +5 −0 index.js
  4. +4 −0 main.js
  5. +71 −0 package.json
  6. +23 −0 src/header.js
  7. 0 src/index.js
  8. +17 −0 test/_index.test.js
  9. +6 −0 test/_main.test.js
  10. +6 −0 test/index.test.js
  11. +17 −0 webpack.config.js
@@ -0,0 +1,18 @@
language: node_js
node_js:
- "7"
- "6"
- "5"
- "4"

install:
- cd $TRAVIS_BUILD_DIR && npm install

script:
- cd $TRAVIS_BUILD_DIR && npm test

cache:
directories:
- "node_modules"

sudo: false
@@ -0,0 +1,126 @@
var gulp = require('gulp'),
gutil = require('gulp-util'),
mocha = require('gulp-mocha'),
sass = require('gulp-sass'),
webpack = require('webpack'),
uglify = require('gulp-uglify'),
documentation = require('gulp-documentation'),
rename = require('gulp-rename'),
del = require('del'),
fs = require('fs');

var HEADER = './src/header.js',
VERSION = './build/version.js',
TARGET_FILE = 'quant.js',
SRC_DIR = __dirname + '/src/',
TEST_DIR = __dirname + '/test/',
DOCS_DIR = __dirname + '/docs/',
BUILD_DIR = __dirname + '/build/',
ASSET_DIR = '/assets',
DIST_DIR = __dirname + '/dist/';

function createBanner() {
var today = gutil.date(new Date(), 'yyyy-mm-dd'); // today, formatted as yyyy-mm-dd
var version = require('./package.json').version;
var year = gutil.date(new Date(), 'yyyy');
return String(fs.readFileSync(HEADER))
.replace('@@date', today)
.replace('@@year', year)
.replace('@@version', version);
}

function updateVersionFile() {
var version = require('./package.json').version;
fs.writeFileSync(VERSION, 'module.exports = \'' + version + '\';\n' +
'// Note: This file is automatically generated when building quant.js.\n' +
'// Changes made in this file will be overwritten.\n');
}

var webpackConfig = require('./webpack.config');
webpackConfig.plugins = [
new webpack.BannerPlugin({
banner: createBanner(),
entryOnly: true,
raw: true
}),
];
var compiler = webpack(webpackConfig);

var uglifyConfig = {
sourceMap: true,
output: {
comments: /@license/
}
};

gulp.task('bundle', ['html','build'], function (cb) {
compiler.run(function (err, stats) {
if (err) {
gutil.log(err);
}
cb();
});
});

gulp.task('minify', ['bundle'], function () {
return gulp.src(DIST_DIR + TARGET_FILE)
.pipe(uglify(uglifyConfig))
.on('error', function (err) { gutil.log(gutil.colors.red('[Error]'), err.toString()); })
.pipe(rename({ extname: '.min.js' }))
.pipe(gulp.dest(DIST_DIR));
});

gulp.task('html', ['html-copy'], function() {
return gulp.src(BUILD_DIR + '**/*.html')
.pipe(gulp.dest(DIST_DIR));
});

gulp.task('html-copy', function() {
return gulp.src(SRC_DIR + '**/*.html')
.pipe(gulp.dest(BUILD_DIR));
});

gulp.task('style', function() {
return gulp.src(SRC_DIR + '**/*.scss')
.pipe(sass({outputStyle: 'expanded'}))
.pipe(gulp.dest(BUILD_DIR + ASSET_DIR));
});

gulp.task('js-copy', function() {
return gulp.src([SRC_DIR + '**/*.js', '!'+HEADER])
.pipe(gulp.dest(BUILD_DIR));
});

gulp.task('test', ['build'], function() {
return gulp.src([TEST_DIR + "**/*test.js"], {read: false})
.pipe(mocha({reporter: 'spec'}))
.on('error', function(){});
});

gulp.task('docs', function () {
return gulp.src([BUILD_DIR + '**/*.js'])
.pipe(documentation('md'))
.pipe(gulp.dest(DOCS_DIR));
});

gulp.task('watch', function () {
gulp.watch(
[ __dirname + '/app.js',
__dirname + '/main.js',
SRC_DIR + '**/*.js'
], ['bundle','test']);
gulp.watch([SRC_DIR + '**/*.scss'], ['bundle']);
gulp.watch([SRC_DIR + '**/*.html'], ['html']);
});

gulp.task('build', ['html-copy','style','js-copy'], function() {
updateVersionFile();
});
gulp.task('compile', ['build']);
gulp.task('coverage', ['test']);
gulp.task('clean', del.bind(null, [BUILD_DIR, DIST_DIR,'**/*.log']));
gulp.task('dist-clean', ['clean'], del.bind(null,
[ __dirname + '/node_modules',
__dirname + '/coverage',
]));
gulp.task('default', ['bundle','minify','docs']);
@@ -0,0 +1,5 @@
var main = require('./main');
function init() {
return main;
}
exports = module.exports = init;
@@ -0,0 +1,4 @@
var version = require('./build/version');
if(module.require) {
} else {
}
@@ -0,0 +1,71 @@
{
"name": "quantjs",
"version": "0.0.1",
"description": "QuantJS is a Javascript library for quantum computing. It aims to become basic library set of quantum computer system.",
"license": "Apache-2.0",
"main": "index.js",
"scripts": {
"test": "nyc --reporter=html --reporter=text gulp test",
"gulp": "gulp",
"compile": "gulp compile",
"build": "gulp build",
"bundle": "gulp bundle",
"watch": "gulp watch",
"docs": "gulp docs",
"clean": "gulp clean",
"dist-clean": "gulp dist-clean",
"coverage": "nyc --reporter=html --reporter=text gulp test",
"report": "nyc report --reporter=text"
},
"nyc": {
"include": [
"build/**/*.js"
]
},
"directories": {
"doc": "docs",
"example": "examples",
"lib": "lib",
"test": "test"
},
"repository": {
"type": "git",
"url": "https://github.com/openql-org/quantjs.git"
},
"dependencies": {
"mathjs": "^3.16.1",
"mersennetwister": "^0.2.3"
},
"devDependencies": {
"browserify": "^14.4.0",
"chai": "^4.1.1",
"css-loader": "^0.28.4",
"del": "^3.0.0",
"documentation": "^5.2.1",
"gulp": "^3.9.1",
"gulp-documentation": "^3.2.1",
"gulp-mocha": "^4.3.1",
"gulp-rename": "^1.2.2",
"gulp-sass": "^3.1.0",
"gulp-uglify": "^3.0.0",
"gulp-util": "^3.0.8",
"jsdom": "^11.1.0",
"mocha": "^3.5.0",
"mocha-jsdom": "^1.1.0",
"node-sass": "^4.5.3",
"nyc": "^11.1.0",
"style-loader": "^0.18.2",
"webpack": "^3.5.4"
},
"keywords": [
"OpenQL",
"openql",
"quantum computing"
],
"homepage": "http://quantjs.org/",
"bugs": {
"url": "https://github.com/openql-org/quantjs/issues"
},
"author": "committer | OpenQL Project <committer@openql.org>",
"contributors": []
}
@@ -0,0 +1,23 @@
/**
* quantjs
* https://github.com/openql-org/quantjs
*
*
* @version @@version
* @date @@date
*
* @license
* Copyright 2017 OpenQL Project <committer@openql.org>
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
No changes.
@@ -0,0 +1,17 @@
var assert = require('assert');
var testee = require('../index');
var testee_name = 'index';

describe(testee_name, function() {
describe('exporter', function() {
describe('init', function() {
var init = testee;
it('should be implemented', function() {
assert(init != undefined);
});
it('should be called', function() {
assert(init({}) !== undefined);
});
});
});
});
@@ -0,0 +1,6 @@
var assert = require('assert');
var testee = require('../main');
var testee_name = 'main';

describe(testee_name, function() {
});
@@ -0,0 +1,6 @@
var assert = require('assert');
var testee = require('../build/index');
var testee_name = 'index';

describe(testee_name, function() {
});
@@ -0,0 +1,17 @@
module.exports = {
module: {
rules: [{
test: /\.css$/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader' }
]
}]
},
entry: './index',
output: {
libraryTarget: 'umd',
path: __dirname + '/dist',
filename: 'q-face.js',
},
};

0 comments on commit 5b63958

Please sign in to comment.
You can’t perform that action at this time.