Skip to content

Commit

Permalink
chore(UX): switch to rollup, return promise<UX> in configure (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
bigopon authored and serifine committed Apr 3, 2018
1 parent 441f9f0 commit 89f5f7f
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 62 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ lerna-debug.log
*.swp
npm-debug.log*
.test
.rollupcache
dist/doc-temp
dist/test
coverage
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Check out the [showcase application](https://github.com/aurelia/app-ux-showcase)

`npm install` installs dependencies for the base Aurelia UX project

`lerna bootstrap`: sets up a symlink between all of the packages in the monorepo
`lerna bootstrap --hoist`: sets up a symlink between all of the packages in the monorepo
`lerna run build`: builds all of the mono repo projects.

>Note: `lerna run build` is very CPU intensive and takes a small period of time on most machines. If you are working within a single component, you might try `npm run build` instead at the component level.
Expand Down
4 changes: 3 additions & 1 deletion packages/core/.npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
src
test
rollup.config.js
karma.conf.js
tsconfig.json
package-lock.json
test
.npmignore
32 changes: 7 additions & 25 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
"license": "MIT",
"author": "Rob Eisenberg <[email protected]> (http://robeisenberg.com/)",
"contributors": [
"Zach Hollingshead <[email protected]>"
"Zach Hollingshead <[email protected]>",
"bigopon <[email protected]>"
],
"main": "dist/commonjs/index.js",
"typings": "dist/commonjs/index.d.ts",
"typings": "dist/types/index.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/aurelia/ux"
Expand All @@ -28,22 +29,9 @@
"test": "cross-env TS_NODE_PROJECT=\"../../tsconfig-tsnode.json\" karma start --single-run",
"develop": "cross-env TS_NODE_PROJECT=\"../../tsconfig-tsnode.json\" karma start",
"prebuild:amd": "cross-env rimraf dist/amd",
"build:amd": "cross-env tsc --project tsconfig.json --outDir dist/amd --module amd",
"postbuild:amd": "cross-env copyfiles --up 1 src/**/*.html src/**/*.css dist/amd",
"prebuild:commonjs": "cross-env rimraf dist/commonjs",
"build:commonjs": "cross-env tsc --project tsconfig.json --outDir dist/commonjs --module commonjs",
"postbuild:commonjs": "cross-env copyfiles --up 1 src/**/*.html src/**/*.css dist/commonjs",
"prebuild:es2015": "cross-env rimraf dist/es2015",
"build:es2015": "cross-env tsc --project tsconfig.json --outDir dist/es2015 --module es2015 --target es2015",
"postbuild:es2015": "cross-env copyfiles --up 1 src/**/*.html src/**/*.css dist/es2015",
"prebuild:native-modules": "cross-env rimraf dist/native-modules",
"build:native-modules": "cross-env tsc --project tsconfig.json --outDir dist/native-modules --module es2015",
"postbuild:native-modules": "cross-env copyfiles --up 1 src/**/*.html src/**/*.css dist/native-modules",
"prebuild:system": "cross-env rimraf dist/system",
"build:system": "cross-env tsc --project tsconfig.json --outDir dist/system --module system",
"postbuild:system": "cross-env copyfiles --up 1 src/**/*.html src/**/*.css dist/system",
"develop2": "rollup -c -w",
"prebuild": "cross-env rimraf dist",
"build": "concurrently \"npm run build:amd\" \"npm run build:commonjs\" \"npm run build:es2015\" \"npm run build:native-modules\" \"npm run build:system\"",
"build": "rollup -c --environment NODE_ENV:production",
"predoc": "cross-env rimraf doc/api.json && rimraf dist/doc-temp && tsc --project tsconfig.json --outFile dist/doc-temp/aurelia-ux.js && node doc/shape-defs && copyfiles tsconfig.json dist/doc-temp",
"doc": "cross-env typedoc --json doc/api.json --excludeExternals --includeDeclarations --mode modules --target ES6 --name aurelia-ux-docs dist/doc-temp/",
"postdoc": "cross-env node doc/shape-doc && rimraf dist/doc-temp",
Expand Down Expand Up @@ -126,15 +114,9 @@
"tsconfig-paths": "^3.1.1",
"tslint": "^4.4.2",
"typedoc": "^0.9.0",
"rollup": "^0.55.1",
"rollup-plugin-typescript2": "^0.10.0",
"typescript": "^2.2.1",
"webpack": "^4.0.1"
},
"aurelia": {
"build": {
"resources": []
},
"documentation": {
"articles": []
}
}
}
102 changes: 102 additions & 0 deletions packages/core/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import typescript from 'rollup-plugin-typescript2';
import * as fse from 'fs-extra';
import * as colors from 'colors';

