Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
feat(project): add d.ts file
Browse files Browse the repository at this point in the history
* update to babel 6
* maybe jspm17 ready
* add lint-md task
* remove unused doc task
* renamed index.js to aurelia-orm
* make d.ts defs as aurelia does
* update dependencies
  • Loading branch information
doktordirk committed Mar 25, 2016
1 parent 3eb578d commit 6a6368c
Show file tree
Hide file tree
Showing 30 changed files with 460 additions and 234 deletions.
24 changes: 24 additions & 0 deletions .remarkrc
@@ -0,0 +1,24 @@
{
"output": true,
"plugins": {
"lint": {
"maximum-line-length": false,
"heading-style": "atx",
"no-duplicate-headings": false,
"no-undefined-references": false,
"no-shortcut-reference-link": false,
"no-heading-punctuation": ".,;:!",
"list-item-indent": false
}
},
"settings": {
"gfm": true,
"bullet": "*",
"closeAtx": false,
"fences": true,
"listItemIndent": "1",
"rule": "-",
"ruleRepetition": 10,
"ruleSpaces": false
}
}
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -24,14 +24,17 @@ This library is used directly by applications only.
This library can be used in the **browser** only.

## Installation

Installing this module is fairly simple.

Run `jspm install github:spoonx/aurelia-orm` from your project root.

## Example

Here's a snippet to give you an idea of what this module does.

### entity/user.js

```javascript
import {Entity, validatedResource} from 'spoonx/aurelia-orm';
import {ensure} from 'aurelia-validation';
Expand All @@ -50,6 +53,7 @@ export class UserEntity extends Entity {
```

### page/some-view-model.js

```javascript
import {EntityManager} from 'spoonx/aurelia-orm';
import {inject} from 'aurelia-framework';
Expand Down Expand Up @@ -80,9 +84,11 @@ export class Create {
```

## Gotchas

When using this module, please keep in mind the following gotchas.

### Bundling

When bundling your aurelia app, the bundler renames your modules (to save space).
This is fine, but aurelia-orm allows you to add decorators without values, and uses the module name to set the value.
For instance, `@resource()` would use the module's name to set the resource.
Expand All @@ -91,4 +97,5 @@ So keep in mind: When using aurelia-orm in a bundled application, you must speci
For instance, `@decorator('category')`.

## Documentation

You can find usage examples and documentation in the [Getting started](doc/getting-started.md) or the `doc/` directory.
6 changes: 6 additions & 0 deletions build/.eslintrc
@@ -0,0 +1,6 @@
{
"rules": {
"no-var": 0,
"no-console": 0
}
}
69 changes: 59 additions & 10 deletions build/babel-options.js
@@ -1,11 +1,60 @@
module.exports = {
modules: 'system',
moduleIds: false,
comments: false,
compact: false,
stage:2,
optional: [
"es7.decorators",
"es7.classProperties"
]
var path = require('path');
var paths = require('./paths');

exports.base = function() {
return {
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',
'transform-flow-strip-types'
]
};
}

exports['plugin-dts'] = ['babel-dts-generator', {
packageName: paths.packageName,
typings: '',
suppressModulePath: true,
suppressComments: false,
memberOutputFilter: /^_.*/
}];

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.dts = function() {
var options = exports.base();
options.plugins.push(exports['plugin-dts']);
return options;
};
14 changes: 12 additions & 2 deletions build/paths.js
@@ -1,14 +1,24 @@
var path = require('path');
var fs = require('fs');

var appRoot = 'src/';
var pkg = JSON.parse(fs.readFileSync('./package.json', 'utf-8'));
// your main file which exports only configure and other modules.
// usually packageName or 'index.js'
var entryFileName = pkg.name + '.js';

module.exports = {
root: appRoot,
source: appRoot + '**/*.js',
tsSource: [
appRoot + '**/*.js', // list files to parse for d.ts
'!' + appRoot + entryFileName // exclude entry file
],
html: appRoot + '**/*.html',
style: 'styles/**/*.css',
output: 'dist/',
doc:'./doc',
doc: './doc',
e2eSpecsSrc: 'test/e2e/src/*.js',
e2eSpecsDist: 'test/e2e/dist/'
e2eSpecsDist: 'test/e2e/dist/',
packageName: pkg.name
};
102 changes: 75 additions & 27 deletions build/tasks/build.js
@@ -1,57 +1,105 @@
var gulp = require('gulp');
var runSequence = require('run-sequence');
var to5 = require('gulp-babel');
var paths = require('../paths');
var gulp = require('gulp');
var runSequence = require('run-sequence');
var to5 = require('gulp-babel');
var paths = require('../paths');
var compilerOptions = require('../babel-options');
var assign = Object.assign || require('object.assign');
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 del = require('del');
var vinylPaths = require('vinyl-paths');

gulp.task('build-html-es6', function() {
return gulp.src(paths.html)
.pipe(gulp.dest(paths.output + 'es6'));
});
// merged output file name. a folder of paths.packageName is temporarly created in build-dts
var jsName = paths.packageName + '.js';

