Commit 9c5eb79941f9aa30df8d9f9257da3ab35c0cdc0a

Authored by ABNER SILVA DE OLIVEIRA
1 parent d24acbad

added script to generate module indexes

.vscode/launch.json 0 → 100644
... ... @@ -0,0 +1,35 @@
  1 +{
  2 + "version": "0.2.0",
  3 + "configurations": [
  4 + {
  5 + "name": "Launch index.html",
  6 + "type": "chrome",
  7 + "request": "launch",
  8 + "file": "index.html"
  9 + },
  10 + {
  11 + "name": "Launch Noosfero NG",
  12 + "type": "chrome",
  13 + "request": "launch",
  14 + "sourceMaps": true,
  15 + "webRoot": "src/app",
  16 + "url": "http://localhost:3001/"
  17 + },
  18 + {
  19 + "name": "Launch localhost with sourcemaps",
  20 + "type": "chrome",
  21 + "request": "launch",
  22 + "url": "http://localhost/mypage.html",
  23 + "sourceMaps": true,
  24 + "webRoot": "wwwroot"
  25 + },
  26 + {
  27 + "name": "Attach",
  28 + "type": "chrome",
  29 + "request": "attach",
  30 + "sourceMaps": true,
  31 + "webRoot": "./",
  32 + "port": 9222
  33 + }
  34 + ]
  35 +}
0 36 \ No newline at end of file
... ...
dev-scripts/generate-index-modules.ts 0 → 100644
... ... @@ -0,0 +1,33 @@
  1 +import * as glob from "glob";
  2 +import * as path from "path";
  3 +import * as fs from "fs";
  4 +let directories = glob.sync("./src/app/**/**/");
  5 +
  6 +// maps to absolute path
  7 +directories = directories.map((directory: string) => {
  8 + return path.resolve(__dirname, "..", directory);
  9 +});
  10 +
  11 +// iterate to generate the index folders
  12 +directories.forEach((directory: string) => {
  13 + // skips the app directory
  14 + if (!/\/app$/.test(directory)) {
  15 + let current_files = glob.sync("./*.ts", { nodir: true, cwd: directory, ignore: ['./index.ts', './*.spec.ts'] });
  16 + console.log("DIRECTORY: ", directory);
  17 + console.log("FILES: ", current_files);
  18 +
  19 + let indexPath = path.join(directory, "index.ts");
  20 +
  21 + let index_ts_content: string = "/* Module Index Entry - generated using the script npm run generate-index */\n";
  22 +
  23 + let exports_content = current_files.map((file) => {
  24 + return `export * from "./${path.basename(file, ".ts")}";\n`;
  25 + });
  26 +
  27 + fs.writeFileSync(indexPath, index_ts_content + exports_content.join(""));
  28 +
  29 + }
  30 +
  31 +
  32 +
  33 +});
... ...
dev-scripts/node_modules 0 → 120000
... ... @@ -0,0 +1 @@
  1 +../node_modules
0 2 \ No newline at end of file
... ...
dev-scripts/tsconfig.json 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +{
  2 + "compilerOptions": {
  3 + "module": "commonjs",
  4 + "target": "es5",
  5 + "noImplicitAny": false,
  6 + "sourceMap": true
  7 + },
  8 + "exclude": [
  9 + "node_modules",
  10 + "typings/browser",
  11 + "typings/browser.d.ts"
  12 + ]
  13 +}
0 14 \ No newline at end of file
... ...
dev-scripts/typings.json 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +{
  2 + "dependencies": {},
  3 + "devDependencies": {},
  4 + "ambientDependencies": {
  5 + "glob": "github:DefinitelyTyped/DefinitelyTyped/glob/glob.d.ts#a14d724826174d1669d4df04c80f4838b7e71fdf",
  6 + "minimatch": "github:DefinitelyTyped/DefinitelyTyped/minimatch/minimatch.d.ts#a3900b896f7b3361b79f9b503224777619907d53",
  7 + "node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#48c1e3c1d6baefa4f1a126f188c27c4fefd36bff"
  8 + }
  9 +}
