-
Notifications
You must be signed in to change notification settings - Fork 0
/
mantra.yaml
378 lines (344 loc) · 9.67 KB
/
mantra.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
root: '.'
panes:
- name: Module
structure:
- directory: actions
structure:
- file: index.ts
template: actionIndex
- directory: components
structure:
- file: stories/index.ts
template: storiesIndex
- directory: containers
- file: routes.tsx
template: route
- file: index.ts
template: module
- name: Server
structure:
- directory: server/publications
structure:
- file: index.ts
template: publicationIndex
- directory: server/methods
structure:
- file: index.ts
template: methodIndex
- file: server/index.ts
template: server
- name: Configs
structure:
- directory: client/configs
- directory: lib
- directory: public
- file: client/configs/context.ts
template: context
- file: client/index.ts
template: client
templates:
# Module action template
- name: actions
text: |
class Actions {
create({Meteor, LocalState}, myParam) {
},
};
let actions = new Actions();
export default actions;
placeholders:
actions:
- type: replace
path: index.ts
what: const actions = {
replace: import $name from "./$name";\nconst actions = {
- type: replace
path: index.ts
what: const actions = {
replace: const actions = {\n $name,
- type: create
path: tests/$name_test.ts
text: |
const {describe, it} = global;
import {expect} from 'chai';
import {spy, stub} from 'sinon';
import actions from '../posts';
describe('module.actions.actionSet', () => {
describe('create', () => {
it('should reject if title is not there', () => {
const LocalState = {set: spy()};
actions.create({LocalState}, null, 'content');
const args = LocalState.set.args[0];
expect(args[0]).to.be.equal('SAVING_ERROR');
expect(args[1]).to.match(/required/);
});
});
});
- name: actionIndex
create: true
text: |
const actions = {
// ACTION
};
export default actions;
# Module component template
- name: storiesIndex
create: true
text: |
// imports
- name: components
text: |
import React from "react";
interface IProps {
}
export default class $1 extends React.Component {
render() {
return (
<div></div>
);
}
}
placeholders:
- Component Name
actions:
- type: create
path: tests/$name_test.ts
text: |
const {describe, it} = global;
import {expect} from 'chai';
import {shallow} from 'enzyme';
import Component from '../$name';
describe('test', () => {
it('should display the post title', () => {
const el = shallow(<Component />);
expect(el).not.to.be.null;
});
});
- type: create
path: stories/$name_stories.ts
text: |
import React from 'react';
import { storiesOf, action } from '@kadira/storybook';
import Component from '../$name';
storiesOf('module.$name', module)
.add('default view', () => {
return (
<Component />
);
})
- type: replace
path: stories/index.ts
what: // imports
replace: |
// imports
import $name from "./$name_stories";
# Module container template
- name: containers
text: |
import { useDeps, composeWithTracker, composeAll } from "../../../configs/context";
import Component from "../components/$1";
interface IProps {
context?: () => IContext;
clearErrors: Function;
}
export const composer = ({context, clearErrors}, onData) => {
const { Meteor, Collections } = context();
if (Meteor.subscribe("$3", postId).ready()) {
const options = {
sort: {createdAt: -1}
};
const data = {Collections.$2.find({$2}, options).fetch()};
onData(null, {data});
} else {
onData();
}
return clearErrors;
};
export const depsMapper = (context, actions) => ({
create: actions.schedule.create,
handleSearch: actions.schedule.handleSearch,
context: () => context
});
export default composeAll(
composeWithTracker(composer),
useDeps(depsMapper)
)(Component);
placeholders:
- Component Name
- Collection Name
- Subscription
actions:
- type: create
path: tests/$name_test.ts
text: |
const { describe, it } = global;
import {expect} from 'chai';
import {spy, stub} from 'sinon';
import {composer, depsMapper} from '../newpost';
describe('component', () => {
describe('composer', () => {
it('should get SAVING_ERROR from local state', () => {
const LocalState = {get: spy()};
const context = () => ({LocalState});
composer({context}, spy());
const args = LocalState.get.args[0];
expect(args).to.have.length(1);
expect(args[0]).to.be.equal('SAVING_ERROR');
});
});
});
# Module route template
- name: route
show: true
create: true
text: |
import React from "react";
import { mount } from "mantra-core";
export default function (injectDeps) {
//const MainLayoutCtx = injectDeps(MainLayout);
// Move these as a module and call this from a main file
// FlowRouter.route("/", {
// name: "ei.list",
// action() {
// mount(MainLayoutCtx, {
// content: () => (<EiList />)
// });
// }
// });
}
# Module index template
- name: module
show: true
create: true
text: |
import actions from "./actions";
import routes from "./routes";
export default {
actions,
routes
};
# Server publication template
- name: server/publications
text: |
import {Meteor} from 'meteor/meteor';
import {check} from 'meteor/check';
export default function () {
Meteor.publish("$1", function () {
const selector = {};
const options = {
// fields: {_id: 1, title: 1},
// sort: {createdAt: -1},
// limit: 10
};
return $2.find(selector, options);
});
}
placeholders:
- Publication Name
- Collection
actions:
- type: replace
path: index.ts
what: export default function () {
replace: |
import $name from "./$name";
export default function () {
- type: replace
path: index.ts
what: export default function () {
replace: |
export default function () {
$name();
# Method template
- name: server/methods
text: |
import {Meteor} from 'meteor/meteor';
import {check} from 'meteor/check';
export default function () {
Meteor.methods({
'$1'($2) {
check($2, String);
}
});
}
placeholders:
- Method Name
- Parameters
actions:
- type: replace
path: index.ts
what: export default function () {
replace: >
import $name from "./$name";
export default function () {
- type: replace
path: index.ts
what: export default function () {
replace: >
export default function () {
$name();
- name: server
create: true
show: true
text: |
import publications from "./publications/index";
import methods from "./methods/index";
// import addInitialData from "./configs/initial_adds";
publications();
methods();
// addInitialData();
- name: publicationIndex
create: true
text: |
export default function () {
}
- name: methodIndex
create: true
text: |
export default function () {
}
# context template
- name: context
create: true
text: |
import * as Collections from "../../lib/collections";
import {Meteor} from 'meteor/meteor';
import {FlowRouter} from 'meteor/kadira:flow-router';
import {ReactiveDict} from 'meteor/reactive-dict';
import {Tracker} from 'meteor/tracker';
export default function () {
return {
Meteor,
FlowRouter,
Collections,
LocalState: new ReactiveDict(),
};
}
# client index template
- name: client
create: true
show: true
text: |
import "./configs/config";
import {createApp} from 'mantra-core';
import coreModule from "./modules/core/index";
import initContext from "./configs/context";
// init context
const context = initContext();
// create app
const app = createApp(context);
app.loadModule(coreModule);
app.init();
actions:
- type: replace
path: ../index.ts
what: import {createApp} from 'mantra-core';
replace: |
import {createApp} from 'mantra-core';
import $nameModule from "./modules/$name";
- type: replace
path: ../index.ts
what: app.init();
replace: |
app.loadModule($nameModule);
app.init()