export default ([
{
input: 'src/index.ts',
output: {
file: 'dist/es2015/index.js',
format: 'es'
},
plugins: [
typescript({
useTsconfigDeclarationDir: true,
tsconfigOverride: {
compilerOptions: {
target: 'es2015'
}
},
cacheRoot: '.rollupcache'
}),
copy({
verbose: true,
files: [
{ from: 'src/reset.css', to: 'dist/es2015/reset.css' },
{ from: 'src/effects/paper-ripple.css', to: 'dist/es2015/paper-ripple.css' }
]
})
]
}
].concat(process.env.NODE_ENV !== 'production'
? []
: [{
input: 'src/index.ts',
output: [
{ file: 'dist/commonjs/index.js', format: 'cjs' },
{ file: 'dist/amd/index.js', format: 'amd', amd: { id: '@aurelia-ux/core' } },
{ file: 'dist/native-modules/index.js', format: 'es' }
],
plugins: [
typescript({
tsconfigOverride: {
compilerOptions: {
declaration: false,
declarationDir: null
}
},
cacheRoot: '.rollupcache',
}),
copy({
verbose: true,
files: [
{ from: 'src/reset.css', to: 'dist/commonjs/reset.css' },
{ from: 'src/reset.css', to: 'dist/amd/reset.css' },
{ from: 'src/reset.css', to: 'dist/native-modules/reset.css' },
{ from: 'src/effects/paper-ripple.css', to: 'dist/commonjs/paper-ripple.css' },
{ from: 'src/effects/paper-ripple.css', to: 'dist/amd/paper-ripple.css' },
{ from: 'src/effects/paper-ripple.css', to: 'dist/native-modules/paper-ripple.css' }
]
})
]
}]
));

function success (name, src, dest) {
console.log('(' + name + ") '" + src.green + "' -> '" + dest.green + "' (" + '\u2714'.green + ')');
}

function fatal (name, src, dest, err) {
console.error('(' + name + ") '" + src.red + "' -> '" + dest.red + "' (" + '\u2718'.red + ')');
console.error();
console.error(' ' + err);
process.exit(err.errno);
}

var copyTimer;

/**
* @param {{ verbose: boolean, files: { from: string, to: string }[] }} options
*/
function copy (options = {}) {
const { verbose = false, files = [] } = options;
const name = 'rollup-plugin-copy-fork-aurelia';

return {
name: name,
onwrite: function (object) {
clearTimeout(copyTimer);
copyTimer = setTimeout(() => {
for (const { from, to } of files) {
fse.copy(from, to).then(() => {
if (verbose) {
success(name, from, to);
}
}).catch(ex => {
fatal(name, from, to, ex);
});
}
}, 1000);
}
};
}
49 changes: 25 additions & 24 deletions packages/core/src/aurelia-ux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,33 @@ export class AureliaUX {
const adapters = this.adapters;
let elementAdapters = adapters[tagName] || adapters[tagName.toLowerCase()];
if (!elementAdapters) {
elementAdapters = adapters[tagName] = adapters[tagName.toLowerCase()] = {} as any;
elementAdapters = adapters[tagName] = adapters[tagName.toLowerCase()] = { tagName: tagName, properties: {} };
}
return elementAdapters;
}

private interceptDetermineDefaultBindingMode(): void {
const ux = this;
const originalFn = SyntaxInterpreter.prototype.determineDefaultBindingMode;

SyntaxInterpreter.prototype.determineDefaultBindingMode = function(
this: SyntaxInterpreter,
element: Element,
attrName: string,
context?: any
) {
const tagName = element.getAttribute('as-element') || element.tagName;
const elAdapters = ux.adapters[tagName];
if (elAdapters) {
const propertyAdapter = elAdapters.properties[attrName];
if (propertyAdapter) {
return propertyAdapter.defaultBindingMode;
}
}
return originalFn.call(this, element, attrName, context);
};
}

public start(config: FrameworkConfiguration) {
const found = this.availableHosts.find(x => x.isAvailable);

Expand All @@ -107,6 +129,7 @@ export class AureliaUX {
this.designProcessor.setSwatchVariables();
this.designProcessor.setDesignVariables(platform.design);
this.designProcessor.setDesignWatches(platform.design);
return this;
});
}

