From 76047590e514755b9a1667df1f70b28c48f2cede Mon Sep 17 00:00:00 2001 From: Martin Gustafsson Date: Fri, 19 Aug 2016 15:00:52 +0200 Subject: [PATCH] refactor(all): update repo structure --- .editorconfig | 14 + .eslintrc.json | 7 + .gitignore | 11 +- .npmignore | 11 +- .travis.yml | 3 - .vscode/launch.json | 40 - README.md | 2 +- bower.json | 25 + build/args.js | 13 + build/babel-options.js | 65 + build/paths.js | 61 + build/tasks/build.js | 130 + build/tasks/clean.js | 9 + build/tasks/dev.js | 10 + build/tasks/doc.js | 46 + build/tasks/lint.js | 10 + build/tasks/prepare-release.js | 33 + build/tasks/test.js | 23 + build/typescript-options.js | 9 + circle.yml | 23 + doc/CHANGELOG.md | 0 doc/api.json | 1 + gulpfile.js | 96 +- package.json | 81 +- spec/support/jasmine.json | 11 - source/disposeable.ts => src/disposeable.js | 0 source/dom.ts => src/dom.js | 0 source/feature.ts => src/feature.js | 0 source/global.ts => src/global.js | 0 source/index.ts => src/index.js | 2 +- source/nodejs-dom.ts => src/nodejs-dom.js | 10 +- .../nodejs-feature.js | 4 +- .../nodejs-mutation-emulator.js | 58 +- .../nodejs-mutation-observer.js | 12 +- .../nodejs-platform.js | 8 +- source/observer.ts => src/observer.js | 0 source/performance.ts => src/performance.js | 0 source/platform.ts => src/platform.js | 0 .../nodejs-dom.spec.js | 2 +- .../nodejs-mutation-source.spec.js | 56 +- .../nodejs-platform.spec.js | 2 +- tsconfig.json | 38 +- typings.json | 7 +- typings/custom/jsdom.d.ts | 192 -- typings/globals/jasmine/index.d.ts | 501 ---- typings/globals/jasmine/typings.json | 8 - typings/globals/node/index.d.ts | 2472 ----------------- typings/globals/node/typings.json | 14 - typings/index.d.ts | 3 - 49 files changed, 653 insertions(+), 3470 deletions(-) create mode 100644 .editorconfig create mode 100644 .eslintrc.json delete mode 100644 .travis.yml delete mode 100644 .vscode/launch.json create mode 100644 bower.json create mode 100644 build/args.js create mode 100644 build/babel-options.js create mode 100644 build/paths.js create mode 100644 build/tasks/build.js create mode 100644 build/tasks/clean.js create mode 100644 build/tasks/dev.js create mode 100644 build/tasks/doc.js create mode 100644 build/tasks/lint.js create mode 100644 build/tasks/prepare-release.js create mode 100644 build/tasks/test.js create mode 100644 build/typescript-options.js create mode 100644 circle.yml create mode 100644 doc/CHANGELOG.md create mode 100644 doc/api.json delete mode 100644 spec/support/jasmine.json rename source/disposeable.ts => src/disposeable.js (100%) rename source/dom.ts => src/dom.js (100%) rename source/feature.ts => src/feature.js (100%) rename source/global.ts => src/global.js (100%) rename source/index.ts => src/index.js (99%) rename source/nodejs-dom.ts => src/nodejs-dom.js (91%) rename source/nodejs-feature.ts => src/nodejs-feature.js (74%) rename source/nodejs-mutation-emulator.ts => src/nodejs-mutation-emulator.js (77%) rename source/nodejs-mutation-observer.ts => src/nodejs-mutation-observer.js (71%) rename source/nodejs-platform.ts => src/nodejs-platform.js (91%) rename source/observer.ts => src/observer.js (100%) rename source/performance.ts => src/performance.js (100%) rename source/platform.ts => src/platform.js (100%) rename spec/nodejs-dom.spec.ts => test/nodejs-dom.spec.js (98%) rename spec/nodejs-mutation-source.spec.ts => test/nodejs-mutation-source.spec.js (66%) rename spec/nodejs-platform.spec.ts => test/nodejs-platform.spec.js (96%) delete mode 100644 typings/custom/jsdom.d.ts delete mode 100644 typings/globals/jasmine/index.d.ts delete mode 100644 typings/globals/jasmine/typings.json delete mode 100644 typings/globals/node/index.d.ts delete mode 100644 typings/globals/node/typings.json delete mode 100644 typings/index.d.ts diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..1033e2d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +# EditorConfig is awesome: http://EditorConfig.org + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +end_of_line = lf +insert_final_newline = true + +# 2 space indentation +[**.*] +indent_style = space +indent_size = 2 \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..107c619 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,7 @@ +{ + "extends": "./node_modules/aurelia-tools/.eslintrc.json", + "rules": { + "no-cond-assign": 0, + "no-extend-native": 0 + } +} diff --git a/.gitignore b/.gitignore index 70ad04c..76489e1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ -**/node_modules -**/jspm_packages -**/*.map -spec/**/*.js -dist/ \ No newline at end of file +node_modules +jspm_packages +bower_components +.idea +.DS_STORE +build/reports diff --git a/.npmignore b/.npmignore index 8ec264a..cafe9b6 100644 --- a/.npmignore +++ b/.npmignore @@ -1,8 +1,3 @@ -source -spec -.vscode -typings -**/*.map -tsconfig.json -typings.json -gulpfile.js \ No newline at end of file +jspm_packages +bower_components +.idea \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b5dc9e1..0000000 --- a/.travis.yml +++ /dev/null @@ -1,3 +0,0 @@ -language: node_js -node_js: - - "5" \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 684a4e6..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "Launch", - "type": "node", - "request": "launch", - "program": "${workspaceRoot}/node_modules/gulp/bin/gulp.js", - "stopOnEntry": false, - "args": [ - "test-no-compile" - ], - "cwd": "${workspaceRoot}", - "preLaunchTask": "compile:tests", - "internalConsoleOptions": "openOnSessionStart", - "runtimeExecutable": null, - "runtimeArgs": [ - "--nolazy" - ], - "env": { - "NODE_ENV": "development" - }, - "externalConsole": false, - "sourceMaps": true, - "outDir": "${workspaceRoot}/dist" - }, - { - "name": "Attach", - "type": "node", - "request": "attach", - "port": 5858, - "address": "localhost", - "restart": false, - "sourceMaps": true, - "outDir": "${workspaceRoot}/dist", - "localRoot": "${workspaceRoot}", - "remoteRoot": null - } - ] -} diff --git a/README.md b/README.md index 8760e7b..970f0c9 100644 --- a/README.md +++ b/README.md @@ -31,4 +31,4 @@ To build the code, follow these steps. ```shell npm test ``` -5. You will find the compiled code in the `dist` folder, available in CommonJS module format. +5. You will find the compiled code in the `dist` folder, available in AMD, CommonJS and ES6 module formats. diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..c913ee5 --- /dev/null +++ b/bower.json @@ -0,0 +1,25 @@ +{ + "name": "aurelia-pal-nodejs", + "version": "0.1.0", + "description": "The Node.js-specific implementation of Aurelia's platform abstraction layer.", + "keywords": [ + "aurelia", + "pal", + "nodejs" + ], + "homepage": "http://aurelia.io", + "main": "dist/commonjs/aurelia-pal-nodejs.js", + "moduleType": "node", + "license": "MIT", + "authors": [ + "Rob Eisenberg (http://robeisenberg.com/)" + ], + "repository": { + "type": "git", + "url": "http://github.com/aurelia/pal-nodejs" + }, + "dependencies": { + "aurelia-pal": "^1.0.0", + "jsdom": "^9.2.1" + } +} diff --git a/build/args.js b/build/args.js new file mode 100644 index 0000000..db342fc --- /dev/null +++ b/build/args.js @@ -0,0 +1,13 @@ +var yargs = require('yargs'); + +var argv = yargs.argv, + validBumpTypes = "major|minor|patch|prerelease".split("|"), + bump = (argv.bump || 'patch').toLowerCase(); + +if(validBumpTypes.indexOf(bump) === -1) { + throw new Error('Unrecognized bump "' + bump + '".'); +} + +module.exports = { + bump: bump +}; diff --git a/build/babel-options.js b/build/babel-options.js new file mode 100644 index 0000000..3e99af9 --- /dev/null +++ b/build/babel-options.js @@ -0,0 +1,65 @@ +var path = require('path'); +var paths = require('./paths'); + +exports.base = function() { + var config = { + filename: '', + filenameRelative: '', + sourceMap: true, + sourceRoot: '', + moduleRoot: path.resolve('src').replace(/\\/g, '/'), + moduleIds: false, + comments: false, + compact: false, + code: true, + presets: [ 'es2015-loose', 'stage-1' ], + plugins: [ + 'syntax-flow', + 'transform-decorators-legacy', + ] + }; + if (!paths.useTypeScriptForDTS) { + config.plugins.push( + ['babel-dts-generator', { + packageName: paths.packageName, + typings: '', + suppressModulePath: true, + suppressComments: false, + memberOutputFilter: /^_.*/, + suppressAmbientDeclaration: true + }] + ); + }; + config.plugins.push('transform-flow-strip-types'); + return config; +} + +exports.commonjs = function() { + var options = exports.base(); + options.plugins.push('transform-es2015-modules-commonjs'); + return options; +}; + +exports.amd = function() { + var options = exports.base(); + options.plugins.push('transform-es2015-modules-amd'); + return options; +}; + +exports.system = function() { + var options = exports.base(); + options.plugins.push('transform-es2015-modules-systemjs'); + return options; +}; + +exports.es2015 = function() { + var options = exports.base(); + options.presets = ['stage-1'] + return options; +}; + +exports['native-modules'] = function() { + var options = exports.base(); + options.presets[0] = 'es2015-loose-native-modules'; + return options; +} diff --git a/build/paths.js b/build/paths.js new file mode 100644 index 0000000..7ea6276 --- /dev/null +++ b/build/paths.js @@ -0,0 +1,61 @@ +var path = require('path'); +var fs = require('fs'); + +var appRoot = 'src/'; +var pkg = JSON.parse(fs.readFileSync('./package.json', 'utf-8')); + +module.exports = { + root: appRoot, + source: appRoot + '**/*.js', + html: appRoot + '**/*.html', + style: 'styles/**/*.css', + output: 'dist/', + doc:'./doc', + e2eSpecsSrc: 'test/e2e/src/*.js', + e2eSpecsDist: 'test/e2e/dist/', + packageName: pkg.name +};var path = require('path'); +var fs = require('fs'); + +// hide warning // +var emitter = require('events'); +emitter.defaultMaxListeners = 20; + +var appRoot = 'src/'; +var pkg = JSON.parse(fs.readFileSync('./package.json', 'utf-8')); + +var paths = { + root: appRoot, + source: appRoot + '**/*.js', + html: appRoot + '**/*.html', + style: 'styles/**/*.css', + output: 'dist/', + doc:'./doc', + e2eSpecsSrc: 'test/e2e/src/*.js', + e2eSpecsDist: 'test/e2e/dist/', + packageName: pkg.name, + ignore: [], + useTypeScriptForDTS: false, + importsToAdd: [], + sort: false +}; + +paths.files = [ +'disposeable.js', +'dom.js', +'feature.js', +'global.js', +'index.js', +'nodejs-dom.js', +'nodejs-feature.js', +'nodejs-mutation-emulator.js', +'nodejs-mutation-observer.js', +'nodejs-platform.js', +'observer.js', +'performance.js', +'platform.js' +].map(function(file){ + return paths.root + file; +}); + +module.exports = paths; diff --git a/build/tasks/build.js b/build/tasks/build.js new file mode 100644 index 0000000..b37ba4d --- /dev/null +++ b/build/tasks/build.js @@ -0,0 +1,130 @@ +var gulp = require('gulp'); +var runSequence = require('run-sequence'); +var to5 = require('gulp-babel'); +var paths = require('../paths'); +var compilerOptions = require('../babel-options'); +var compilerTsOptions = require('../typescript-options'); +var assign = Object.assign || require('object.assign'); +var through2 = require('through2'); +var concat = require('gulp-concat'); +var insert = require('gulp-insert'); +var rename = require('gulp-rename'); +var tools = require('aurelia-tools'); +var ts = require('gulp-typescript'); +var gutil = require('gulp-util'); +var gulpIgnore = require('gulp-ignore'); +var merge = require('merge2'); +var jsName = paths.packageName + '.js'; +var compileToModules = ['es2015', 'commonjs', 'amd', 'system', 'native-modules']; + +function cleanGeneratedCode() { + return through2.obj(function(file, enc, callback) { + file.contents = new Buffer(tools.cleanGeneratedCode(file.contents.toString('utf8'))); + this.push(file); + return callback(); + }); +} + +gulp.task('build-index', function() { + var importsToAdd = paths.importsToAdd.slice(); + + var src = gulp.src(paths.files); + + if (paths.sort) { + src = src.pipe(tools.sortFiles()); + } + + if (paths.ignore) { + paths.ignore.forEach(function(filename){ + src = src.pipe(gulpIgnore.exclude(filename)); + }); + } + + return src.pipe(through2.obj(function(file, enc, callback) { + file.contents = new Buffer(tools.extractImports(file.contents.toString('utf8'), importsToAdd)); + this.push(file); + return callback(); + })) + .pipe(concat(jsName)) + .pipe(insert.transform(function(contents) { + return tools.createImportBlock(importsToAdd) + contents; + })) + .pipe(gulp.dest(paths.output)); +}); + +function gulpFileFromString(filename, string) { + var src = require('stream').Readable({ objectMode: true }); + src._read = function() { + this.push(new gutil.File({ cwd: paths.appRoot, base: paths.output, path: filename, contents: new Buffer(string) })) + this.push(null) + } + return src; +} + +function srcForBabel() { + return merge( + gulp.src(paths.output + jsName), + gulpFileFromString(paths.output + 'index.js', "export * from './" + paths.packageName + "';") + ); +} + +function srcForTypeScript() { + return gulp + .src(paths.output + paths.packageName + '.js') + .pipe(rename(function (path) { + if (path.extname == '.js') { + path.extname = '.ts'; + } + })); +} + +compileToModules.forEach(function(moduleType){ + gulp.task('build-babel-' + moduleType, function () { + return srcForBabel() + .pipe(to5(assign({}, compilerOptions[moduleType]()))) + .pipe(cleanGeneratedCode()) + .pipe(gulp.dest(paths.output + moduleType)); + }); + + if (moduleType === 'native-modules') return; // typescript doesn't support the combination of: es5 + native modules + + gulp.task('build-ts-' + moduleType, function () { + var tsProject = ts.createProject( + compilerTsOptions({ module: moduleType, target: moduleType == 'es2015' ? 'es2015' : 'es5' }), ts.reporter.defaultReporter()); + var tsResult = srcForTypeScript().pipe(ts(tsProject)); + return tsResult.js + .pipe(gulp.dest(paths.output + moduleType)); + }); +}); + +gulp.task('build-dts', function() { + var tsProject = ts.createProject( + compilerTsOptions({ removeComments: false, target: "es2015", module: "es2015" }), ts.reporter.defaultReporter()); + var tsResult = srcForTypeScript().pipe(ts(tsProject)); + return tsResult.dts + .pipe(gulp.dest(paths.output)); +}); + +gulp.task('build', function(callback) { + return runSequence( + 'clean', + 'build-index', + compileToModules + .map(function(moduleType) { return 'build-babel-' + moduleType }) + .concat(paths.useTypeScriptForDTS ? ['build-dts'] : []), + callback + ); +}); + +gulp.task('build-ts', function(callback) { + return runSequence( + 'clean', + 'build-index', + 'build-babel-native-modules', + compileToModules + .filter(function(moduleType) { return moduleType !== 'native-modules' }) + .map(function(moduleType) { return 'build-ts-' + moduleType }) + .concat(paths.useTypeScriptForDTS ? ['build-dts'] : []), + callback + ); +}); diff --git a/build/tasks/clean.js b/build/tasks/clean.js new file mode 100644 index 0000000..800cb0b --- /dev/null +++ b/build/tasks/clean.js @@ -0,0 +1,9 @@ +var gulp = require('gulp'); +var paths = require('../paths'); +var del = require('del'); +var vinylPaths = require('vinyl-paths'); + +gulp.task('clean', function() { + return gulp.src([paths.output]) + .pipe(vinylPaths(del)); +}); diff --git a/build/tasks/dev.js b/build/tasks/dev.js new file mode 100644 index 0000000..2d8c619 --- /dev/null +++ b/build/tasks/dev.js @@ -0,0 +1,10 @@ +var gulp = require('gulp'); +var tools = require('aurelia-tools'); + +gulp.task('update-own-deps', function(){ + tools.updateOwnDependenciesFromLocalRepositories(); +}); + +gulp.task('build-dev-env', function () { + tools.buildDevEnv(); +}); diff --git a/build/tasks/doc.js b/build/tasks/doc.js new file mode 100644 index 0000000..1bb4f36 --- /dev/null +++ b/build/tasks/doc.js @@ -0,0 +1,46 @@ +var gulp = require('gulp'); +var paths = require('../paths'); +var typedoc = require('gulp-typedoc'); +var runSequence = require('run-sequence'); +var through2 = require('through2'); + +gulp.task('doc-generate', function(){ + return gulp.src([paths.output + paths.packageName + '.d.ts']) + .pipe(typedoc({ + target: 'es6', + includeDeclarations: true, + moduleResolution: 'node', + json: paths.doc + '/api.json', + name: paths.packageName + '-docs',  + mode: 'modules', + excludeExternals: true, + ignoreCompilerErrors: false, + version: true + })); +}); + +gulp.task('doc-shape', function(){ + return gulp.src([paths.doc + '/api.json']) + .pipe(through2.obj(function(file, enc, callback) { + var json = JSON.parse(file.contents.toString('utf8')).children[0]; + + json = { + name: paths.packageName, + children: json.children, + groups: json.groups + }; + + file.contents = new Buffer(JSON.stringify(json)); + this.push(file); + return callback(); + })) + .pipe(gulp.dest(paths.doc)); +}); + +gulp.task('doc', function(callback){ + return runSequence( + 'doc-generate', + 'doc-shape', + callback + ); +}); diff --git a/build/tasks/lint.js b/build/tasks/lint.js new file mode 100644 index 0000000..b690fa4 --- /dev/null +++ b/build/tasks/lint.js @@ -0,0 +1,10 @@ +var gulp = require('gulp'); +var paths = require('../paths'); +var eslint = require('gulp-eslint'); + +gulp.task('lint', function() { + return gulp.src(paths.source) + .pipe(eslint()) + .pipe(eslint.format()) + .pipe(eslint.failOnError()); +}); diff --git a/build/tasks/prepare-release.js b/build/tasks/prepare-release.js new file mode 100644 index 0000000..b374e6b --- /dev/null +++ b/build/tasks/prepare-release.js @@ -0,0 +1,33 @@ +var gulp = require('gulp'); +var runSequence = require('run-sequence'); +var paths = require('../paths'); +var fs = require('fs'); +var bump = require('gulp-bump'); +var args = require('../args'); +var conventionalChangelog = require('gulp-conventional-changelog'); + +gulp.task('changelog', function () { + return gulp.src(paths.doc + '/CHANGELOG.md', { + buffer: false + }).pipe(conventionalChangelog({ + preset: 'angular' + })) + .pipe(gulp.dest(paths.doc)); +}); + +gulp.task('bump-version', function(){ + return gulp.src(['./package.json', './bower.json']) + .pipe(bump({type:args.bump })) //major|minor|patch|prerelease + .pipe(gulp.dest('./')); +}); + +gulp.task('prepare-release', function(callback){ + return runSequence( + 'build', + 'lint', + 'bump-version', + 'doc', + 'changelog', + callback + ); +}); diff --git a/build/tasks/test.js b/build/tasks/test.js new file mode 100644 index 0000000..4dd6153 --- /dev/null +++ b/build/tasks/test.js @@ -0,0 +1,23 @@ +var gulp = require('gulp'); + +/** + * Run test once and exit + */ +gulp.task('test', function (done) { + // TODO +}); + +/** + * Watch for file changes and re-run tests on each change + */ +gulp.task('tdd', function (done) { + // TODO +}); + +/** + * Run test once with code coverage and exit + */ +gulp.task('cover', function (done) { + // TODO +}); + diff --git a/build/typescript-options.js b/build/typescript-options.js new file mode 100644 index 0000000..8a22abe --- /dev/null +++ b/build/typescript-options.js @@ -0,0 +1,9 @@ +var tsconfig = require('../tsconfig.json'); +var assign = Object.assign || require('object.assign'); + +module.exports = function(override) { + return assign(tsconfig.compilerOptions, { + "target": override && override.target || "es5", + "typescript": require('typescript') + }, override || {}); +} diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..80492b4 --- /dev/null +++ b/circle.yml @@ -0,0 +1,23 @@ +##### +# Circle CI +# +# For running docker images on circle ci, see: https://circleci.com/docs/docker +# For circle.yml explanation, see: https://circleci.com/docs/manually +##### + +machine: + node: + version: 4.2.6 + +dependencies: + pre: + - npm install -g gulp + - npm install -g jspm + override: + - npm install + - jspm install + +test: + override: + - gulp build + - gulp test diff --git a/doc/CHANGELOG.md b/doc/CHANGELOG.md new file mode 100644 index 0000000..e69de29 diff --git a/doc/api.json b/doc/api.json new file mode 100644 index 0000000..8d63055 --- /dev/null +++ b/doc/api.json @@ -0,0 +1 @@ +{"name":"aurelia-pal-nodejs","children":[{"id":2,"name":"initialize","kind":64,"kindString":"Function","flags":{"isExported":true},"signatures":[{"id":3,"name":"initialize","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Initializes the PAL with nodejs."},"type":{"type":"instrinct","name":"void"}}]}],"groups":[{"title":"Functions","kind":64,"children":[2]}]} \ No newline at end of file diff --git a/gulpfile.js b/gulpfile.js index ea6f281..978fd98 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,95 +1 @@ -'use strict'; - -var gulp = require('gulp'); -var ts = require('gulp-typescript'); -var shell = require('gulp-shell'); -var merge = require('merge2'); -var jasmine = require('gulp-jasmine'); -var plumber = require('gulp-plumber'); -var sourcemap = require('gulp-sourcemaps'); -var rimraf = require('gulp-rimraf'); -var replace = require('gulp-replace'); -var runsequence = require('run-sequence'); - - - -var paths = { - source: "source/", - output: "dist/", - spec: "spec/" -} - -gulp.task('clean:typescript', function () { - return gulp.src([paths.output + '**/*'], { read: false }) - .pipe(rimraf()); -}); - -gulp.task('clean:tests', function () { - return gulp.src([paths.spec + '**/*.spec.js', paths.spec + '**/*.map'], { read: false }) - .pipe(rimraf()); -}); - -gulp.task('clean', ['clean:tests', 'clean:typescript'], function () { -}); - -gulp.task('compile:typescript', ['clean:typescript'], function () { - var project = ts.createProject('tsconfig.json'); - - var tsResult = gulp - .src([ - '!' + paths.source + '**/*spec.ts', - paths.source + '**/*.ts', - 'typings/index.d.ts' - ]) - .pipe(sourcemap.init()) - .pipe(ts(project)); - - return merge([ - tsResult.dts.pipe(gulp.dest(paths.output)), - tsResult.js - .pipe(sourcemap.write('.', { sourceRoot: '../source' })) - .pipe(gulp.dest(paths.output)) - ]); -}); - -gulp.task('compile:tests', ['compile:typescript', 'clean:tests'], function () { - var project = ts.createProject('tsconfig.json'); - - var tsResult = gulp.src([ - paths.spec + '**/*spec.ts', 'typings/index.d.ts' - ]) - .pipe(sourcemap.init()) - .pipe(ts(project)); - - return tsResult.js - .pipe(sourcemap.write('.', { sourceRoot: '../spec' })) - .pipe(replace(/(require\('\..\/source\/)/g, 'require(\'..\/dist\/')) - .pipe(gulp.dest(paths.spec)); -}); - -gulp.task('test:jasmine', function (done) { - return gulp.src('spec/*.js') - .pipe(plumber()) - .pipe(jasmine({ verbose: true })); -}); - -gulp.task('test', function (done) { - runsequence('compile:tests', 'test:jasmine', function (err) { - runsequence('clean:tests'); - done(); - }); -}); - -gulp.task('test-no-compile', function (done) { - runsequence('test:jasmine', function (err) { - runsequence('clean:tests'); - done(); - }); -}); - -gulp.task('watch', ['test'], function () { - gulp.watch(paths.source + '**/*.ts', ['test']); -}); - -gulp.task('default', ['test'], function () { -}); +require('require-dir')('build/tasks'); diff --git a/package.json b/package.json index a9de3dd..ae69188 100644 --- a/package.json +++ b/package.json @@ -1,34 +1,73 @@ { "name": "aurelia-pal-nodejs", - "description": "node-js implementation of the aurelia pal-abstraction layer", - "author": "Meirion Hughes ", + "version": "0.1.0", + "description": "The Node.js-specific implementation of Aurelia's platform abstraction layer.", + "keywords": [ + "aurelia", + "pal", + "nodejs" + ], + "homepage": "http://aurelia.io", + "bugs": { + "url": "https://github.com/aurelia/pal-nodejs/issues" + }, "license": "MIT", - "main": "./dist/index.js", - "typings": "./dist/index.d.ts", - "version": "1.0.0-alpha.1", + "author": "Rob Eisenberg (http://robeisenberg.com/)", + "main": "dist/commonjs/aurelia-pal-nodejs.js", + "typings": "dist/aurelia-pal-nodejs.d.ts", "repository": { "type": "git", - "url": "https://github.com/aurelia/pal-nodejs" + "url": "http://github.com/aurelia/pal-nodejs" + }, + "dependencies": { + "aurelia-pal": "^1.0.0", + "jsdom": "^9.2.1" }, "devDependencies": { + "aurelia-tools": "^0.2.4", + "babel-dts-generator": "^0.6.1", + "babel-eslint": "^6.1.2", + "babel-plugin-syntax-flow": "^6.8.0", + "babel-plugin-transform-decorators-legacy": "^1.3.4", + "babel-plugin-transform-es2015-modules-amd": "^6.8.0", + "babel-plugin-transform-es2015-modules-commonjs": "^6.11.5", + "babel-plugin-transform-es2015-modules-systemjs": "^6.11.6", + "babel-plugin-transform-flow-strip-types": "^6.8.0", + "babel-preset-es2015": "^6.9.0", + "babel-preset-es2015-loose": "^7.0.0", + "babel-preset-es2015-loose-native-modules": "^1.0.0", + "babel-preset-stage-1": "^6.5.0", + "del": "^2.2.1", "gulp": "^3.9.1", - "gulp-jasmine": "^2.3.0", + "gulp-babel": "^6.1.2", + "gulp-bump": "^2.2.0", + "gulp-concat": "^2.6.0", + "gulp-conventional-changelog": "^1.1.0", + "gulp-eslint": "^3.0.1", + "gulp-ignore": "^2.0.1", + "gulp-insert": "^0.5.0", + "gulp-jasmine": "^2.4.0", "gulp-plumber": "^1.1.0", - "gulp-replace": "^0.5.4", - "gulp-rimraf": "^0.2.0", - "gulp-shell": "^0.5.2", - "gulp-sourcemaps": "^1.6.0", - "gulp-typescript": "^2.13.4", - "jasmine": "^2.4.1", + "gulp-rename": "^1.2.2", + "gulp-typedoc": "^2.0.0", + "gulp-typedoc-extractor": "^0.0.8", + "gulp-typescript": "^2.13.6", + "gulp-util": "^3.0.7", + "jasmine-core": "^2.4.1", "merge2": "^1.0.2", - "run-sequence": "^1.2.1", - "typings": "^1.0.4" + "object.assign": "^4.0.4", + "require-dir": "^0.3.0", + "run-sequence": "^1.2.2", + "through2": "^2.0.1", + "typedoc": "^0.4.4", + "typescript": "^1.9.0-dev.20160622-1.0", + "vinyl": "^1.1.1", + "vinyl-paths": "^2.1.0", + "yargs": "^4.8.1" }, - "scripts": { - "test": "gulp test" - }, - "dependencies": { - "aurelia-pal": "^1.0.0", - "jsdom": "^9.2.1" + "aurelia": { + "documentation": { + "articles": [] + } } } diff --git a/spec/support/jasmine.json b/spec/support/jasmine.json deleted file mode 100644 index 3ea3166..0000000 --- a/spec/support/jasmine.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "spec_dir": "spec", - "spec_files": [ - "**/*[sS]pec.js" - ], - "helpers": [ - "helpers/**/*.js" - ], - "stopSpecOnExpectationFailure": false, - "random": false -} diff --git a/source/disposeable.ts b/src/disposeable.js similarity index 100% rename from source/disposeable.ts rename to src/disposeable.js diff --git a/source/dom.ts b/src/dom.js similarity index 100% rename from source/dom.ts rename to src/dom.js diff --git a/source/feature.ts b/src/feature.js similarity index 100% rename from source/feature.ts rename to src/feature.js diff --git a/source/global.ts b/src/global.js similarity index 100% rename from source/global.ts rename to src/global.js diff --git a/source/index.ts b/src/index.js similarity index 99% rename from source/index.ts rename to src/index.js index ad0f511..6e24f15 100644 --- a/source/index.ts +++ b/src/index.js @@ -85,7 +85,7 @@ function ensurePerformance(window) { if (window.performance === undefined) { window.performance = {}; } - + if (window.performance.now === undefined) { let nowOffset = Date.now(); diff --git a/source/nodejs-dom.ts b/src/nodejs-dom.js similarity index 91% rename from source/nodejs-dom.ts rename to src/nodejs-dom.js index 2da8774..2eeba9b 100644 --- a/source/nodejs-dom.ts +++ b/src/nodejs-dom.js @@ -8,12 +8,12 @@ import {NodeJsMutationObserver} from './nodejs-mutation-observer'; */ export class NodeJsDom implements IDom { - public mutationEmulator: NodeJsMutationEmulator; + mutationEmulator: NodeJsMutationEmulator; - constructor(public global: IGlobal) { + constructor(global: IGlobal) { - this.Element = (global).Element; - this.SVGElement = (global).SVGElement; + this.Element = global.Element; + this.SVGElement = global.SVGElement; this.mutationEmulator = new NodeJsMutationEmulator(); } @@ -42,7 +42,7 @@ export class NodeJsDom implements IDom { return this.global.document.createDocumentFragment(); } createMutationObserver(callback: (changes: MutationRecord[], instance: MutationObserver) => void): MutationObserver { - return (this.global.window).MutationObserver || (this.mutationEmulator != null) ? new NodeJsMutationObserver(this.mutationEmulator, callback) : null; + return (this.global.window).MutationObserver || (this.mutationEmulator != null) ? new NodeJsMutationObserver(this.mutationEmulator, callback) : null; } createCustomEvent(eventType: string, options: Object): CustomEvent { return new this.global.CustomEvent(eventType, options); diff --git a/source/nodejs-feature.ts b/src/nodejs-feature.js similarity index 74% rename from source/nodejs-feature.ts rename to src/nodejs-feature.js index 973623d..04e52cd 100644 --- a/source/nodejs-feature.ts +++ b/src/nodejs-feature.js @@ -2,8 +2,8 @@ import {IFeature} from './feature'; import {IGlobal} from './global'; export class NodeJsFeature implements IFeature{ - constructor(private global: IGlobal){ - this.shadowDOM = (this.global.window).HTMLElement.prototype.attachShadow != undefined; + constructor(global: IGlobal){ + this.shadowDOM = (this.global.window).HTMLElement.prototype.attachShadow != undefined; this.scopedCSS = 'scoped' in this.global.document.createElement('style'); this.htmlTemplateElement = true; this.mutationObserver = true; // partial diff --git a/source/nodejs-mutation-emulator.ts b/src/nodejs-mutation-emulator.js similarity index 77% rename from source/nodejs-mutation-emulator.ts rename to src/nodejs-mutation-emulator.js index e2fbc9b..d039dab 100644 --- a/source/nodejs-mutation-emulator.ts +++ b/src/nodejs-mutation-emulator.js @@ -3,11 +3,11 @@ import {IObserver} from './observer'; import {IDisposable} from './disposeable'; export class NodeJsMutationEmulator { - private cycleMutations: MutationRecord[]; - private cycleTimerId: NodeJS.Timer; - private targets: { target: Node, last: Node }[]; - private observers: IObserver[]; - public interval:number; + cycleMutations: MutationRecord[]; + cycleTimerId: NodeJS.Timer; + targets: { target: Node, last: Node }[]; + observers: IObserver[]; + interval:number; constructor(interval?: number) { this.interval = (interval === undefined) ? 100 : interval; @@ -21,8 +21,8 @@ export class NodeJsMutationEmulator { if (this.interval > 0) this.cycleTimerId = setInterval(() => this.cycle(), this.interval); } - - stop(){ + + stop(){ clearInterval(this.cycleTimerId); } @@ -51,17 +51,17 @@ export class NodeJsMutationEmulator { } } - public cycle() { - this.cycleDirtyCheck(); - this.cycleReport(); - this.cycleTidy(); + cycle() { + this._cycleDirtyCheck(); + this._cycleReport(); + this._cycleTidy(); } - private cycleTidy() { - //remove targets no longer having any observer; + _cycleTidy() { + //remove targets no longer having any observer; } - private cycleReport() { + _cycleReport() { let mutations = this.cycleMutations; this.cycleMutations = []; @@ -80,7 +80,7 @@ export class NodeJsMutationEmulator { }); } - private cycleDirtyCheck() { + _cycleDirtyCheck() { let targets = this.targets; let targetsCount = targets.length; @@ -89,15 +89,15 @@ export class NodeJsMutationEmulator { let targetNode = target.target; let previous = target.last; - this.cycleDirtyCheckAttributes(targetNode, previous); - this.cycleDirtyCheckNodeValue(targetNode, previous); - this.cycleDirtyCheckChildList(targetNode, previous); + this._cycleDirtyCheckAttributes(targetNode, previous); + this._cycleDirtyCheckNodeValue(targetNode, previous); + this._cycleDirtyCheckChildList(targetNode, previous); target.last = targetNode.cloneNode(true); } } - - private cycleDirtyCheckAttributes(target: Node, previous:Node ) { + + _cycleDirtyCheckAttributes(target: Node, previous: Node) { if(!target.attributes) return; @@ -107,12 +107,12 @@ export class NodeJsMutationEmulator { for (let i = 0; i < countNew; i++) { let attr = attrNew.item(i); - let old = this.findAttr(attrOld, attr.name); + let old = this._findAttr(attrOld, attr.name); let mutated = false; if (!old || old.value != attr.value) { - let mutation = { + let mutation = { target: target, type: "attributes", addedNodes: {}, @@ -134,7 +134,7 @@ export class NodeJsMutationEmulator { let old = attrOld.item(i); if (!this.findAttr(attrNew, old.name)) { - let mutation = { + let mutation = { target: target, type: "attributes", addedNodes: {}, @@ -151,9 +151,9 @@ export class NodeJsMutationEmulator { } } - private cycleDirtyCheckNodeValue(target: Node, previous:Node ) { + _cycleDirtyCheckNodeValue(target: Node, previous:Node ) { if (target.nodeValue != previous.nodeValue) { - let mutation = { + let mutation = { target: target, type: "characterData", addedNodes: {}, @@ -168,13 +168,13 @@ export class NodeJsMutationEmulator { this.registerMutation(mutation); } } - - private cycleDirtyCheckChildList(target: Node, previous:Node ) { + + _cycleDirtyCheckChildList(target: Node, previous:Node ) { if(!target.nodeValue) return; - } + } - private findAttr(attrs: NamedNodeMap, name: string): Attr { + _findAttr(attrs: NamedNodeMap, name: string): Attr { var count = attrs.length; for (let i = 0; i < count; i++) { diff --git a/source/nodejs-mutation-observer.ts b/src/nodejs-mutation-observer.js similarity index 71% rename from source/nodejs-mutation-observer.ts rename to src/nodejs-mutation-observer.js index 7bfd64f..e7d420c 100644 --- a/source/nodejs-mutation-observer.ts +++ b/src/nodejs-mutation-observer.js @@ -4,24 +4,24 @@ import {NodeJsMutationEmulator} from './nodejs-mutation-emulator'; export class NodeJsMutationObserver implements MutationObserver { - private disposable:()=>void; + disposable:()=>void; constructor( - private source:NodeJsMutationEmulator, - private callback:(changes:MutationRecord[], instance:MutationObserver)=>void ) - { + source:NodeJsMutationEmulator, + callback:(changes:MutationRecord[], instance:MutationObserver)=>void ) + { } disconnect(): void { if(this.disposable) this.disposable(); - this.disposable = null; + this.disposable = null; } observe(target: Node, options: MutationObserverInit): void { this.disposable = this.source.registerObserver({ - target:target, + target:target, options:options, callback:(changes:MutationRecord[])=>this.callback(changes, this)}); } diff --git a/source/nodejs-platform.ts b/src/nodejs-platform.js similarity index 91% rename from source/nodejs-platform.ts rename to src/nodejs-platform.js index 583bc35..cb79279 100644 --- a/source/nodejs-platform.ts +++ b/src/nodejs-platform.js @@ -4,7 +4,7 @@ import {IGlobal} from './global'; export class NodeJsPlatform implements IPlatform { - constructor(public global: IGlobal) { + constructor(global: IGlobal) { this.performance = this.global.performance; this.location = this.global.location; this.history = this.global.history; @@ -41,7 +41,7 @@ export class NodeJsPlatform implements IPlatform { * @param callback A callback that will receive each module id along with the module object. Return true to end enumeration. */ eachModule(callback: (key: string, value: Object) => boolean): void { - //TODO: What is this? + //TODO: What is this? } /** * Add a global event listener. @@ -50,7 +50,7 @@ export class NodeJsPlatform implements IPlatform { * @param capture If true, useCapture indicates that the user wishes to initiate capture. */ addEventListener(eventName: string, callback: Function, capture?: boolean): void { - this.global.addEventListener(eventName, callback, capture); + this.global.addEventListener(eventName, callback, capture); } /** * Remove a global event listener. @@ -59,7 +59,7 @@ export class NodeJsPlatform implements IPlatform { * @param capture Specifies whether the listener to be removed was registered as a capturing listener or not. */ removeEventListener(eventName: string, callback: Function, capture?: boolean): void { - this.global.removeEventListener(eventName, callback, capture); + this.global.removeEventListener(eventName, callback, capture); } /** diff --git a/source/observer.ts b/src/observer.js similarity index 100% rename from source/observer.ts rename to src/observer.js diff --git a/source/performance.ts b/src/performance.js similarity index 100% rename from source/performance.ts rename to src/performance.js diff --git a/source/platform.ts b/src/platform.js similarity index 100% rename from source/platform.ts rename to src/platform.js diff --git a/spec/nodejs-dom.spec.ts b/test/nodejs-dom.spec.js similarity index 98% rename from spec/nodejs-dom.spec.ts rename to test/nodejs-dom.spec.js index fd57d2f..b996cf8 100644 --- a/spec/nodejs-dom.spec.ts +++ b/test/nodejs-dom.spec.js @@ -1,4 +1,4 @@ -import {initialize} from '../source/index' +import {initialize} from '../src/index' import {DOM} from 'aurelia-pal'; import {jsdom} from 'jsdom'; diff --git a/spec/nodejs-mutation-source.spec.ts b/test/nodejs-mutation-source.spec.js similarity index 66% rename from spec/nodejs-mutation-source.spec.ts rename to test/nodejs-mutation-source.spec.js index 9640062..8ce9ebb 100644 --- a/spec/nodejs-mutation-source.spec.ts +++ b/test/nodejs-mutation-source.spec.js @@ -1,5 +1,5 @@ -import {NodeJsMutationEmulator} from '../source/nodejs-mutation-emulator'; -import {IObserver} from '../source/observer'; +import {NodeJsMutationEmulator} from '../src/nodejs-mutation-emulator'; +import {IObserver} from '../src/observer'; import {jsdom} from 'jsdom'; describe("Mutation Source", function () { @@ -8,18 +8,18 @@ describe("Mutation Source", function () { var source = new NodeJsMutationEmulator(0); var dom = jsdom(undefined); - let observer = { + let observer = { } var target = dom.createElement("div"); target.setAttribute("foo", "moo"); - var callback = (records: MutationRecord[]) => { + var callback = (records) => { wasCalled = true; } - source.registerObserver({ + source.registerObserver({ target: target, callback: callback }); @@ -32,7 +32,7 @@ describe("Mutation Source", function () { it("does raise mutation after attribute is changed", function () { var source = new NodeJsMutationEmulator(0); var dom = jsdom(undefined); - let observer = {} + let observer = {} var target = dom.createElement("div"); @@ -40,11 +40,11 @@ describe("Mutation Source", function () { var wasCalled; - var callback = (records: MutationRecord[]) => { + var callback = (records) => { wasCalled = true; } - source.registerObserver({ + source.registerObserver({ target: target, callback: callback }); @@ -52,20 +52,20 @@ describe("Mutation Source", function () { wasCalled = false; source.cycle(); expect(wasCalled).toBe(false); - - wasCalled = false; + + wasCalled = false; target.setAttribute("foo", "boo"); source.cycle(); - expect(wasCalled).toBe(true); + expect(wasCalled).toBe(true); - wasCalled = false; + wasCalled = false; source.cycle(); - expect(wasCalled).toBe(false); + expect(wasCalled).toBe(false); - wasCalled = false; + wasCalled = false; target.setAttribute("foo", "choo"); source.cycle(); - expect(wasCalled).toBe(true); + expect(wasCalled).toBe(true); }); }); @@ -74,15 +74,15 @@ describe("Mutation Source", function () { it("doesn't raise mutation if nodeValue not changed", function () { var source = new NodeJsMutationEmulator(0); var dom = jsdom(undefined); - let observer = {} + let observer = {} var target = dom.createTextNode("foo"); - var callback = (records: MutationRecord[]) => { + var callback = (records) => { wasCalled = true; } - source.registerObserver({ + source.registerObserver({ target: target, callback: callback }); @@ -95,16 +95,16 @@ describe("Mutation Source", function () { it("does raise mutation after nodeValue is changed", function () { var source = new NodeJsMutationEmulator(0); var dom = jsdom(undefined); - let observer = {} + let observer = {} var target = dom.createTextNode("foo"); var wasCalled; - var callback = (records: MutationRecord[]) => { + var callback = (records) => { wasCalled = true; } - source.registerObserver({ + source.registerObserver({ target: target, callback: callback }); @@ -112,20 +112,20 @@ describe("Mutation Source", function () { wasCalled = false; source.cycle(); expect(wasCalled).toBe(false); - - wasCalled = false; + + wasCalled = false; target.nodeValue = "boo"; source.cycle(); - expect(wasCalled).toBe(true); + expect(wasCalled).toBe(true); - wasCalled = false; + wasCalled = false; source.cycle(); - expect(wasCalled).toBe(false); + expect(wasCalled).toBe(false); - wasCalled = false; + wasCalled = false; target.nodeValue = "choo"; source.cycle(); - expect(wasCalled).toBe(true); + expect(wasCalled).toBe(true); }); }); diff --git a/spec/nodejs-platform.spec.ts b/test/nodejs-platform.spec.js similarity index 96% rename from spec/nodejs-platform.spec.ts rename to test/nodejs-platform.spec.js index 911c554..22e35a3 100644 --- a/spec/nodejs-platform.spec.ts +++ b/test/nodejs-platform.spec.js @@ -1,4 +1,4 @@ -import {initialize} from '../source/index' +import {initialize} from '../src/index' import {PLATFORM} from 'aurelia-pal'; initialize(); diff --git a/tsconfig.json b/tsconfig.json index be71ed5..4adcc86 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,17 +1,25 @@ { - "version": "1.8.10", - "compilerOptions": { - "target": "es6", - "module": "commonjs", - "sourceMap": true, - "noEmitOnError": true, - "newLine": "LF", - "declaration": true, - "removeComments": false, - "experimentalDecorators": true, - "allowSyntheticDefaultImports": true - }, - "exclude": [ - "node_modules" - ] + "compilerOptions": { + "target": "es2015", + "module": "es2015", + "experimentalDecorators": true, + "emitDecoratorMetadata": false, + "moduleResolution": "node", + "stripInternal": true, + "preserveConstEnums": true, + "listFiles": true, + "declaration": true, + "removeComments": true, + "lib": ["es2015", "dom"] + }, + "exclude": [ + "node_modules", + "dist", + "build", + "doc", + "test", + "config.js", + "gulpfile.js", + "karma.conf.js" + ] } diff --git a/typings.json b/typings.json index ae04bea..056abde 100644 --- a/typings.json +++ b/typings.json @@ -1,8 +1,7 @@ { "name": "aurelia-pal-nodejs", - "dependencies": {}, - "globalDependencies": { - "jasmine": "registry:dt/jasmine#2.2.0+20160505161446", - "node": "registry:env/node#6.0.0+20160610031852" + "main": "dist/aurelia-pal-nodejs.d.ts", + "dependencies": { + "aurelia-pal": "github:aurelia/pal" } } diff --git a/typings/custom/jsdom.d.ts b/typings/custom/jsdom.d.ts deleted file mode 100644 index 7246e55..0000000 --- a/typings/custom/jsdom.d.ts +++ /dev/null @@ -1,192 +0,0 @@ -// Generated by typings -// Source: https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/56295f5058cac7ae458540423c50ac2dcf9fc711/jsdom/jsdom.d.ts -declare module "jsdom" { - - import {EventEmitter} from 'events'; - - /** - * The do-what-I-mean API. - * - * Example: - * jsdom.env(html, function (errors, window) { - * // free memory associated with the window - * window.close(); - * }); - * - * @param urlOrSource may be a URL, file name, or HTML fragment - * @param scriptUrlsOrSources a string or array of strings, containing file names or URLs that will be inserted as - * @param config Configuration object - * @param callback - */ - export function env(urlOrHtml: string, scripts: string, config: Config, callback?: Callback): void; - export function env(urlOrHtml: string, scripts: string, callback: Callback): void; - export function env(urlOrHtml: string, scripts: string[], config: Config, callback?: Callback): void; - export function env(urlOrHtml: string, scripts: string[], callback: Callback): void; - export function env(urlOrHtml: string, callback: Callback): void; - export function env(urlOrHtml: string, config: Config, callback?: Callback): void; - export function env(config: Config, callback?: Callback): void; - - export function serializeDocument(doc: Document): string; - - export interface VirtualConsole extends EventEmitter { - sendTo(console: Console): VirtualConsole; - } - - export interface VirtualConsoleOptions { - } - - export interface WindowProperties { - parsingMode?: string; // html, xml, auto, undefined - contentType?: string; - parser?: any; - url?: string; - referrer?: string; - cookieJar?: CookieJar; - cookie?: string; - resourceLoader?: any; - deferClose?: boolean; - concurrentNodeIterators?: number; - virtualConsole?: VirtualConsole; - created?: (something: any, window: Window) => any; - features?: FeatureOptions; - top?: Window; - } - - // tough-cookie - export interface CookieJar { - - } - - export function createVirtualConsole(options?: VirtualConsoleOptions): VirtualConsole; - export function getVirtualConsole(window: Window): VirtualConsole; - export function createCookieJar(): CookieJar; - export function nodeLocation(node: Node): any; - export function reconfigureWindow(window: Window, newProps: WindowProperties): void; - - //export function jQueryify(window: Window, jqueryUrl: string, callback: (window: Window, jquery: JQuery) => any): void; - - export var debugMode: boolean; - - export interface DocumentWithParentWindow extends Document { - parentWindow: Window; - } - - /** - * The jsdom.jsdom method does less things automatically; it takes in only HTML source, and does not let you to - * separately supply script that it will inject and execute. It just gives you back a document object, - * with usable document.parentWindow, and starts asynchronously executing any