-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReactReduxEnvironment.js
143 lines (136 loc) · 4.37 KB
/
ReactReduxEnvironment.js
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
const path = require('path');
const _ = require('lodash');
const types = require('babel-types');
class DummyBaseClass {}
const filePathArray = path => path.split('/').filter(s => /[a-zA-z]+/g.test(s));
const filePathToObjectNotation = path => filePathArray(path).join('.');
const filePathToObjectNotationAst = path => {
let array = filePathArray(path);
return array.reduce(
(acc, next) => types.memberExpression(acc, types.identifier(next)),
types.memberExpression(
types.identifier(array.shift()),
types.identifier(array.shift())
)
);
};
module.exports = (BaseClass = DummyBaseClass) =>
class extends BaseClass {
constructor(args, ...rest) {
super(args, ...rest);
this.props = {};
if (_.isString(args)) {
this.props.name = args;
this.props.path = '';
} else if (_.isArray(args) && args.length) {
this.props.name = args[0];
this.props.path = args[1];
}
}
get _resolvedPath() {
return path.join(this.props.path, this.props.name);
}
get _resolvedPathExcludingIndex() {
return path.join(
this.props.path,
this.props.name === 'index' ? '' : this.props.name
);
}
get _jsEntryPath() {
return path.join('src', this._resolvedPath);
}
get _jsEntryFilePath() {
return './' + this._jsEntryPath + '.js';
}
get _actionsPath() {
return path.join('actions', this._resolvedPath);
}
get _actionsFilePath() {
return path.join('src', this._actionsPath) + '.js';
}
get _rootReducerPath() {
return path.join('reducers', this._resolvedPath);
}
get _rootReducerFilePath() {
return path.join('src', this._rootReducerPath) + '.js';
}
get _entitiesReducerPath() {
return path.join('reducers', this._resolvedPath, 'entities');
}
get _entitiesReducerFilePath() {
return path.join('src', this._entitiesReducerPath) + '.js';
}
get _storePath() {
return path.join('stores', this._resolvedPath);
}
get _storeFilePath() {
return path.join('src', this._storePath) + '.js';
}
get _sectionsReducerPath() {
return this._reducerPath('sections');
}
get _sectionsReducerFilePath() {
return path.join('src', this._sectionsReducerPath) + '.js';
}
get _defaultSectionReducerPath() {
return this._sectionReducersPath();
}
get _defaultSectionReducerFilePath() {
return path.join('src', this._defaultSectionReducerPath, 'index.js');
}
get _defaultContainerPath() {
return this._containersPath();
}
get _defaultContainerFilePath() {
return path.join('src', this._defaultContainerPath, 'index.js');
}
_pathToReducerObjectNotation(base = '') {
return filePathToObjectNotation(
path.join('state', base, this._resolvedPathExcludingIndex)
);
}
_pathToReducerObjectNotationAst(base = '') {
return filePathToObjectNotationAst(
path.join('state', base, this._resolvedPathExcludingIndex)
);
}
_resolvePath(toJoin = '') {
return path.join(this._resolvedPath, toJoin);
}
_reducerPath(toJoin) {
return path.join('reducers', this._resolvePath(toJoin));
}
_reducerFilePath(toJoin) {
return path.join('src', this._reducerPath(toJoin)) + '.js';
}
_sectionReducersPath(toJoin = '') {
return path.join('reducers', this.props.path, this.props.name, 'sections', toJoin);
}
_sectionReducersDirectoryPath(toJoin) {
return path.join('src', this._sectionReducersPath(toJoin));
}
_sectionReducersFilePath(toJoin) {
return this._sectionReducersDirectoryPath(toJoin) + '.js';
}
_componentsPath(toJoin) {
return path.join('components', this._resolvePath(toJoin));
}
_componentsDirectoryPath(toJoin) {
return path.join('src', this._componentsPath(toJoin));
}
_componentsFilePath(toJoin) {
return this._componentsDirectoryPath(toJoin) + '.js';
}
_containersPath(toJoin) {
return path.join('containers', this._resolvePath(toJoin));
}
_containersDirectoryPath(toJoin) {
return path.join('src', this._containersPath(toJoin));
}
_containersFilePath(toJoin) {
return path.join('src', this._containersPath(toJoin)) + '.js';
}
forceConfiguration(options, prompts) {
this.props = Object.assign({}, this.props, options, prompts);
}
};