logic-auto 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitconfig +2 -0
- package/.vscode/launch.json +155 -0
- package/README.md +13 -0
- package/index.js +9 -0
- package/jest.config.js +15 -0
- package/package.json +20 -0
- package/src/auto-task.js +357 -0
- package/src/automation.js +762 -0
- package/src/depend-resolver.js +471 -0
- package/src/original-path.js +337 -0
- package/src/source-batch.js +1027 -0
- package/test/base/mod1/__SaveFile.json +8 -0
- package/test/base/mod1/auto.js +12 -0
- package/test/base/mod1/dist/100.webp +0 -0
- package/test/base/mod1/dist/102-3.webp +0 -0
- package/test/base/mod1/dist/board.css +6 -0
- package/test/base/mod1/dist/board_m.css +6 -0
- package/test/base/mod1/dist/m3.html +16 -0
- package/test/base/mod1/out/bar.css +7 -0
- package/test/base/mod1/package.json +11 -0
- package/test/base/mod1/src/100.webp +0 -0
- package/test/base/mod1/src/102-3.webp +0 -0
- package/test/base/mod1/src/board.css +6 -0
- package/test/base/mod1/src/board_m.css +6 -0
- package/test/base/mod1/src/m3.html +16 -0
- package/test/base.test.js +19 -0
- package/test/index.test.js +33 -0
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const isBinaryPath = require('is-binary-path');
|
|
4
|
+
const { MetaElement, PropertyCollection, MetaObject } = require('white-core');
|
|
5
|
+
// const { MetaElement, PropertyCollection, MetaObject } = require('entitybind');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 의존성 파일시스템
|
|
9
|
+
*/
|
|
10
|
+
class OriginalPath {
|
|
11
|
+
|
|
12
|
+
/*_______________________________________*/
|
|
13
|
+
//public
|
|
14
|
+
// location = null;
|
|
15
|
+
// fullPath = '';
|
|
16
|
+
/**
|
|
17
|
+
* null : 이름변경 O, 내용변경 O
|
|
18
|
+
* true : 이름변경 X, 내용변경 X
|
|
19
|
+
* false : 이름변경 X, 내용변경 O
|
|
20
|
+
*/
|
|
21
|
+
isStatic = null;
|
|
22
|
+
comment = ''; // 파일 설명
|
|
23
|
+
|
|
24
|
+
/*_______________________________________*/
|
|
25
|
+
// protected
|
|
26
|
+
_auto = null;
|
|
27
|
+
_target = null;
|
|
28
|
+
|
|
29
|
+
/*_______________________________________*/
|
|
30
|
+
// private
|
|
31
|
+
#location = null;
|
|
32
|
+
#dir = null;
|
|
33
|
+
|
|
34
|
+
/*_______________________________________*/
|
|
35
|
+
// property
|
|
36
|
+
get location() {
|
|
37
|
+
return this.#location;
|
|
38
|
+
}
|
|
39
|
+
get dir() {
|
|
40
|
+
return this.#dir;
|
|
41
|
+
}
|
|
42
|
+
get name() {
|
|
43
|
+
throw new Error(' name 프로퍼티를 정의해야 합니다.');
|
|
44
|
+
}
|
|
45
|
+
get subDir() {
|
|
46
|
+
throw new Error(' subDir 프로퍼티를 정의해야 합니다.');
|
|
47
|
+
}
|
|
48
|
+
get subPath() {
|
|
49
|
+
throw new Error(' subPath 프로퍼티를 정의해야 합니다.');
|
|
50
|
+
}
|
|
51
|
+
get localDir() {
|
|
52
|
+
throw new Error(' localDir 프로퍼티를 정의해야 합니다.');
|
|
53
|
+
}
|
|
54
|
+
get localPath() {
|
|
55
|
+
throw new Error(' localPath 프로퍼티를 정의해야 합니다.');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 생성자
|
|
60
|
+
* @param {*} auto
|
|
61
|
+
* @param {*} location
|
|
62
|
+
* @param {*} dir
|
|
63
|
+
*/
|
|
64
|
+
constructor(auto, location, dir) {
|
|
65
|
+
this._auto = auto;
|
|
66
|
+
this.#location = location;
|
|
67
|
+
this.#dir = dir;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/*_______________________________________*/
|
|
71
|
+
// protected method
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 타겟 설정
|
|
75
|
+
* @param {*} tar
|
|
76
|
+
*/
|
|
77
|
+
_setTarget(tar) {
|
|
78
|
+
this._target = tar;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 가상폴더 클래스
|
|
84
|
+
*/
|
|
85
|
+
class VirtualFolder extends OriginalPath {
|
|
86
|
+
|
|
87
|
+
/*_______________________________________*/
|
|
88
|
+
// private
|
|
89
|
+
#fullPath = null;
|
|
90
|
+
|
|
91
|
+
/*_______________________________________*/
|
|
92
|
+
// property
|
|
93
|
+
get fullPath() {
|
|
94
|
+
return this.#fullPath;
|
|
95
|
+
}
|
|
96
|
+
get name() {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
get subDir() {
|
|
100
|
+
return this.fullPath;
|
|
101
|
+
}
|
|
102
|
+
get subPath() {
|
|
103
|
+
return this.fullPath;
|
|
104
|
+
}
|
|
105
|
+
get localDir() {
|
|
106
|
+
return this.fullPath;
|
|
107
|
+
}
|
|
108
|
+
get localPath() {
|
|
109
|
+
return this.fullPath;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* VirtualFolder 생성자
|
|
114
|
+
* @extends OriginalPath
|
|
115
|
+
* @param {*} auto 소유하는 auto
|
|
116
|
+
* @param {*} localPath
|
|
117
|
+
* @param {*} dir
|
|
118
|
+
*/
|
|
119
|
+
constructor(auto, localPath, dir) {
|
|
120
|
+
super(auto, 'vir', dir);
|
|
121
|
+
|
|
122
|
+
// 필수 검사 필요!!
|
|
123
|
+
this.#fullPath = localPath;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* 비텍스트파일 클래스
|
|
130
|
+
*/
|
|
131
|
+
class NonTextFile extends OriginalPath {
|
|
132
|
+
|
|
133
|
+
/*_______________________________________*/
|
|
134
|
+
// public
|
|
135
|
+
|
|
136
|
+
/*_______________________________________*/
|
|
137
|
+
// protected
|
|
138
|
+
_dep = [];
|
|
139
|
+
|
|
140
|
+
/*_______________________________________*/
|
|
141
|
+
// private
|
|
142
|
+
#fullPath = null;
|
|
143
|
+
|
|
144
|
+
/*_______________________________________*/
|
|
145
|
+
// property
|
|
146
|
+
get fullPath() {
|
|
147
|
+
return this.#fullPath;
|
|
148
|
+
}
|
|
149
|
+
get name() {
|
|
150
|
+
return path.basename(this.fullPath);
|
|
151
|
+
}
|
|
152
|
+
get subDir() {
|
|
153
|
+
return path.dirname(this.subPath);
|
|
154
|
+
}
|
|
155
|
+
get subPath() {
|
|
156
|
+
return path.relative(this.dir + path.sep + this.location, this.fullPath);
|
|
157
|
+
}
|
|
158
|
+
get localDir() {
|
|
159
|
+
return path.dirname(this.localPath);
|
|
160
|
+
}
|
|
161
|
+
get localPath() {
|
|
162
|
+
return path.relative(this.dir, this.fullPath);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* 생성자
|
|
167
|
+
* @extends OriginalPath
|
|
168
|
+
* @param {*} auto
|
|
169
|
+
* @param {*} fullPath
|
|
170
|
+
* @param {*} location
|
|
171
|
+
* @param {*} dir
|
|
172
|
+
*/
|
|
173
|
+
constructor(auto, fullPath, location, dir) {
|
|
174
|
+
super(auto, location, dir);
|
|
175
|
+
|
|
176
|
+
this.#fullPath = fullPath;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/*_______________________________________*/
|
|
180
|
+
// public method
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* 참조객체 등록
|
|
184
|
+
* @param {*} src 참조 대상 원본소스
|
|
185
|
+
* @param {*} list 참조 위치 객체
|
|
186
|
+
*/
|
|
187
|
+
addDepend(ref, pos) {
|
|
188
|
+
this._dep.push({
|
|
189
|
+
ref: ref,
|
|
190
|
+
pos: pos
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* 텍스트파일 클래스
|
|
197
|
+
*/
|
|
198
|
+
class TextFile extends NonTextFile {
|
|
199
|
+
|
|
200
|
+
/*_______________________________________*/
|
|
201
|
+
// public
|
|
202
|
+
data = null;
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* 생성자
|
|
206
|
+
* @extends NonTextFile
|
|
207
|
+
* @param {*} auto
|
|
208
|
+
* @param {*} fullPath
|
|
209
|
+
* @param {*} location
|
|
210
|
+
* @param {*} dir
|
|
211
|
+
*/
|
|
212
|
+
constructor(auto, fullPath, location, dir) {
|
|
213
|
+
super(auto, fullPath, location, dir);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* 메타 컬렉션
|
|
219
|
+
*/
|
|
220
|
+
class FileCollection extends PropertyCollection {
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* 생성자
|
|
224
|
+
* @class
|
|
225
|
+
* @extends PropertyCollection
|
|
226
|
+
* @param {*} owner
|
|
227
|
+
*/
|
|
228
|
+
constructor(owner) {
|
|
229
|
+
super(owner);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/*_______________________________________*/
|
|
233
|
+
// public method
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* 지정위치의 파일들 추가 (src, out)
|
|
237
|
+
* @param {*} location
|
|
238
|
+
* @param {*} opt
|
|
239
|
+
*/
|
|
240
|
+
addLocation(location, opt) {
|
|
241
|
+
|
|
242
|
+
const _this = this;
|
|
243
|
+
const sep = path.sep;
|
|
244
|
+
const dirs = this._onwer.dirs;
|
|
245
|
+
let dir = '', bDir = '';
|
|
246
|
+
|
|
247
|
+
// 내부 함수
|
|
248
|
+
function _addPath(path, dir = '', baseDir) {
|
|
249
|
+
|
|
250
|
+
let arr, file, alias, idx;
|
|
251
|
+
|
|
252
|
+
arr = fs.readdirSync(path);
|
|
253
|
+
|
|
254
|
+
for (let i = 0; i < arr.length; i++) {
|
|
255
|
+
|
|
256
|
+
// REVIEW:: 비동기 성능이슈 있음
|
|
257
|
+
|
|
258
|
+
// 대상 파일의 필터 TODO::
|
|
259
|
+
// TODO: 템플릿 파일은 제외해야야함
|
|
260
|
+
if (fs.statSync(path +'/'+ arr[i]).isFile()) {
|
|
261
|
+
// 컬렉션에 등록
|
|
262
|
+
alias = dir === '' ? arr[i] : dir + sep + arr[i];
|
|
263
|
+
if (isBinaryPath(path +'/'+ arr[i])) {
|
|
264
|
+
file = new NonTextFile(_this._onwer, path + sep + arr[i], location, baseDir);
|
|
265
|
+
} else {
|
|
266
|
+
file = new TextFile(_this._onwer, path + sep + arr[i], location, baseDir);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
idx = _this.indexOfName(alias); // 중복이름 검사
|
|
270
|
+
if (idx > -1) _this[idx] = file; // 내용 교체
|
|
271
|
+
else _this.add(alias, file);
|
|
272
|
+
|
|
273
|
+
} else if (fs.statSync(path + sep + arr[i]).isDirectory()) {
|
|
274
|
+
_addPath(path + sep + arr[i], dir, baseDir);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
for (let i = 0; i < dirs.length; i++) {
|
|
280
|
+
dir = dirs[i] + path.sep + location;
|
|
281
|
+
bDir = dirs[i];
|
|
282
|
+
if (fs.existsSync(dir)) _addPath(dir, '', bDir);
|
|
283
|
+
}
|
|
284
|
+
// 폴더가 있는경우만
|
|
285
|
+
// if (fs.existsSync(dir)) _addPath(dir);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* 파일 data 채우기
|
|
291
|
+
*/
|
|
292
|
+
fillData() {
|
|
293
|
+
|
|
294
|
+
let filePath;
|
|
295
|
+
|
|
296
|
+
for (let i = 0; i < this.list.length; i++) {
|
|
297
|
+
filePath = this.list[i].fullPath;
|
|
298
|
+
this.list[i].data = fs.readFileSync(filePath,'utf-8');
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* 메타컬렉션 클래스
|
|
305
|
+
*/
|
|
306
|
+
class FolderCollection extends PropertyCollection {
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* 생성자
|
|
310
|
+
* @param {*} owner
|
|
311
|
+
*/
|
|
312
|
+
constructor(owner) {
|
|
313
|
+
super(owner);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/*_______________________________________*/
|
|
317
|
+
// public method
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* 가상폴더 추가
|
|
321
|
+
* @param {string} vFolder
|
|
322
|
+
*/
|
|
323
|
+
add(vFolder) {
|
|
324
|
+
|
|
325
|
+
let obj;
|
|
326
|
+
|
|
327
|
+
obj = new VirtualFolder(this._onwer, vFolder, this._onwer.dir);
|
|
328
|
+
super.add(vFolder, obj);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
exports.OriginalPath = OriginalPath;
|
|
333
|
+
exports.VirtualFolder = VirtualFolder;
|
|
334
|
+
exports.NonTextFile = NonTextFile;
|
|
335
|
+
exports.TextFile = TextFile;
|
|
336
|
+
exports.FileCollection = FileCollection;
|
|
337
|
+
exports.FolderCollection = FolderCollection;
|