UNPKG

6.59 kBMarkdownView Raw
1FinalModules
2============
3
4FinalModules is a gulp task generator class. I uses convention over Configuration.
5
6## So, what's the convention?
7
8The convention is about the code organization and selection of tools for browser development.
9FinalModules generates only gulp tasks for browser code.
10Your code should be written in TypeScript.
11As for now only Stylus is supported.
12
13### Directories
14
15You should create in your public directory a place for your final-modules, let it be `public/final-modules` directory.
16 Then split your project into modules and place each module as a directory in public/final-modules dir.
17 Let's say we will have `core` module and `app` module.:
18
19 public
20 └── final-modules
21 ├── app
22 ── core
23
24Then inside of every module your code should go to `src` directory:
25
26 public/
27 └── final-modules
28 ├── app
29 │   └── src
30 │   ├── application
31 │   │   ├── application.styl
32 │   │   ├── application.html
33 │   │   └── Application.ts
34 │   └── mainMenu
35 │   ├── mainMenu.html
36 │   ├── mainMenu.styl
37 │   └── MainMenu.ts
38 └── core
39 └── src
40 ├── CoreComponent.ts
41 ├── core.styl
42 ├── footer
43 │   ├── footer.html
44 │   ├── footer.styl
45 │   └── Footer.ts
46 ├── header
47 │   ├── header.html
48 │   ├── header.styl
49 │   └── Header.ts
50 └── layout.html
51
52After compilation all compiled module's files will be placed inside of a `build` directory of each module.
53
54### Conventions in TypeScript files
55
56Let's say Application.ts file depends on CoreComponent.ts, we would love to have declarations generated for core module first and then just use one declaration file for all the core module.
57
58FinalModules creates gulp tasks that generates declaration files and puts them inside a build folder of each module, so then inside of the Application.ts we would have this reference:
59
60 ///<reference path="../../core/build/core.d.ts"/>
61
62Another think about TypeScript in FinalModules is usage of amd/commonjs modules. We don't use any of them since the code is separated and concatenated into modules. Your example typescript file should look like this:
63
64 ///<reference path="../../core/build/core.d.ts"/>
65
66 module app {
67
68 export class Application extends core.CoreComponent {
69 constructor() {
70 super();
71 }
72 }
73
74 }
75
76### Conventions in HTML
77
78Every \*.html file in the module's src directory will be placed in moduleName.html.js file as a variable.
79 For example, the content of the application.html file would be inside of a variable: `app.html.application`,
80 content of a footer.html would be inside of a `core.html.footer` variable.
81
82### Stylus
83
84Every \*.styl file found in the module's src directory will be compiled with stylus (with nib plugin available) and merged into moduleName.css file with the coresponding map file.
85
86### Watching TypeScript
87
88The `fm:*:watch:ts` tasks watch only the files of a particular module but when the change occures they run a compilation of every module that is dependent upon the changed module. FinalModules resolve dependencies using [dependency-resolver](https://www.npmjs.org/package/dependency-resolver "dependency-resolver") node package.
89
90## Usage
91
92First, install the plugin using npm:
93
94 npm install final-modules --save-dev
95
96inside your `gulpfile.js`:
97
98 var gulp = require('gulp');
99 var FinalModules = require('final-modules');
100
101 var mods = new FinalModules('public/src');
102 mods.add('core');
103 mods.add('app', ['core']);
104 mods.generateTasks(gulp);
105
106This code will generate the following gulp tasks:
107
108- for core module: `fm:core`, `fm:core:clean`, `fm:core:html`, `fm:core:ts`, `fm:core:ts:standalone`, `fm:core:min`, `fm:core:styl`, `fm:core:watch`, `fm:core:watch:ts`, `fm:core:watch:styl`, `fm:core:watch:html`
109- for app module: `fm:app`, `fm:app:clean`, `fm:app:html`, `fm:app:ts`, `fm:app:min`, `fm:app:styl`, `fm:app:watch`, `fm:app:watch:ts`, `fm:app:watch:styl`, `fm:app:watch:html`
110- for all the modules: `fm`, `fm:clean`, `fm:html`, `fm:ts`, `fm:min`, `fm:styl`, `fm:watch`, `fm:watch:ts`, `fm:watch:styl`, `fm:watch:html`
111
112After that you can add a default task that will run all the generated tasks with this statement:
113
114 gulp.task('default', ['fm']);
115
116## Compilation
117
118To compile all the final-modules use gulp inside your projects:
119
120 gulp fm
121
122This will generate `build` directories inside of each module. In our example it looks like that:
123
124 public/
125 └── src
126 ├── app
127 │   ├── build
128 │   │   ├── app.d.ts
129 │   │   ├── app.html.js
130 │   │   ├── app.js
131 │   │   ├── app.js.map
132 │   │   ├── app.min.js
133 │   │   └── app.min.js.map
134 │   └── src
135 │   ├── application
136 │   │   ├── application.html
137 │   │   ├── application.styl
138 │   │   └── Application.ts
139 │   └── mainMenu
140 │   ├── mainMenu.html
141 │   ├── mainMenu.styl
142 │   └── MainMenu.ts
143 └── core
144 ├── build
145 │   ├── core.d.ts
146 │   ├── core.html.js
147 │   ├── core.js
148 │   ├── core.js.map
149 │   ├── core.min.js
150 │   └── core.min.js.map
151 └── src
152 ├── CoreComponent.ts
153 ├── core.styl
154 ├── footer
155 │   ├── footer.html
156 │   ├── footer.styl
157 │   └── Footer.ts
158 ├── header
159 │   ├── header.html
160 │   ├── header.styl
161 │   └── Header.ts
162 └── layout.html
163
164## License: ISC
165
166ISC is even simpler **MIT** like license. See `LICENSE` file.