diff --git a/gulpfile.js b/gulpfile.js index 3eafe41421..fee160df25 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,247 +1,12 @@ -const gulp = require('gulp'); +'use strict'; +/** + * Load the TypeScript compiler and then load the tasks from 'scripts/gulp'. + */ const path = require('path'); -const sass = require('gulp-sass'); -const replace = require('gulp-replace'); -const rollup = require('gulp-rollup'); -const rename = require('gulp-rename'); -const resolve = require('rollup-plugin-node-resolve'); -const semver = require('semver'); -const bump = require('gulp-bump'); -var typedoc = require('gulp-typedoc'); -var exec = require('child_process').execSync; -const VERSION = require('./package.json').version; -var export_sass = require('./scripts/export-themes'); -const inline_resources = require('./scripts/inline-resources'); +const gulpPath = path.join(__dirname, 'scripts/gulp'); +const tsconfigPath = path.join(gulpPath, 'tsconfig.json'); +const tsconfig = require(tsconfigPath); -const BUILD_DIR = './.ng_build'; -const LIB_DIR = './src/.lib'; -const ROLLUP_GLOBALS = { - 'tslib': 'tslib', - - // Angular dependencies - '@angular/animations': 'ng.animations', - '@angular/core': 'ng.core', - '@angular/common': 'ng.common', - '@angular/forms': 'ng.forms', - '@angular/common/http': 'ng.common.http', - '@angular/router': 'ng.router', - '@angular/platform-browser': 'ng.platformBrowser', - '@angular/platform-server': 'ng.platformServer', - '@angular/platform-browser-dynamic': 'ng.platformBrowserDynamic', - '@angular/platform-browser/animations': 'ng.platformBrowser.animations', - '@angular/core/testing': 'ng.core.testing', - '@angular/common/testing': 'ng.common.testing', - '@angular/common/http/testing': 'ng.common.http.testing', - - - // RxJS dependencies - 'rxjs/BehaviorSubject': 'Rx', - 'rxjs/ReplaySubject': 'Rx', - 'rxjs/Observable': 'Rx', - 'rxjs/Subject': 'Rx', - 'rxjs/Subscription': 'Rx', - 'rxjs/Observer': 'Rx', - 'rxjs/Subscriber': 'Rx', - 'rxjs/Scheduler': 'Rx', - - 'rxjs/observable/combineLatest': 'Rx.Observable', - 'rxjs/observable/forkJoin': 'Rx.Observable', - 'rxjs/observable/fromEvent': 'Rx.Observable', - 'rxjs/observable/merge': 'Rx.Observable', - 'rxjs/observable/of': 'Rx.Observable', - 'rxjs/observable/throw': 'Rx.Observable', - 'rxjs/observable/defer': 'Rx.Observable', - 'rxjs/observable/fromEventPattern': 'Rx.Observable', - 'rxjs/observable/empty': 'Rx.Observable', - - 'rxjs/operators/debounceTime': 'Rx.operators', - 'rxjs/operators/takeUntil': 'Rx.operators', - 'rxjs/operators/take': 'Rx.operators', - 'rxjs/operators/first': 'Rx.operators', - 'rxjs/operators/filter': 'Rx.operators', - 'rxjs/operators/map': 'Rx.operators', - 'rxjs/operators/tap': 'Rx.operators', - 'rxjs/operators/startWith': 'Rx.operators', - 'rxjs/operators/auditTime': 'Rx.operators', - 'rxjs/operators/switchMap': 'Rx.operators', - 'rxjs/operators/switchMapTo': 'Rx.operators', - 'rxjs/operators/finalize': 'Rx.operators', - 'rxjs/operators/catchError': 'Rx.operators', - 'rxjs/operators/share': 'Rx.operators', - 'rxjs/operators/delay': 'Rx.operators', - 'rxjs/operators/combineLatest': 'Rx.operators', - 'rxjs/operators/pairwise': 'Rx.operators', - 'rxjs/operators/distinctUntilChanged': 'Rx.operators', - 'rxjs/operators/takeWhile': 'Rx.operators', - 'rxjs/operators/repeat': 'Rx.operators', - - // 3rd party dependencies - - // @nebular dependencies - '@nebular/theme': 'nb.theme', - '@nebular/auth': 'nb.auth', - '@nebular/security': 'nb.security', -}; -const ROLLUP_COMMON_CONFIG = { - sourceMap: true, - rollup: require('rollup'), - context: 'this', - globals: ROLLUP_GLOBALS, - external: Object.keys(ROLLUP_GLOBALS), - plugins: [ - resolve({ - jsnext: true, - main: true - }), - ], -}; - -gulp.task('copy-sources', copySources); -gulp.task('default', ['copy-sources']); -gulp.task('inline-resources', copyResources); -gulp.task('bundle:umd:theme', bundleUmdTheme); -gulp.task('bundle:umd:auth', bundleUmdAuth); -gulp.task('bundle:umd:security', bundleUmdSecurity); -gulp.task('bundle', ['bundle:umd:theme', 'bundle:umd:auth', 'bundle:umd:security']); -gulp.task('bump', bumpVersions); - -function bumpVersions() { - gulp.src([ - './package.json', - './src/framework/theme/package.json', - './src/framework/auth/package.json', - './src/framework/security/package.json', - ], {base: './'}) - .pipe(bump({ - version: VERSION - })) - .pipe(gulp.dest('./')); -} - -function copySources() { - gulp.src('./src/framework/**/*') - .pipe(gulp.dest(BUILD_DIR)) - .on('end', replaceScssWithCss); -} - -function replaceScssWithCss() { - gulp.src(`${BUILD_DIR}/**/*.ts`) - .pipe(replace('.scss', '.css')) - .pipe(gulp.dest(BUILD_DIR)) - .on('end', compileSass); -} - -function compileSass() { - gulp.src(`${BUILD_DIR}/**/*.scss`) - .pipe(sass({ - outputStyle: 'compressed', - importer: function (url, prev, done) { - if (url[0] === '~') { - url = path.resolve('node_modules', url.substr(1)); - } - done({ - file: url - }); - } - })) - .pipe(gulp.dest(BUILD_DIR)); -} - -function copyResources() { - gulp.src([ - `${BUILD_DIR}/**/*.html`, - `${BUILD_DIR}/**/*.css`, - `${BUILD_DIR}/**/*.scss`, - `${BUILD_DIR}/**/LICENSE.txt`, - `${BUILD_DIR}/**/README.md`, - `${BUILD_DIR}/**/package.json`, - ]) - .pipe(gulp.dest(LIB_DIR)) - .on('end', inlineResources); -} - -function inlineResources() { - inline_resources(LIB_DIR); -} - -function bundleUmdTheme() { - const config = { - src: `${LIB_DIR}/theme/**/*.js`, - moduleName: 'nb.theme', - entry: `${LIB_DIR}/theme/index.js`, - format: 'umd', - output: 'theme.umd.js', - dest: `${LIB_DIR}/theme/bundles`, - }; - - bundle(config); -} - -function bundleUmdAuth() { - const config = { - src: `${LIB_DIR}/auth/**/*.js`, - moduleName: 'nb.auth', - entry: `${LIB_DIR}/auth/index.js`, - format: 'umd', - output: 'auth.umd.js', - dest: `${LIB_DIR}/auth/bundles`, - }; - - bundle(config); -} - -function bundleUmdSecurity() { - const config = { - src: `${LIB_DIR}/security/**/*.js`, - moduleName: 'nb.security', - entry: `${LIB_DIR}/security/index.js`, - format: 'umd', - output: 'security.umd.js', - dest: `${LIB_DIR}/security/bundles`, - }; - - bundle(config); -} - -function bundle(config) { - gulp.src(config.src) - .pipe(rollup(Object.assign({}, ROLLUP_COMMON_CONFIG, { - moduleName: config.moduleName, - entry: config.entry, - format: config.format, - }))) - .pipe(rename(config.output)) - .pipe(gulp.dest(config.dest)); -} - -gulp.task('generate-doc-json', generateDocJson); - -function generateDocJson() { - return gulp - .src(['src/framework/**/*.ts', '!src/framework/theme/**/node_modules{,/**}']) - .pipe(typedoc({ - module: 'commonjs', - target: 'ES6', - // TODO: ignoreCompilerErrors, huh? - ignoreCompilerErrors: true, - includeDeclarations: true, - emitDecoratorMetadata: true, - experimentalDecorators: true, - excludeExternals: true, - exclude: 'node_modules/**/*', - json: 'docs/docs.json', - version: true, - noLib: true - })); -} - -gulp.task('docs', ['generate-doc-json'], parseSassThemes); - -function parseSassThemes() { - exec("prsr -g typedoc -f angular -i docs/docs.json -o docs/output.json"); - return gulp - .src('docs/themes.scss') - .pipe(sass({ - functions: export_sass('docs/'), - })); -} +// Register TypeScript. +require('ts-node').register({ project: tsconfigPath }); +require(path.join(gulpPath, 'gulpfile')); diff --git a/package-lock.json b/package-lock.json index acc1c1cfc9..f3d9332147 100644 --- a/package-lock.json +++ b/package-lock.json @@ -975,6 +975,17 @@ "@types/node": "6.0.90" } }, + "@types/gulp": { + "version": "3.8.36", + "resolved": "https://registry.npmjs.org/@types/gulp/-/gulp-3.8.36.tgz", + "integrity": "sha512-u6/zWPzYRNPAtvyFJ3/RSXjmBaBM1dVs5kW22/jU6J786ZGLfSndhLoNOpFI6FGQvqTA+QzFHjSMhpkAN+wxcQ==", + "dev": true, + "requires": { + "@types/node": "6.0.90", + "@types/orchestrator": "0.3.2", + "@types/vinyl": "2.0.2" + } + }, "@types/handlebars": { "version": "4.0.36", "resolved": "https://registry.npmjs.org/@types/handlebars/-/handlebars-4.0.36.tgz", @@ -1035,6 +1046,16 @@ "integrity": "sha512-tXoGRVdi7wZX7P1VWoV9Wfk0uYDOAHdEYXAttuWgSrN76Q32wQlSrMX0Rgyv3RTEaQY2ZLQrzYHVM2e8rfo8sA==", "dev": true }, + "@types/orchestrator": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@types/orchestrator/-/orchestrator-0.3.2.tgz", + "integrity": "sha512-cKB4yTX0wGaRCSkdHDX2fkGQbMAA8UOshC2U7DQky1CE5o+5q2iQQ8VkbPbE/88uaTtsusvBPMcCX7dgmjxBhQ==", + "dev": true, + "requires": { + "@types/node": "6.0.90", + "@types/q": "0.0.32" + } + }, "@types/q": { "version": "0.0.32", "resolved": "https://registry.npmjs.org/@types/q/-/q-0.0.32.tgz", @@ -1057,6 +1078,15 @@ "@types/node": "6.0.90" } }, + "@types/vinyl": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/@types/vinyl/-/vinyl-2.0.2.tgz", + "integrity": "sha512-2iYpNuOl98SrLPBZfEN9Mh2JCJ2EI9HU35SfgBEb51DcmaHkhp8cKMblYeBqMQiwXMgAD3W60DbQ4i/UdLiXhw==", + "dev": true, + "requires": { + "@types/node": "6.0.90" + } + }, "JSONStream": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.2.tgz", @@ -5445,7 +5475,7 @@ "requires": { "detect-file": "1.0.0", "is-glob": "3.1.0", - "micromatch": "3.1.8", + "micromatch": "3.1.9", "resolve-dir": "1.0.1" }, "dependencies": { @@ -5721,9 +5751,9 @@ "dev": true }, "micromatch": { - "version": "3.1.8", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-3.1.8.tgz", - "integrity": "sha512-/XeuOQqYg+B5kwjDWekXseSwGS7CzE0w9Gjo4Cjkf/uFitNh47NrZHAY2vp/oS2YQVfebPIdbEIvgdy+kIcAog==", + "version": "3.1.9", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-3.1.9.tgz", + "integrity": "sha512-SlIz6sv5UPaAVVFRKodKjCg48EbNoIhgetzfK/Cy0v5U52Z6zB136M8tp0UC9jM53LYbmIRihJszvvqpKkfm9g==", "dev": true, "requires": { "arr-diff": "4.0.0", diff --git a/package.json b/package.json index fcce6a5737..376e5e141b 100644 --- a/package.json +++ b/package.json @@ -101,6 +101,7 @@ "@angular/cli": "1.7.1", "@angular/compiler-cli": "^5.2.6", "@angular/language-service": "^5.2.6", + "@types/gulp": "3.8.36", "@types/jasmine": "2.8.3", "@types/jasminewd2": "2.0.3", "@types/leaflet": "1.0.60", diff --git a/scripts/gulp/gulpfile.ts b/scripts/gulp/gulpfile.ts new file mode 100644 index 0000000000..5fb06d875e --- /dev/null +++ b/scripts/gulp/gulpfile.ts @@ -0,0 +1,10 @@ +import { task } from 'gulp'; + +import './tasks/inline-resources/inline-resources'; +import './tasks/bundle/bundle'; +import './tasks/docs/docs'; +import './tasks/copy-sources'; +import './tasks/bump-versions'; + +task('default', ['copy-sources']); + diff --git a/scripts/gulp/tasks/bump-versions.ts b/scripts/gulp/tasks/bump-versions.ts new file mode 100644 index 0000000000..45d6b565d1 --- /dev/null +++ b/scripts/gulp/tasks/bump-versions.ts @@ -0,0 +1,17 @@ +import { dest, src, task } from 'gulp'; + +const bump = require('gulp-bump'); +const VERSION = require('../../../package.json').version; + +task('bump', () => { + src([ + './package.json', + './src/framework/theme/package.json', + './src/framework/auth/package.json', + './src/framework/security/package.json', + ], { base: './' }) + .pipe(bump({ + version: VERSION, + })) + .pipe(dest('./')); +}); diff --git a/scripts/gulp/tasks/bundle/bundle.ts b/scripts/gulp/tasks/bundle/bundle.ts new file mode 100644 index 0000000000..ee64d99598 --- /dev/null +++ b/scripts/gulp/tasks/bundle/bundle.ts @@ -0,0 +1,62 @@ +import { dest, src, task } from 'gulp'; +import { ROLLUP_COMMON_CONFIG } from './rollup-config'; +import { LIB_DIR } from '../config'; + +const rollup = require('gulp-rollup'); +const rename = require('gulp-rename'); + +task('bundle', ['bundle:umd:theme', 'bundle:umd:auth', 'bundle:umd:security']); +task('bundle:umd:theme', bundleUmdTheme); +task('bundle:umd:auth', bundleUmdAuth); +task('bundle:umd:security', bundleUmdSecurity); + +function bundleUmdTheme() { + const config = { + src: `${LIB_DIR}/theme/**/*.js`, + moduleName: 'nb.theme', + entry: `${LIB_DIR}/theme/index.js`, + format: 'umd', + output: 'theme.umd.js', + dest: `${LIB_DIR}/theme/bundles`, + }; + + bundle(config); +} + +function bundleUmdAuth() { + const config = { + src: `${LIB_DIR}/auth/**/*.js`, + moduleName: 'nb.auth', + entry: `${LIB_DIR}/auth/index.js`, + format: 'umd', + output: 'auth.umd.js', + dest: `${LIB_DIR}/auth/bundles`, + }; + + bundle(config); +} + +function bundleUmdSecurity() { + const config = { + src: `${LIB_DIR}/security/**/*.js`, + moduleName: 'nb.security', + entry: `${LIB_DIR}/security/index.js`, + format: 'umd', + output: 'security.umd.js', + dest: `${LIB_DIR}/security/bundles`, + }; + + bundle(config); +} + +function bundle(config: any) { + src(config.src) + .pipe(rollup(Object.assign({}, ROLLUP_COMMON_CONFIG, { + moduleName: config.moduleName, + entry: config.entry, + format: config.format, + }))) + .pipe(rename(config.output)) + .pipe(dest(config.dest)); +} + diff --git a/scripts/gulp/tasks/bundle/rollup-config.ts b/scripts/gulp/tasks/bundle/rollup-config.ts new file mode 100644 index 0000000000..1660411b53 --- /dev/null +++ b/scripts/gulp/tasks/bundle/rollup-config.ts @@ -0,0 +1,83 @@ +const resolve = require('rollup-plugin-node-resolve'); + +const ROLLUP_GLOBALS = { + 'tslib': 'tslib', + + // Angular dependencies + '@angular/animations': 'ng.animations', + '@angular/core': 'ng.core', + '@angular/common': 'ng.common', + '@angular/forms': 'ng.forms', + '@angular/common/http': 'ng.common.http', + '@angular/router': 'ng.router', + '@angular/platform-browser': 'ng.platformBrowser', + '@angular/platform-server': 'ng.platformServer', + '@angular/platform-browser-dynamic': 'ng.platformBrowserDynamic', + '@angular/platform-browser/animations': 'ng.platformBrowser.animations', + '@angular/core/testing': 'ng.core.testing', + '@angular/common/testing': 'ng.common.testing', + '@angular/common/http/testing': 'ng.common.http.testing', + + + // RxJS dependencies + 'rxjs/BehaviorSubject': 'Rx', + 'rxjs/ReplaySubject': 'Rx', + 'rxjs/Observable': 'Rx', + 'rxjs/Subject': 'Rx', + 'rxjs/Subscription': 'Rx', + 'rxjs/Observer': 'Rx', + 'rxjs/Subscriber': 'Rx', + 'rxjs/Scheduler': 'Rx', + + 'rxjs/observable/combineLatest': 'Rx.Observable', + 'rxjs/observable/forkJoin': 'Rx.Observable', + 'rxjs/observable/fromEvent': 'Rx.Observable', + 'rxjs/observable/merge': 'Rx.Observable', + 'rxjs/observable/of': 'Rx.Observable', + 'rxjs/observable/throw': 'Rx.Observable', + 'rxjs/observable/defer': 'Rx.Observable', + 'rxjs/observable/fromEventPattern': 'Rx.Observable', + 'rxjs/observable/empty': 'Rx.Observable', + + 'rxjs/operators/debounceTime': 'Rx.operators', + 'rxjs/operators/takeUntil': 'Rx.operators', + 'rxjs/operators/take': 'Rx.operators', + 'rxjs/operators/first': 'Rx.operators', + 'rxjs/operators/filter': 'Rx.operators', + 'rxjs/operators/map': 'Rx.operators', + 'rxjs/operators/tap': 'Rx.operators', + 'rxjs/operators/startWith': 'Rx.operators', + 'rxjs/operators/auditTime': 'Rx.operators', + 'rxjs/operators/switchMap': 'Rx.operators', + 'rxjs/operators/switchMapTo': 'Rx.operators', + 'rxjs/operators/finalize': 'Rx.operators', + 'rxjs/operators/catchError': 'Rx.operators', + 'rxjs/operators/share': 'Rx.operators', + 'rxjs/operators/delay': 'Rx.operators', + 'rxjs/operators/combineLatest': 'Rx.operators', + 'rxjs/operators/pairwise': 'Rx.operators', + 'rxjs/operators/distinctUntilChanged': 'Rx.operators', + 'rxjs/operators/takeWhile': 'Rx.operators', + 'rxjs/operators/repeat': 'Rx.operators', + + // 3rd party dependencies + + // @nebular dependencies + '@nebular/theme': 'nb.theme', + '@nebular/auth': 'nb.auth', + '@nebular/security': 'nb.security', +}; + +export const ROLLUP_COMMON_CONFIG = { + sourceMap: true, + rollup: require('rollup'), + context: 'this', + globals: ROLLUP_GLOBALS, + external: Object.keys(ROLLUP_GLOBALS), + plugins: [ + resolve({ + jsnext: true, + main: true, + }), + ], +}; diff --git a/scripts/gulp/tasks/config.ts b/scripts/gulp/tasks/config.ts new file mode 100644 index 0000000000..c511e2e640 --- /dev/null +++ b/scripts/gulp/tasks/config.ts @@ -0,0 +1,2 @@ +export const BUILD_DIR = './.ng_build'; +export const LIB_DIR = './src/.lib'; diff --git a/scripts/gulp/tasks/copy-sources.ts b/scripts/gulp/tasks/copy-sources.ts new file mode 100644 index 0000000000..b5bb0c2fa6 --- /dev/null +++ b/scripts/gulp/tasks/copy-sources.ts @@ -0,0 +1,36 @@ +import { dest, src, task } from 'gulp'; +import * as path from 'path'; +import { BUILD_DIR } from './config'; + +const sass = require('gulp-sass'); +const replace = require('gulp-replace'); + +task('copy-sources', () => { + src('./src/framework/**/*') + .pipe(dest(BUILD_DIR)) + .on('end', replaceScssWithCss); +}); + +function replaceScssWithCss() { + src(`${BUILD_DIR}/**/*.ts`) + .pipe(replace('.scss', '.css')) + .pipe(dest(BUILD_DIR)) + .on('end', compileSass); +} + +function compileSass() { + src(`${BUILD_DIR}/**/*.scss`) + .pipe(sass({ + outputStyle: 'compressed', + importer: function (url: any, _: any, done: any) { + if (url[0] === '~') { + url = path.resolve('node_modules', url.substr(1)); + } + done({ + file: url, + }); + }, + })) + .pipe(dest(BUILD_DIR)); +} + diff --git a/scripts/gulp/tasks/docs/docs.ts b/scripts/gulp/tasks/docs/docs.ts new file mode 100644 index 0000000000..028013d8b0 --- /dev/null +++ b/scripts/gulp/tasks/docs/docs.ts @@ -0,0 +1,35 @@ +import { src, task } from 'gulp'; +import { exportThemes } from './export-themes'; + +const typedoc = require('gulp-typedoc'); +const sass = require('gulp-sass'); +const exec = require('child_process').execSync; + +task('docs', ['generate-doc-json'], parseSassThemes); +task('generate-doc-json', generateDocJson); + +function generateDocJson() { + return src(['src/framework/**/*.ts', '!src/framework/theme/**/node_modules{,/**}']) + .pipe(typedoc({ + module: 'commonjs', + target: 'ES6', + // TODO: ignoreCompilerErrors, huh? + ignoreCompilerErrors: true, + includeDeclarations: true, + emitDecoratorMetadata: true, + experimentalDecorators: true, + excludeExternals: true, + exclude: 'node_modules/**/*', + json: 'docs/docs.json', + version: true, + noLib: true, + })); +} + +function parseSassThemes() { + exec('prsr -g typedoc -f angular -i docs/docs.json -o docs/output.json'); + return src('docs/themes.scss') + .pipe(sass({ + functions: exportThemes('docs/', ''), + })); +} diff --git a/scripts/export-themes.js b/scripts/gulp/tasks/docs/export-themes.ts similarity index 74% rename from scripts/export-themes.js rename to scripts/gulp/tasks/docs/export-themes.ts index 235c849a5c..8bb168496d 100644 --- a/scripts/export-themes.js +++ b/scripts/gulp/tasks/docs/export-themes.ts @@ -1,30 +1,42 @@ -'use strict'; -(function (module) { - var _ = require('lodash'); - var fs = require('fs'); - var Colors = require('colors.js'); +const _ = require('lodash'); +const fs = require('fs'); +const Colors = require('colors.js'); - var exporter = {}; +class Prop { + public name: string; + public value: any = null; + public parents: any[] = []; + public childs: any[] = []; - module.exports = function (path, name) { - var out = {}; - out[exporter.interface(name)] = exporter.function(path); - return out; + constructor(name) { + this.name = name; }; +} - exporter.get_value = function get_value(a) { - var value, i; +class PropLink { + public theme: any; + public prop: any; + + constructor(theme, prop) { + this.theme = theme; + this.prop = prop; + } +} + +const exporter = { + get_value(a) { + let value, i; switch (a.constructor.name) { case 'SassList': value = []; for (i = 0; i < a.getLength(); i++) { - value.push(get_value(a.getValue(i))); + value.push(exporter.get_value(a.getValue(i))); } break; case 'SassMap': value = {}; for (i = 0; i < a.getLength(); i++) { - value[a.getKey(i).getValue()] = get_value(a.getValue(i)); + value[a.getKey(i).getValue()] = exporter.get_value(a.getValue(i)); } break; case 'SassColor': @@ -48,26 +60,10 @@ value = a.getValue(); } return value; - }; - - class Prop { - constructor(name) { - this.name = name; - this.value = null; - this.parents = []; - this.childs = []; - }; - } - - class PropLink { - constructor(theme, prop) { - this.theme = theme; - this.prop = prop; - } - } + }, - exporter.parseThemes = function(THEMES) { - var result = {}; + parseThemes(THEMES) { + let result = {}; for (let themeName in THEMES) { result[themeName] = result[themeName] ? result[themeName] : {}; result[themeName].data = result[themeName].data ? result[themeName].data : {}; @@ -82,9 +78,9 @@ let output = {}; output['themes'] = result; return output; - } + }, - exporter.getParent = function(prop, scopedThemeName, resultThemeName, resultProp, resultObj, THEMES) { + getParent(prop, scopedThemeName, resultThemeName, resultProp, resultObj, THEMES) { let scopedTheme = THEMES[scopedThemeName].data; let scopedParent = THEMES[scopedThemeName].parent; let value = scopedTheme[prop]; @@ -103,10 +99,10 @@ } } return resultObj; - } + }, - exporter.linkProps = function (resultObj, parentThemeName, parentPropName, childThemeName, childPropName) { + linkProps(resultObj, parentThemeName, parentPropName, childThemeName, childPropName) { if (!resultObj.hasOwnProperty(parentThemeName)) { resultObj[parentThemeName].data = {}; resultObj[parentThemeName].data[parentPropName] = new Prop(parentPropName); @@ -116,21 +112,28 @@ resultObj[childThemeName].data[childPropName].parents.push(new PropLink(parentThemeName, parentPropName)); resultObj[parentThemeName].data[parentPropName].childs.push(new PropLink(childThemeName, childPropName)); return resultObj; - } + }, - exporter.function = function (path) { + + function(path) { return function (file, value, options) { - let opt = _.defaults(exporter.get_value(options), {prefix: '', suffix: '', extend: false}); + let opt = _.defaults(exporter.get_value(options), { prefix: '', suffix: '', extend: false }); let output = exporter.get_value(value); output = exporter.parseThemes(output); output = _.defaults(JSON.parse(fs.readFileSync(path + '/' + file.getValue())), output); fs.writeFileSync(path + '/' + file.getValue(), opt.prefix + JSON.stringify(output, null, ' ') + opt.suffix); return value; } - }; + }, - exporter.interface = function (name) { + interface(name) { name = name || 'export'; return name + '($file, $value, $options:())'; - }; -})(module); + }, +}; + +export function exportThemes(path, name) { + const out = {}; + out[exporter.interface(name)] = exporter.function(path); + return out; +} diff --git a/scripts/inline-resources.js b/scripts/gulp/tasks/inline-resources/copy-resources.ts similarity index 89% rename from scripts/inline-resources.js rename to scripts/gulp/tasks/inline-resources/copy-resources.ts index 6ac3c47e72..92c01b8a00 100644 --- a/scripts/inline-resources.js +++ b/scripts/gulp/tasks/inline-resources/copy-resources.ts @@ -1,10 +1,6 @@ -#!/usr/bin/env node - -'use strict'; - -const fs = require('fs'); -const path = require('path'); -const glob = require('glob'); +import * as fs from 'fs'; +import * as path from 'path'; +import * as glob from 'glob'; /** * Simple Promiseify function that takes a Node API and return a version that supports promises. @@ -12,8 +8,7 @@ const glob = require('glob'); * faster. It also simplify the code. */ function promiseify(fn) { - return function () { - const args = [].slice.call(arguments, 0); + return function (...args) { return new Promise((resolve, reject) => { fn.apply(this, args.concat([function (err, value) { if (err) { @@ -30,7 +25,7 @@ const readFile = promiseify(fs.readFile); const writeFile = promiseify(fs.writeFile); -function inlineResources(globs) { +export function copyResources(globs) { if (typeof globs == 'string') { globs = [globs]; } @@ -72,12 +67,12 @@ function inlineResourcesFromString(content, urlResolver) { return [ inlineTemplate, inlineStyle, - removeModuleId + removeModuleId, ].reduce((content, fn) => fn(content, urlResolver), content); } if (require.main === module) { - inlineResources(process.argv.slice(2)); + copyResources(process.argv.slice(2)); } @@ -89,7 +84,7 @@ if (require.main === module) { * @return {string} The content with all templates inlined. */ function inlineTemplate(content, urlResolver) { - return content.replace(/templateUrl:\s*'([^']+?\.html)'/g, function (m, templateUrl) { + return content.replace(/templateUrl:\s*'([^']+?\.html)'/g, function (_, templateUrl) { const templateFile = urlResolver(templateUrl); const templateContent = fs.readFileSync(templateFile, 'utf-8'); const shortenedTemplate = templateContent @@ -108,7 +103,7 @@ function inlineTemplate(content, urlResolver) { * @return {string} The content with all styles inlined. */ function inlineStyle(content, urlResolver) { - return content.replace(/styleUrls:\s*(\[[\s\S]*?\])/gm, function (m, styleUrls) { + return content.replace(/styleUrls:\s*(\[[\s\S]*?\])/gm, function (_, styleUrls) { const urls = eval(styleUrls); return 'styles: [' + urls.map(styleUrl => { @@ -119,7 +114,7 @@ function inlineStyle(content, urlResolver) { .replace(/"/g, '\\"'); return `"${shortenedStyle}"`; }) - .join(',\n') + + .join(',\n') + ']'; }); } @@ -133,7 +128,3 @@ function inlineStyle(content, urlResolver) { function removeModuleId(content) { return content.replace(/\s*moduleId:\s*module\.id\s*,?\s*/gm, ''); } - - -module.exports = inlineResources; -module.exports.inlineResourcesFromString = inlineResourcesFromString; diff --git a/scripts/gulp/tasks/inline-resources/inline-resources.ts b/scripts/gulp/tasks/inline-resources/inline-resources.ts new file mode 100644 index 0000000000..3dc6a73433 --- /dev/null +++ b/scripts/gulp/tasks/inline-resources/inline-resources.ts @@ -0,0 +1,16 @@ +import { dest, src, task } from 'gulp'; +import { copyResources } from './copy-resources'; +import { BUILD_DIR, LIB_DIR } from '../config'; + +task('inline-resources', () => { + src([ + `${BUILD_DIR}/**/*.html`, + `${BUILD_DIR}/**/*.css`, + `${BUILD_DIR}/**/*.scss`, + `${BUILD_DIR}/**/LICENSE.txt`, + `${BUILD_DIR}/**/README.md`, + `${BUILD_DIR}/**/package.json`, + ]) + .pipe(dest(LIB_DIR)) + .on('end', () => copyResources(LIB_DIR)); +}); diff --git a/scripts/gulp/tsconfig.json b/scripts/gulp/tsconfig.json new file mode 100644 index 0000000000..522c3fea28 --- /dev/null +++ b/scripts/gulp/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "experimentalDecorators": true, + "noUnusedParameters": true, + "lib": [ + "es2017" + ], + "module": "commonjs", + "moduleResolution": "node", + "strictNullChecks": true, + "target": "es5", + "typeRoots": [ + "node_modules/@types" + ], + "types": [ + "node" + ], + "baseUrl": "." + }, + "files": [ + "gulpfile.ts" + ] +}