... ...
package.json
... ... @@ -9,7 +9,8 @@
9 9 "scripts": {
10 10 "test": "concurrently \"webpack -w\" \"karma start\"",
11 11 "postinstall": "npm install -g bower && bower install",
12   - "start": "concurrently \"webpack -w\" \"gulp serve\""
  12 + "start": "concurrently \"webpack -w\" \"gulp serve\"",
  13 + "generate-indexes": "ts-node --project ./dev-scripts ./dev-scripts/generate-index-modules.ts"
13 14 },
14 15 "devDependencies": {
15 16 "browser-sync": "~2.9.11",
... ... @@ -65,6 +66,7 @@
65 66 "phantomjs-polyfill": "0.0.2",
66 67 "reflect-metadata": "^0.1.3",
67 68 "ts-loader": "^0.8.1",
  69 + "ts-node": "^0.5.5",
68 70 "typescript": "^1.8.2",
69 71 "typings": "^0.6.8",
70 72 "uglify-save-license": "~0.4.1",
... ...
src/app/cms/index.ts 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +/* Module Index Entry - generated using the script npm run generate-index */
  2 +export * from "./cms.component";
... ...
src/app/components/auth/auth_controller.spec.ts 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +import {AuthController} from "./auth_controller";
  2 +import {AuthService} from "./auth_service";
  3 +
  4 +describe("AuthController", () => {
  5 +
  6 + it("calls authenticate on AuthService when login called", () => {
  7 +
  8 + // creating a Mock AuthService
  9 + let AuthServiceMock: AuthService = jasmine.createSpyObj("AuthService", ["login"]);
  10 +
  11 + // pass AuthServiceMock into the constructor
  12 + let authController = new AuthController(null, null, null, AuthServiceMock);
  13 +
  14 + // setup of authController -> set the credentials instance property
  15 + let credentials = { username: "username", password: "password" };
  16 +
  17 + authController.credentials = credentials;
  18 +
  19 + // calls the authController login method
  20 + authController.login();
  21 +
  22 + // checks if the method login of the injected AuthService has been called
  23 + expect(AuthServiceMock.login).toHaveBeenCalledWith(credentials);
  24 +
  25 + });
  26 +
  27 +});
... ...
src/app/components/auth/index.ts 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +/* Module Index Entry - generated using the script npm run generate-indexes */
  2 +export * from "./auth_controller";
  3 +export * from "./auth_events";
  4 +export * from "./auth_service";
  5 +export * from "./session";
... ...
src/app/components/index.ts 0 → 100644
... ... @@ -0,0 +1 @@
  1 +/* Module Index Entry - generated using the script npm run generate-index */
... ...
src/app/components/navbar/index.ts 0 → 100644
... ... @@ -0,0 +1 @@
  1 +/* Module Index Entry - generated using the script npm run generate-index */
... ...
src/app/components/noosfero-activities/activity/index.ts 0 → 100644
... ... @@ -0,0 +1 @@
  1 +/* Module Index Entry - generated using the script npm run generate-index */
... ...
src/app/components/noosfero-activities/index.ts 0 → 100644
... ... @@ -0,0 +1 @@
  1 +/* Module Index Entry - generated using the script npm run generate-index */
... ...
src/app/components/noosfero-articles/article/article_view.spec.ts
1   -import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
2   -import {Input, provide, Component} from 'ng-forward';
3 1  
  2 +import {Input, provide, Component} from 'ng-forward';
4 3 import {ArticleView, ArticleDefaultView} from './article_view';
5 4  
6   -// Instantiate the Builder, this part is different than ng2.
7   -// In ng2 you inject tcb.
8   -const tcb = new TestComponentBuilder();
  5 +import {createComponentFromClass, quickCreateComponent} from "../../../../spec/helpers.ts";
9 6  
10 7 // this htmlTemplate will be re-used between the container components in this spec file
11 8 const htmlTemplate: string = '<noosfero-article [article]="ctrl.article" [profile]="ctrl.profile"></noosfero-article>';
... ... @@ -30,8 +27,7 @@ describe(&quot;ArticleView Component&quot;, () =&gt; {
30 27 }
31 28 }
32 29  
33   - // uses the TestComponentBuilder instance to initialize the component
34   - tcb.createAsync(ArticleContainerComponent).then((fixture) => {
  30 + createComponentFromClass(ArticleContainerComponent).then((fixture) => {
35 31 // and here we can inspect and run the test assertions
36 32  
37 33 // gets the children component of ArticleContainerComponent
... ... @@ -46,6 +42,7 @@ describe(&quot;ArticleView Component&quot;, () =&gt; {
46 42 // here is write tests in angular 2 ways, this is recommended
47 43 done();
48 44 });
  45 +
49 46 });
50 47  
51 48 it("receives the article and profile as inputs", (done: Function) => {
... ... @@ -61,7 +58,7 @@ describe(&quot;ArticleView Component&quot;, () =&gt; {
61 58 }
62 59  
63 60 // uses the TestComponentBuilder instance to initialize the component
64   - tcb.createAsync(ArticleContainerComponent).then((fixture) => {
  61 + createComponentFromClass(ArticleContainerComponent).then((fixture) => {
65 62 // and here we can inspect and run the test assertions
66 63 let articleView: ArticleView = fixture.debugElement.componentViewChildren[0].componentInstance;
67 64  
... ... @@ -97,7 +94,7 @@ describe(&quot;ArticleView Component&quot;, () =&gt; {
97 94 constructor() {
98 95 }
99 96 }
100   - tcb.createAsync(CustomArticleType).then(fixture => {
  97 + createComponentFromClass(CustomArticleType).then(fixture => {
101 98 let myComponent: CustomArticleType = fixture.componentInstance;
102 99 expect(myComponent.article.type).toEqual("TinyMceArticle");
103 100 expect(fixture.debugElement.componentViewChildren[0].text()).toEqual("TinyMceArticle");
... ...
src/app/components/noosfero-articles/article/index.ts 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +/* Module Index Entry - generated using the script npm run generate-index */
  2 +export * from "./article_view";
... ...
src/app/components/noosfero-articles/blog/index.ts 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +/* Module Index Entry - generated using the script npm run generate-index */
  2 +export * from "./blog.component";
... ...
src/app/components/noosfero-articles/index.ts 0 → 100644
... ... @@ -0,0 +1 @@
  1 +/* Module Index Entry - generated using the script npm run generate-index */
... ...
src/app/components/noosfero-blocks/index.ts 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +/* Module Index Entry - generated using the script npm run generate-index */
  2 +export * from "./block.component";
... ...
src/app/components/noosfero-blocks/link-list/index.ts 0 → 100644
... ... @@ -0,0 +1 @@
  1 +/* Module Index Entry - generated using the script npm run generate-index */
... ...
src/app/components/noosfero-blocks/main-block/index.ts 0 → 100644
... ... @@ -0,0 +1 @@
  1 +/* Module Index Entry - generated using the script npm run generate-index */
... ...
src/app/components/noosfero-blocks/members-block/index.ts 0 → 100644
... ... @@ -0,0 +1 @@
  1 +/* Module Index Entry - generated using the script npm run generate-index */
... ...
src/app/components/noosfero-blocks/profile-image/index.ts 0 → 100644
... ... @@ -0,0 +1 @@
  1 +/* Module Index Entry - generated using the script npm run generate-index */
... ...
src/app/components/noosfero-blocks/recent-documents/index.ts 0 → 100644
... ... @@ -0,0 +1 @@
  1 +/* Module Index Entry - generated using the script npm run generate-index */
... ...
src/app/components/noosfero-boxes/index.ts 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +/* Module Index Entry - generated using the script npm run generate-index */
  2 +export * from "./boxes.component";
... ...
src/app/components/noosfero/index.ts 0 → 100644
... ... @@ -0,0 +1 @@
  1 +/* Module Index Entry - generated using the script npm run generate-index */
... ...
src/app/components/noosfero/profile-image/index.ts 0 → 100644
... ... @@ -0,0 +1 @@
  1 +/* Module Index Entry - generated using the script npm run generate-index */
... ...
src/app/content-viewer/index.ts 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +/* Module Index Entry - generated using the script npm run generate-index */
  2 +export * from "./content-viewer-actions.component";
  3 +export * from "./content-viewer.component";
... ...
src/app/main/index.ts 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +/* Module Index Entry - generated using the script npm run generate-index */
  2 +export * from "./main.component";
... ...
src/app/models/index.ts 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +/* Module Index Entry - generated using the script npm run generate-index */
  2 +export * from "./interfaces";
... ...
src/app/profile-info/index.ts 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +/* Module Index Entry - generated using the script npm run generate-index */
  2 +export * from "./profile-info.component";
... ...
src/app/profile/index.ts 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +/* Module Index Entry - generated using the script npm run generate-index */
  2 +export * from "./profile-home.component";
  3 +export * from "./profile.component";
... ...
src/spec/helpers.ts 0 → 100644
... ... @@ -0,0 +1,31 @@
  1 +
  2 +import {ngClass, TestComponentBuilder, ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder';
  3 +import {quickFixture} from 'ng-forward/cjs/tests/utils';
  4 +import {Input, provide, Component} from 'ng-forward';
  5 +
  6 +
  7 +
  8 +export interface ComponentFixtureTemplate {
  9 + providers?: any[];
  10 + directives?: any[];
  11 + template?: string;
  12 +}
  13 +
  14 +let tcb: TestComponentBuilder = new TestComponentBuilder();
  15 +
  16 +export function quickCreateComponent({
  17 + providers = [],
  18 + directives = [],
  19 + template = '<div></div>'
  20 +}): Promise<ComponentFixture> {
  21 +
  22 + @Component({ selector: 'test', template, directives, providers })
  23 + class Test { }
  24 +
  25 + return tcb.createAsync(Test);
  26 +}
  27 +
  28 +export function createComponentFromClass(yourClass: ngClass) {
  29 + return tcb.createAsync(yourClass);
  30 +}
  31 +
... ...
tsconfig.json
... ... @@ -7,6 +7,7 @@
7 7 "experimentalDecorators": true
8 8 },
9 9 "exclude": [
  10 + "dev-scripts",
10 11 "node_modules",
11 12 "typings/main",
12 13 "typings/main.d.ts",
... ...