Expand All @@ -116,7 +139,7 @@ export class AureliaUX {
this.adapterCreated = true;
}
const elementAdapters = this.getOrCreateUxElementAdapters(tagName);
elementAdapters.properties = properties;
Object.assign(elementAdapters.properties, properties);
}

public registerUxElementConfig(observerAdapter: UxElementObserverAdapter) {
Expand All @@ -126,26 +149,4 @@ export class AureliaUX {
}
this.addUxElementObserverAdapter(observerAdapter.tagName.toUpperCase(), observerAdapter.properties);
}

private interceptDetermineDefaultBindingMode(): void {
const ux = this;
const originalFn = SyntaxInterpreter.prototype.determineDefaultBindingMode;

SyntaxInterpreter.prototype.determineDefaultBindingMode = function(
this: SyntaxInterpreter,
element: Element,
attrName: string,
context?: any
) {
const tagName = element.getAttribute('as-element') || element.tagName;
const elAdapters = ux.adapters[tagName];
if (elAdapters) {
const propertyAdapter = elAdapters.properties[attrName];
if (propertyAdapter) {
return propertyAdapter.defaultBindingMode;
}
}
return originalFn.call(this, element, attrName, context);
};
}
}
22 changes: 14 additions & 8 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { FrameworkConfiguration, PLATFORM } from 'aurelia-framework';
import { BindingBehaviorResource, FrameworkConfiguration, PLATFORM, ViewResources } from 'aurelia-framework';

import { AureliaUX } from './aurelia-ux';
import { BooleanBB } from './components/boolean-attr-binding-behavior';

export { swatches } from './colors/swatches';
export { shadows } from './colors/shadows';
export { processDesignAttributes } from './designs/design-attributes';
Expand All @@ -18,18 +20,22 @@ export { GlobalStyleEngine } from './styles/global-style-engine';
export { AureliaUX } from './aurelia-ux';
export { UXConfiguration } from './ux-configuration';

export function configure(config: FrameworkConfiguration, callback?: (config: AureliaUX) => Promise<any>) {
const ux = config.container.get(AureliaUX) as AureliaUX;
let uxCorePromise: Promise<AureliaUX>;

config.globalResources([
PLATFORM.moduleName('./components/boolean-attr-binding-behavior')
]);
export function configure(config: FrameworkConfiguration, callback?: (config: AureliaUX) => Promise<any>) {
if (uxCorePromise) {
return uxCorePromise;
}
const ux: AureliaUX = config.container.get(AureliaUX);
const boolAttr = new BindingBehaviorResource('');
boolAttr.initialize(config.container, BooleanBB);
boolAttr.register(config.aurelia.resources, 'booleanAttr');

if (typeof callback === 'function') {
return Promise.resolve(callback(ux))
return uxCorePromise = Promise.resolve(callback(ux))
.then(() => ux.start(config));
} else {
ux.use.defaultConfiguration();
return ux.start(config);
return uxCorePromise = ux.start(config);
}
}
34 changes: 31 additions & 3 deletions packages/core/test/unit/aurelia-ux.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
import {configure} from '../../src/index';
import { AureliaUX } from '../../src/index';
import { Container, bindingMode, ObserverLocator } from 'aurelia-framework';

describe('aurelia-ux/core', () => {
it('configure is defined', () => {
expect(configure).toBeDefined();
let container: Container;
let ux: AureliaUX;
let observerLocator: ObserverLocator;

beforeEach(() => {
container = new Container();
ux = container.get(AureliaUX);
observerLocator = container.get(ObserverLocator);
});

it('add ux elements observer adapter', () => {
let adapter: any = {};

ux.addUxElementObserverAdapter('UX-INPUT', {
value: {
defaultBindingMode: bindingMode.twoWay,
getObserver: () => adapter
}
});

let input = document.createElement('ux-input');
// needs a getter to get it resolves to adapter
Object.defineProperty(input, 'value', {
get() {
return '';
}
});
let observer = observerLocator.getObserver(input, 'value');
expect(observer).toBe(adapter);
});
});
1 change: 1 addition & 0 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"noImplicitReturns": true,
"strictNullChecks": true,
"declaration": true,
"declarationDir": "dist/types",
"forceConsistentCasingInFileNames": true,
"experimentalDecorators": true,
"noEmitHelpers": false,
Expand Down

0 comments on commit 89f5f7f

Please sign in to comment.