Skip to content

Commit

Permalink
Refactor (again) to make Angular AoT compatible.
Browse files Browse the repository at this point in the history
  • Loading branch information
dschnelldavis committed Jun 17, 2017
1 parent 768f651 commit 30d7ec7
Show file tree
Hide file tree
Showing 27 changed files with 271 additions and 292 deletions.
26 changes: 13 additions & 13 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ return Promise.resolve()
moduleName: camelCase(libName),
sourceMap: true,
// ATTENTION:
// Add any dependency or peer dependency your library to `globals` and `external`.
// This is required for UMD bundle users.
// Add any dependency or peer dependency your library to
// `globals` and `external`. This is required for UMD bundle users.
globals: {
// The key here is library name, and the value is the the name of the global variable name
// the window object.
// The key here is library name, and the value is the the name
// of the global variable name the window object.
// See https://github.com/rollup/rollup/wiki/JavaScript-API#globals for more.
'@angular/animations': 'ng.animations',
'@angular/common': 'ng.common',
Expand All @@ -71,8 +71,8 @@ return Promise.resolve()
'lodash': '_'
},
external: [
// List of dependencies
// See https://github.com/rollup/rollup/wiki/JavaScript-API#external for more.
// List of dependencies. For more, see
// https://github.com/rollup/rollup/wiki/JavaScript-API#external
'@angular/animations',
'@angular/common',
'@angular/core',
Expand Down Expand Up @@ -144,8 +144,7 @@ return Promise.resolve()
.then(() => console.log('LICENSE file copied.'))
.then(() => _relativeCopy('README.md', rootFolder, distFolder))
.then(() => console.log('README.md file copied.'))
.then(() => _relativeCopy('package.json', rootFolder, distFolder))
.then(() => _cleanPackageJson(distFolder))
.then(() => _copyPackageJson(rootFolder, distFolder))
.then(() => console.log('package.json file copied and updated.'))
)
.catch(e => {
Expand Down Expand Up @@ -179,15 +178,16 @@ function _recursiveMkDir(dir) {
}
}

// Clean package.json file
function _cleanPackageJson(dir) {
// Copy and update package.json file
function _copyPackageJson(from, to) {
return new Promise((resolve, reject) => {
const fullPath = path.join(dir, 'package.json');
let data = JSON.parse(fs.readFileSync(fullPath, 'utf-8'));
const origin = path.join(from, 'package.json');
const dest = path.join(to, 'package.json');
let data = JSON.parse(fs.readFileSync(origin, 'utf-8'));
delete data.engines;
delete data.scripts;
delete data.devDependencies;
fs.writeFileSync(fullPath, JSON.stringify(data, null, 2));
fs.writeFileSync(dest, JSON.stringify(data, null, 2));
resolve();
});
}
39 changes: 15 additions & 24 deletions inline-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,17 @@ const fs = require('fs');
const path = require('path');
const glob = require('glob');


/**
* Simple Promiseify function that takes a Node API and return a version that supports promises.
* We use promises instead of synchronized functions to make the process less I/O bound and
* faster. It also simplifies the code.
* Simple Promiseify function that takes a Node API and return a version that
* supports promises. We use promises instead of synchronized functions to
* make the process less I/O bound and faster. It also simplifies the code.
*/
function promiseify(fn) {
return function () {
const args = [].slice.call(arguments, 0);
return new Promise((resolve, reject) => {
fn.apply(this, args.concat([function (err, value) {
if (err) {
reject(err);
} else {
resolve(value);
}
if (err) { reject(err); } else { resolve(value); }
}]));
});
};
Expand Down Expand Up @@ -85,32 +80,28 @@ function inlineTemplate(content, urlResolver) {
});
}


/**
* Inline the styles for a source file. Simply search for instances of `styleUrls: [...]` and
* replace with `styles: [...]` (with the content of the file included).
* Inline the styles for a source file. Search for instances of `styleUrls: [...]`
* and replace with `styles: [...]` (with the content of the file included).
* @param urlResolver {Function} A resolver that takes a URL and return a path.
* @param content {string} The source file's content.
* @return {string} The content with all styles inlined.
*/
function inlineStyle(content, urlResolver) {
return content.replace(/styleUrls:\s*(\[[\s\S]*?\])/gm, function (m, styleUrls) {
const urls = eval(styleUrls);
return 'styles: ['
+ urls.map(styleUrl => {
const styleFile = urlResolver(styleUrl);
const styleContent = fs.readFileSync(styleFile, 'utf-8');
const shortenedStyle = styleContent
.replace(/([\n\r]\s*)+/gm, ' ')
.replace(/"/g, '\\"');
return `"${shortenedStyle}"`;
})
.join(',\n')
+ ']';
const styles = urls.map(styleUrl => {
const styleFile = urlResolver(styleUrl);
const styleContent = fs.readFileSync(styleFile, 'utf-8');
const shortenedStyle = styleContent
.replace(/([\n\r]\s*)+/gm, ' ')
.replace(/"/g, '\\"');
return `"${shortenedStyle}"`;
});
return `styles: [${styles.join(',\n')}]`;
});
}


/**
* Remove every mention of `moduleId: module.id`.
* @param content {string} The source file's content.
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular2-json-schema-form",
"version": "0.4.0-alpha.9",
"version": "0.4.0-alpha.11",
"author": {
"name": "David Schnell-Davis",
"email": "[email protected]"
Expand Down Expand Up @@ -41,11 +41,13 @@
"start": "ng serve",
"test": "ng test",
"lint": "ng lint",
"docs": "typedoc --options typedoc.json src/index.ts",
"docs": "typedoc --options typedoc.json lib/src/json-schema-form.module.ts",
"clean": "rimraf out-ngc dist/*",
"prebuild": "npm run clean",
"build": "node build.js",
"postbuild": "rimraf out-ngc",
"prepublish": "npm run build",
"publish": "cd dist && npm publish",
"ng-build": "ng build",
"old-build-demo": "tsc -p src/demo/",
"old-build-demo:watch": "tsc -p src/demo/ -w",
Expand Down
2 changes: 1 addition & 1 deletion src/demo/app/demo.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BrowserModule } from '@angular/platform-browser';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';

import { JsonSchemaFormModule } from '../../lib';
import { JsonSchemaFormModule } from '../../lib/src/json-schema-form.module';
// To include JsonSchemaFormModule after downloading from NPM, use this instead:
// import { JsonSchemaFormModule } from 'angular2-json-schema-form';

Expand Down
4 changes: 3 additions & 1 deletion src/lib/angular2-json-schema-form.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from './index';
export { JsonSchemaFormComponent } from './index';
export { JsonSchemaFormService } from './index';
export { JsonSchemaFormModule } from './index';
42 changes: 29 additions & 13 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
export * from './src/shared/convert-json-schema.functions';
export * from './src/shared/validator.functions';
export * from './src/shared/utility.functions';
export * from './src/shared/jsonpointer.functions';
export * from './src/shared/json.validators';
export * from './src/shared/json-schema.functions';
export * from './src/shared/form-group.functions';
export * from './src/shared/layout.functions';
import { convertJsonSchema3to4 } from './src/shared/convert-json-schema.functions';
import {
_executeValidators, _executeAsyncValidators, _mergeObjects, _mergeErrors,
isDefined, hasValue, isEmpty, isString, isNumber, isInteger, isBoolean,
isFunction, isObject, isArray, isMap, isSet, isPromise, getType, isType,
isPrimitive, toJavaScriptType, toSchemaType, _convertToPromise, inArray, xor,
SchemaPrimitiveType, SchemaType, JavaScriptPrimitiveType, JavaScriptType,
PrimitiveValue, PlainObject, IValidatorFn, AsyncIValidatorFn
} from './src/shared/validator.functions';
import {
addClasses, copy, forEach, forEachCopy, hasOwn,
mergeFilteredObject, parseText, toTitleCase
} from './src/shared/utility.functions';
import { Pointer, JsonPointer } from './src/shared/jsonpointer.functions';
import { JsonValidators } from './src/shared/json.validators';
import {
buildSchemaFromLayout, buildSchemaFromData, getFromSchema,
getSchemaReference, getInputType, checkInlineType, isInputRequired,
updateInputOptions, getControlValidators
} from './src/shared/json-schema.functions';
import {
buildFormGroupTemplate, buildFormGroup, setRequiredFields,
formatFormData, getControl, fixJsonFormOptions
} from './src/shared/form-group.functions';
import {
buildLayout, buildLayoutFromSchema, mapLayout, buildTitleMap
} from './src/shared/layout.functions';

import { AddReferenceComponent } from './src/widget-library/add-reference.component';
import { ButtonComponent } from './src/widget-library/button.component';
Expand All @@ -30,8 +49,9 @@ import { TabComponent } from './src/widget-library/tab.compo
import { TabsComponent } from './src/widget-library/tabs.component';
import { TemplateComponent } from './src/widget-library/template.component';
import { TextareaComponent } from './src/widget-library/textarea.component';
import { WidgetLibraryService } from './src/widget-library/widget-library.service';
import { OrderableDirective } from './src/widget-library/orderable.directive';
import { WidgetLibraryModule } from './src/widget-library/widget-library.module';
import { WidgetLibraryService } from './src/widget-library/widget-library.service';

import { MaterialAddReferenceComponent } from './src/framework-library/material-design-framework/material-add-reference.component';
import { MaterialButtonComponent } from './src/framework-library/material-design-framework/material-button.component';
Expand All @@ -50,12 +70,8 @@ import { MaterialTabsComponent } from './src/framework-library/materi
import { MaterialTextareaComponent } from './src/framework-library/material-design-framework/material-textarea.component';
import { MaterialDesignFrameworkComponent } from './src/framework-library/material-design-framework/material-design-framework.component';
import { MaterialDesignFrameworkModule } from './src/framework-library/material-design-framework/material-design-framework.module';

import { NoFrameworkComponent } from './src/framework-library/no-framework.component';
import { Bootstrap3FrameworkComponent } from './src/framework-library/bootstrap-3-framework.component';
// import { Bootstrap4FrameworkComponent } from './src/framework-library/bootstrap-4-framework.component';
// import { Foundation6FrameworkComponent } from './src/framework-library/foundation-6-framework.component';
// import { SemanticUIFrameworkComponent } from './src/framework-library/semantic-ui-framework.component';
import { FrameworkLibraryService } from './src/framework-library/framework-library.service';
import { FrameworkLibraryModule } from './src/framework-library/framework-library.module';

Expand Down
28 changes: 0 additions & 28 deletions src/lib/src/framework-library/bootstrap-4-framework.component.ts

This file was deleted.

28 changes: 0 additions & 28 deletions src/lib/src/framework-library/foundation-6-framework.component.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/lib/src/framework-library/framework-library.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { CommonModule } from '@angular/common';
import { WidgetLibraryModule } from '../widget-library/widget-library.module';
import { MaterialDesignFrameworkModule } from './material-design-framework/material-design-framework.module';

import { JsonSchemaFormService } from '../json-schema-form.service';
import { WidgetLibraryService } from '../widget-library/widget-library.service';
import { FrameworkLibraryService } from './framework-library.service';

Expand Down
Loading

0 comments on commit 30d7ec7

Please sign in to comment.