gulp.task('build-es6', ['build-html-es6'], function() {
return gulp.src(paths.source)
.pipe(gulp.dest(paths.output + 'es6'));

gulp.task('build-dts', function() {
var importsToAdd = []; // stores extracted imports

return gulp.src(paths.tsSource)
//.pipe(tools.sortFiles()) // sort fails with subdirectories!
.pipe(through2.obj(function(file, enc, callback) { // extract all imports to importsToAdd
file.contents = new Buffer(tools.extractImports(file.contents.toString('utf8'), importsToAdd));
this.push(file);
return callback();
}))
.pipe(concat(jsName)) // concat all selected files to jsName (now without their imports)
.pipe(insert.transform(function(contents) { // re-add extracted imports on top
return tools.createImportBlock(importsToAdd) + contents;
}))
.pipe(to5(assign({}, compilerOptions.dts()))); // compile to d.ts from file jsName. d.ts file is in folder paths.packageName
});

gulp.task('build-html-commonjs', function() {
return gulp.src(paths.html)
.pipe(gulp.dest(paths.output + 'commonjs'));
gulp.task('build-es2015', ['build-html-es2015'], function() {
return gulp.src(paths.source)
.pipe(to5(assign({}, compilerOptions.es2015())))
.pipe(gulp.dest(paths.output + 'es2015'));
});

gulp.task('build-commonjs', ['build-html-commonjs'], function() {
return gulp.src(paths.source)
.pipe(to5(assign({}, compilerOptions, {modules: 'common'})))
.pipe(to5(assign({}, compilerOptions.commonjs())))
.pipe(gulp.dest(paths.output + 'commonjs'));
});

gulp.task('build-html-amd', function() {
return gulp.src(paths.html)
gulp.task('build-amd', ['build-html-amd'], function() {
return gulp.src(paths.source)
.pipe(to5(assign({}, compilerOptions.amd())))
.pipe(gulp.dest(paths.output + 'amd'));
});

gulp.task('build-amd', ['build-html-amd'], function() {
gulp.task('build-system', ['build-html-system'], function() {
return gulp.src(paths.source)
.pipe(to5(assign({}, compilerOptions, {modules: 'amd'})))
.pipe(gulp.dest(paths.output + 'amd'));
.pipe(to5(assign({}, compilerOptions.system())))
.pipe(gulp.dest(paths.output + 'system'));
});

gulp.task('build-html-system', function() {
gulp.task('copy-dts', function() {
var tdsPath = paths.packageName + '/' + paths.packageName + '.d.ts';
return gulp.src(tdsPath)
.pipe(rename(paths.packageName + '.d.ts'))
.pipe(gulp.dest(paths.output + 'es2015'))
.pipe(gulp.dest(paths.output + 'commonjs'))
.pipe(gulp.dest(paths.output + 'amd'))
.pipe(gulp.dest(paths.output + 'system'));
});

gulp.task('remove-dts-folder', function() {
var tdsFolder = paths.packageName;
return gulp.src([tdsFolder])
.pipe(vinylPaths(del));
});

gulp.task('build-html-es2015', function() {
return gulp.src(paths.html)
.pipe(gulp.dest(paths.output + 'system'));
.pipe(gulp.dest(paths.output + 'es2015'));
});

gulp.task('build-system', ['build-html-system'], function() {
return gulp.src(paths.source)
.pipe(to5(assign({}, compilerOptions, {modules: 'system'})))
gulp.task('build-html-commonjs', function() {
return gulp.src(paths.html)
.pipe(gulp.dest(paths.output + 'commonjs'));
});

gulp.task('build-html-amd', function() {
return gulp.src(paths.html)
.pipe(gulp.dest(paths.output + 'amd'));
});

gulp.task('build-html-system', function() {
return gulp.src(paths.html)
.pipe(gulp.dest(paths.output + 'system'));
});

gulp.task('build', function(callback) {
return runSequence(
'clean',
['build-es6', 'build-commonjs', 'build-amd', 'build-system'],
['build-es2015', 'build-commonjs', 'build-amd', 'build-system'],
'build-dts',
'copy-dts',
'remove-dts-folder',
callback
);
});
14 changes: 0 additions & 14 deletions build/tasks/doc.js

This file was deleted.

20 changes: 18 additions & 2 deletions build/tasks/lint.js
@@ -1,10 +1,26 @@
var gulp = require('gulp');
var paths = require('../paths');
var gulp = require('gulp');
var paths = require('../paths');
var eslint = require('gulp-eslint');
var mdlint = require('gulp-remark');
var squeezeParagraphs = require('remark-squeeze-paragraphs');
var remarkNormalizeHeadings = require('remark-normalize-headings');
var remarkValidateLinks = require('remark-validate-links');
var remarkToc = require('remark-toc');


gulp.task('lint', function() {
return gulp.src(paths.source)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError());
});

gulp.task('lint-md', function() {
gulp.src(['*.md', paths.doc + '/*.md', '!' + paths.doc + '/CHANGELOG.md'], {base: './'})
.pipe(mdlint()
.use(squeezeParagraphs)
.use(remarkNormalizeHeadings)
.use(remarkValidateLinks)
.use(remarkToc, {tight: true, maxDepth: 2})
).pipe(gulp.dest('./'));
});
1 change: 0 additions & 1 deletion build/tasks/prepare-release.js
Expand Up @@ -29,7 +29,6 @@ gulp.task('prepare-release', function(callback) {
'build',
'lint',
'bump-version',
'doc',
'changelog',
callback
);
Expand Down

0 comments on commit 6a6368c

Please sign in to comment.