From 813ae4df674e43679bbeb04b8ae2c5e00972da97 Mon Sep 17 00:00:00 2001 From: Hans Larsen Date: Fri, 29 Jan 2016 14:01:19 -0800 Subject: [PATCH] feat(): Dartanalyzer running. --- .gitignore | 4 ++ docs/dart/writing-compatible-typescript.md | 2 +- ember-cli-build.js | 56 +++++++++++++++++----- package.json | 2 + tools/broccoli/broccoli-dest-copy.ts | 10 ++-- 5 files changed, 55 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 76469371e96..59d6031380c 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,10 @@ /.packages /packages /pubspec.lock +/src/.pub +/src/.packages +/src/packages +/src/pubspec.lock # IDEs diff --git a/docs/dart/writing-compatible-typescript.md b/docs/dart/writing-compatible-typescript.md index 1e492604339..890129cf96f 100644 --- a/docs/dart/writing-compatible-typescript.md +++ b/docs/dart/writing-compatible-typescript.md @@ -37,4 +37,4 @@ Here's a list of gotchas to keep in mind when writing TypeScript code that will * **Boolean expressions are required to be boolean.** There's no type coercion or truthiness concept in Dart. Code like this: `if (!aNumber) {}` must be refactored to be `if (aNumber != 0) {}`. * **Accessing any platform primitive must be done through a Facade.** For example, Promises or DOM manipulation. Facades are going to be provided on a need-to-have basis. * **Union types are a no-go.** Dart has them on its roadmap, but for now we must avoid them. -* **Dart files cannot have the same name as a reserved keyword.** For example, `for.dart`, `switch.dart` or `class.dart` are all invalid names. Since the TypeScript files have the same name when transpiled to Dart, they also have the same restriction. \ No newline at end of file +* **Dart files cannot have the same name as a reserved keyword.** For example, `for.dart`, `switch.dart` or `class.dart` are all invalid names. Since the TypeScript files have the same name when transpiled to Dart, they also have the same restriction. diff --git a/ember-cli-build.js b/ember-cli-build.js index 03ded4383eb..1e48d26473e 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -5,12 +5,17 @@ var path = require('path'); require('ts-node/register'); const detect = require('./tools/build/dart').detect; + var mergeTrees = require('broccoli-merge-trees'); var Angular2App = require('angular-cli/lib/broccoli/angular2-app'); var BroccoliSass = require('broccoli-sass'); var broccoliAutoprefixer = require('broccoli-autoprefixer'); -var BroccoliTs2Dart = require('./tools/broccoli/broccoli-ts2dart').default; -var dartfmt = require('./tools/broccoli/broccoli-dartfmt').default; + +const BroccoliTs2Dart = require('./tools/broccoli/broccoli-ts2dart').default; +const BroccoliDestCopy = require('./tools/broccoli/broccoli-dest-copy').default; +const BroccoliDartFmt = require('./tools/broccoli/broccoli-dartfmt').default; +const BroccoliFunnel = require('broccoli-funnel'); +const BroccoliSource = require('broccoli-source'); var autoprefixerOptions = require('./build/autoprefixer-options'); @@ -31,17 +36,8 @@ module.exports = function(defaults) { /** Gets the Dart tree - Transpile Dart files and format them afterward. */ function getDartTree(root) { - const ts2dart = new BroccoliTs2Dart('src/', { - generateLibraryName: true, - generateSourceMap: false, - translateBuiltins: true, - }); - const dartSDK = detect(); - if (dartSDK) { - // If Dart isn't found, detect() will throw an error. - return dartfmt(ts2dart, { dartSDK }); - } else { + if (!dartSDK) { console.warn('---------------------------------------'); console.warn('You do not have the Dart SDK installed.'); console.warn('In order to contribute to this repo, please refer to'); @@ -50,6 +46,41 @@ function getDartTree(root) { console.warn('You can still build and serve the demo app without dart support.'); return null; } + + const ts2dart = new BroccoliTs2Dart(root, { + generateLibraryName: true, + generateSourceMap: false, + translateBuiltins: true, + }); + + const formatter = new BroccoliDartFmt(ts2dart, { dartSDK }); + + const dartSources = new BroccoliFunnel(root, { + include: ['**/*.dart'], + destDir: 'dart/web', + }); + + const allDartFiles = mergeTrees([ + dartSources, + formatter + ]); + + //const pubSpecTree = new BroccoliFunnel('.', { + // files: ['pubspec.yaml'], + // //exclude: ['**/*'], + // destDir: 'dart' + //}); + const pubSpecTree = new BroccoliFunnel(new BroccoliSource.UnwatchedDir('.'), { + files: ['pubspec.yaml'], + destDir: 'dart', + }); + + // Publishes the Dart files and pubspec inside a + return mergeTrees([ + dartSources, + pubSpecTree, + new BroccoliDestCopy(formatter, 'dart/web'), + ]); } /** Gets the tree for all of the components' CSS. */ @@ -74,4 +105,3 @@ function getCssTree(folder) { }, []); return broccoliAutoprefixer(mergeTrees(componentCssTrees), autoprefixerOptions); } - diff --git a/package.json b/package.json index 289fa6d59ff..2f83a3b5ef3 100644 --- a/package.json +++ b/package.json @@ -31,8 +31,10 @@ "angular-cli": "0.0.*", "angular-cli-github-pages": "^0.2.0", "broccoli-autoprefixer": "^4.1.0", + "broccoli-funnel": "^1.0.1", "broccoli-merge-trees": "^1.1.1", "broccoli-sass": "^0.7.0", + "broccoli-source": "^1.1.0", "browserstacktunnel-wrapper": "^1.4.2", "ember-cli-inject-live-reload": "^1.3.0", "fs-extra": "^0.26.5", diff --git a/tools/broccoli/broccoli-dest-copy.ts b/tools/broccoli/broccoli-dest-copy.ts index ecfd90a482b..d8e0426b85a 100644 --- a/tools/broccoli/broccoli-dest-copy.ts +++ b/tools/broccoli/broccoli-dest-copy.ts @@ -11,22 +11,22 @@ import {wrapDiffingPlugin, DiffingBroccoliPlugin, DiffResult} from './diffing-br * and tees a copy to the given path outside the tmp dir. */ class DestCopy implements DiffingBroccoliPlugin { - constructor(private inputPath, private cachePath, private outputRoot: string) {} + constructor(private inputPath, private cachePath: string, private outputRoot: string) {} rebuild(treeDiff: DiffResult) { treeDiff.addedPaths.concat(treeDiff.changedPaths) .forEach((changedFilePath) => { - var destFilePath = path.join(this.outputRoot, changedFilePath); - + var sourceFilePath = path.join(this.inputPath, changedFilePath); + var destFilePath = path.join(this.cachePath, this.outputRoot, changedFilePath); var destDirPath = path.dirname(destFilePath); + fse.mkdirsSync(destDirPath); - fse.copySync(path.join(this.inputPath, changedFilePath), destFilePath); + fse.copySync(sourceFilePath, destFilePath); }); treeDiff.removedPaths.forEach((removedFilePath) => { var destFilePath = path.join(this.outputRoot, removedFilePath); - // TODO: what about obsolete directories? we are not cleaning those up yet fs.unlinkSync(destFilePath); });