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 ADDED
@@ -0,0 +1,2 @@
1
+ [user]
2
+ email = logicfeel@gmail.com
@@ -0,0 +1,155 @@
1
+ {
2
+ // IntelliSense를 사용하여 가능한 특성에 대해 알아보세요.
3
+ // 기존 특성에 대한 설명을 보려면 가리킵니다.
4
+ // 자세한 내용을 보려면 https://go.microsoft.com/fwlink/?linkid=830387을(를) 방문하세요.
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "type": "node",
9
+ "request": "launch",
10
+ "name": "프로그램 시작",
11
+ "program": "${workspaceFolder}/index.js"
12
+ },
13
+ {
14
+ "type": "node",
15
+ "request": "launch",
16
+ "name": "커서-mac",
17
+ "skipFiles": [
18
+ "<node_internals>/**"
19
+ ],
20
+ "program": "${file}"
21
+ },
22
+ {
23
+ "type": "node",
24
+ "request": "launch",
25
+ "name": "t1 build",
26
+ "program": "${workspaceFolder}/task/t1/test_build.js"
27
+ },
28
+ {
29
+ "type": "node",
30
+ "request": "launch",
31
+ "name": "t1 clear",
32
+ "program": "${workspaceFolder}/task/t1/test_clear.js"
33
+ },
34
+ {
35
+ "type": "node",
36
+ "request": "launch",
37
+ "name": "t2 import",
38
+ "program": "${workspaceFolder}/task/t2/test_import.js"
39
+ },
40
+ {
41
+ "type": "node",
42
+ "request": "launch",
43
+ "name": "t2 clear",
44
+ "program": "${workspaceFolder}/task/t2/test_clear.js"
45
+ },
46
+ {
47
+ "type": "node",
48
+ "request": "launch",
49
+ "name": "t3 extends",
50
+ "program": "${workspaceFolder}/task/t3/test_extends.js"
51
+ },
52
+ {
53
+ "type": "node",
54
+ "request": "launch",
55
+ "name": "t3 cover",
56
+ "program": "${workspaceFolder}/task/t3/test_cover.js"
57
+ },
58
+ {
59
+ "type": "node",
60
+ "request": "launch",
61
+ "name": "t3 clear",
62
+ "program": "${workspaceFolder}/task/t3/test_clear.js"
63
+ },
64
+ {
65
+ "type": "node",
66
+ "request": "launch",
67
+ "name": "t4 event",
68
+ "program": "${workspaceFolder}/task/t4/test_event.js"
69
+ },
70
+ {
71
+ "type": "node",
72
+ "request": "launch",
73
+ "name": "t5 page",
74
+ "program": "${workspaceFolder}/task/t5/test_page.js"
75
+ },
76
+ {
77
+ "type": "node",
78
+ "request": "launch",
79
+ "name": "t6 ns/page",
80
+ "program": "${workspaceFolder}/task/t6/test_page.js"
81
+ },
82
+ {
83
+ "type": "node",
84
+ "request": "launch",
85
+ "name": "teaster/all_clear",
86
+ "program": "${workspaceFolder}/tester/all_clear.test.js"
87
+ },
88
+ {
89
+ "type": "node",
90
+ "request": "launch",
91
+ "name": "teaster/all_clear(opt=1)",
92
+ "args": ["1"],
93
+ "program": "${workspaceFolder}/tester/all_clear.test.js"
94
+ },
95
+
96
+ {
97
+ "type": "node",
98
+ "request": "launch",
99
+ "name": "teaster/main",
100
+ "program": "${workspaceFolder}/tester/main.test.js"
101
+ },
102
+ {
103
+ "type": "node",
104
+ "request": "launch",
105
+ "name": "teaster/base",
106
+ "program": "${workspaceFolder}/tester/base.test.js"
107
+ },
108
+ {
109
+ "type": "node",
110
+ "request": "launch",
111
+ "name": "teaster/pageGroup",
112
+ "program": "${workspaceFolder}/tester/pageGroup.test.js"
113
+ },
114
+ {
115
+ "type": "node",
116
+ "request": "launch",
117
+ "name": "teaster/import",
118
+ "program": "${workspaceFolder}/tester/import.test.js"
119
+ },
120
+ {
121
+ "type": "node",
122
+ "request": "launch",
123
+ "name": "teaster/extends",
124
+ "program": "${workspaceFolder}/tester/extends.test.js"
125
+ },
126
+ {
127
+ "type": "node",
128
+ "request": "launch",
129
+ "name": "teaster/j-base",
130
+ "program": "${workspaceFolder}/tester/j-base.test.js"
131
+ },
132
+ {
133
+ "name": "Launch via npm",
134
+ "type": "node",
135
+ "request": "launch",
136
+ "cwd": "${workspaceFolder}",
137
+ "runtimeExecutable": "npm",
138
+ "runtimeArgs": ["test", "__test__/base.test.js"]
139
+ },
140
+ {
141
+ "type": "node",
142
+ "request": "launch",
143
+ "name": "Debug Tests",
144
+ "program": "${workspaceRoot}/node_modules/.bin/jest",
145
+ "cwd": "${workspaceRoot}",
146
+ "args": ["--i", "--config", "__test__/base.test.js"],
147
+ },
148
+ {
149
+ "type": "node",
150
+ "request": "launch",
151
+ "name": "_test_ run",
152
+ "program": "${workspaceFolder}/__test__/base.test.js"
153
+ },
154
+ ]
155
+ }
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # automation
2
+
3
+
4
+ ----------------------------------------
5
+ File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
6
+ -----------------------------------------|---------|----------|---------|---------|--
7
+ All files | 40.58 | 18.7 | 36.36 | 43.27 |
8
+ auto-task.js | 34.75 | 26.08 | 45.45 | 38.21 | 43-49,65,79,96,132-311
9
+ automation.js | 30.59 | 13.49 | 34.61 | 33.99 | 130-136,155-178,202-215,232,282-533,548-550,586,637-730
10
+ depend-resolver.js | 65.71 | 36 | 60 | 67.36 | 36-39,95-146,165,170-173,181-185,302-304,309-327,405-412
11
+ original-path.js | 74.39 | 46.15 | 51.61 | 73.68 | 43-55,89-123,153,159,273-274,327-328
12
+ source-batch.js | 33.93 | 16.72 | 19.35 | 36.64 | ...4-258,294-386,430-431,438-452,458-462,520-524,535-546,557-567,596-610,636-638,643-653,698-699,708,740-748,762-1018
13
+ ----------------------------------------
package/index.js ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * ES6, CJS
3
+ */
4
+ const { Automation } = require('./src/automation');
5
+ const { AutoTask } = require('./src/auto-task');
6
+
7
+
8
+ exports.Automation = Automation;
9
+ exports.AutoTask = AutoTask;
package/jest.config.js ADDED
@@ -0,0 +1,15 @@
1
+ module.exports = {
2
+ //collectCoverageFrom: ['**/*.[jt]s?(x)', '!**/*.stories.[jt]s?(x)'],
3
+ collectCoverageFrom: ['src/*.js', '!src/_*.js'],
4
+
5
+ /*
6
+ coverageThreshold: {
7
+ './src/': {
8
+ statements: 95,
9
+ branches: 90,
10
+ functions: 95,
11
+ lines: 90,
12
+ },
13
+ },
14
+ */
15
+ };
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "logic-auto",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "jest",
8
+ "test:c": "jest --coverage",
9
+ "test:u": "jest --updateSnapshot",
10
+ "test:v": "jest --verbose"
11
+ },
12
+ "author": "logic",
13
+ "license": "ISC",
14
+ "devDependencies": {
15
+ "auto-template": "github:white-base/auto-template",
16
+ "is-binary-path": "^2.1.0",
17
+ "jest": "^29.5.0",
18
+ "white-core": "github:white-base/core"
19
+ }
20
+ }
@@ -0,0 +1,357 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { SourceBatch } = require('./source-batch');
4
+ const { Observer } = require('white-core');
5
+ // const { Observer } = require('entitybind');
6
+
7
+ /**
8
+ * 오토태스크 클래스
9
+ */
10
+ class AutoTask {
11
+ /*_______________________________________*/
12
+ // public
13
+ entry = null;
14
+ batch = null;
15
+ cursor = '';
16
+ FILE = { // location
17
+ RELATION: '__Relation.json',
18
+ };
19
+ // batch = a.SourceBatch.getInstance();
20
+
21
+ /*_______________________________________*/
22
+ // protected
23
+ static _instance = null;
24
+
25
+ /*_______________________________________*/
26
+ // private
27
+ #isLog = false;
28
+ #dir = null;
29
+ #event = new Observer(this, this);
30
+
31
+ /*_______________________________________*/
32
+ // property
33
+ get isLog() { return this.#isLog };
34
+ set isLog(val) {
35
+ if (typeof val !== 'boolean') throw new Error('boolean 타입만 설정할 수 있습니다.');
36
+ this.entry.isLog = val;
37
+ this.#isLog = val;
38
+ };
39
+
40
+ /*_______________________________________*/
41
+ // event property
42
+ set onLoad(fun) {
43
+ this.#event.subscribe(fun, 'load');
44
+ }
45
+ set onSave(fun) {
46
+ this.#event.subscribe(fun, 'save');
47
+ }
48
+ set onSaved(fun) {
49
+ this.#event.subscribe(fun, 'saved');
50
+ }
51
+
52
+ constructor() {
53
+ this.batch = SourceBatch.getInstance();
54
+ this.batch._task = this;
55
+ }
56
+
57
+ /*_______________________________________*/
58
+ // public method
59
+
60
+ /**
61
+ * taask 생성
62
+ */
63
+ static create(dir) {
64
+ if (typeof dir !== 'string' || dir.length === 0) {
65
+ throw new Error(' start [dir] request fail...');
66
+ }
67
+ this._instance = new this();
68
+ this._instance.#dir = dir;
69
+ this._instance._load();
70
+ return this._instance;
71
+ }
72
+
73
+ /**
74
+ * 객체 얻기
75
+ * @returns {this}
76
+ */
77
+ static getInstance() {
78
+ if (this._instance === null) {
79
+ throw new Error(' 태스크가 생성되지 않았습니다. [dir] request fail...');
80
+ }
81
+ return this._instance;
82
+ }
83
+
84
+ /**
85
+ * 상속한 모듈을 복제한다.
86
+ */
87
+ do_clone() {
88
+
89
+ }
90
+
91
+ /**
92
+ * 엔트리 오토만 재배치 한다.
93
+ * 파일 변경 감시수 자동 업데이트에 활용함
94
+ */
95
+ do_update() {
96
+ this.cursor = 'UPDATE';
97
+ }
98
+
99
+ /**
100
+ * 강제로 전체를 오토를 dist 한다.
101
+ */
102
+ do_dist() {
103
+ this.cursor = 'DIST';
104
+
105
+ // 로딩
106
+ this._load();
107
+
108
+ // 대상 오토 조회
109
+ let list = this.entry._getAllList(true);
110
+
111
+ for (let i = 0; i < list.length; i++) {
112
+ list[i].readSource(true, false);
113
+ }
114
+
115
+ // 의존성 로딩 및 설정
116
+ for (let i = 0; i < list.length; i++) {
117
+ list[i].resolver.read();
118
+ list[i].resolver.resolve();
119
+ this.batch.addCollection(list[i].src, this.entry.LOC.DIS, true);
120
+ }
121
+
122
+ // 저장
123
+ this.batch.pathType = 2; // 기본절대경로
124
+ this.batch.save();
125
+ }
126
+
127
+ /**
128
+ * 제외 모듈 : 엔트리모듈, sub모듈, super모듈(상위포함)
129
+ * 처리 모듈 : 제외 모듈의 포함이 안되면서, /dist 폴더가 없는 경우
130
+ */
131
+ do_depend() {
132
+ this.cursor = 'DEPEND';
133
+
134
+ // 로딩
135
+ this._load();
136
+
137
+ /**
138
+ * TODO:: 대상 오토의 1차 의존성의 구조까지 로딩해야함
139
+ * 확인필요 !!
140
+ */
141
+ let all = this.entry._getAllList(); // 엔트리는 제외
142
+ let dep = this.entry._getDependList();
143
+
144
+ /**
145
+ * - 구조만 불러와도 배치는 할 수 있다.
146
+ */
147
+
148
+ // 이부분은 정의 역활을 한다.
149
+ for (let i = 0; i < all.length; i++) {
150
+ all[i].readSource(true, false);
151
+ }
152
+
153
+ // 의존성 로딩 및 설정
154
+ for (let i = 0; i < all.length; i++) {
155
+ all[i].resolver.read();
156
+ all[i].resolver.resolve();
157
+
158
+ // 기타 모듈
159
+ if (dep.indexOf(all[i]) < 0) {
160
+ this.batch.addCollection(all[i].src, this.entry.LOC.DIS);
161
+
162
+ // 의존성 모듈
163
+ } else {
164
+ this.batch.addCollection(all[i].src, this.entry.LOC.DEP);
165
+ }
166
+ }
167
+ // 저장
168
+ // this.batch.isRoot = true; // 절대경로시 entry 폴더 기준
169
+ this.batch.pathType = 1; // 기본상대경로
170
+ // this.batch.pathType = 2; // 기본절대경로
171
+ this.batch.save();
172
+ }
173
+
174
+ /**
175
+ * install 태스크 실행
176
+ */
177
+ do_install() {
178
+ this.cursor = 'INSTALL';
179
+ // 로딩
180
+ this._load();
181
+
182
+ // 대상 오토 조회
183
+ let list = this.entry._getAllList(true);
184
+
185
+ for (let i = 0; i < list.length; i++) {
186
+ list[i].readSource(true, true);
187
+ }
188
+
189
+ // 의존성 로딩 및 설정
190
+ for (let i = 0; i < list.length; i++) {
191
+ list[i].resolver.read();
192
+ list[i].resolver.resolve();
193
+ this.batch.addCollection(list[i].src, this.entry.LOC.INS);
194
+ this.batch.addCollection(list[i].out, this.entry.LOC.INS);
195
+ this.batch.addCollection(list[i].vir, this.entry.LOC.INS);
196
+ }
197
+
198
+ // 저장
199
+ this.batch.isRoot = false; // 절대경로시 'install' 폴더
200
+ // this.batch.pathType = 1; // 전체절대경로
201
+ // this.batch.pathType = 2; // 기본절대경로
202
+ this.batch.save();
203
+ }
204
+
205
+ /**
206
+ * 의존 관계 파일 생성 태스크 실행
207
+ */
208
+ do_relation() {
209
+ this.cursor = 'RELATION';
210
+ // 로딩
211
+ this._load();
212
+
213
+ // 대상 오토 조회
214
+ let list = this.entry._getAllList(true);
215
+
216
+ for (let i = 0; i < list.length; i++) {
217
+ list[i].readSource(true, true);
218
+ }
219
+
220
+ this.entry.isSaveRelation = true;
221
+ // 의존성 로딩 및 설정
222
+ for (let i = 0; i < list.length; i++) {
223
+ list[i].resolver.read();
224
+ list[i].resolver.resolve();
225
+ }
226
+ }
227
+
228
+ /**
229
+ * 상속한 부모의 객체 및 소스(src, out) 가져오기 태스크 실행
230
+ * @param {*} auto
231
+ */
232
+ do_cover(auto = this.entry) {
233
+ this.cursor = 'COVER';
234
+ // 로딩
235
+ this._load();
236
+
237
+ auto.readSource(true, true);
238
+ auto.writeParentObject();
239
+ }
240
+
241
+ /**
242
+ * 오토모듈의 구조를 파일로 저장하는 태스트 실행
243
+ * @param {number} opt 0:전체, 1:요약, 2:세부, 3:대상의존성
244
+ */
245
+ do_map(opt) {
246
+ this.cursor = 'MAP';
247
+ // 로딩
248
+ this._load();
249
+
250
+ // 대상 오토 조회
251
+ let list = this.entry._getAllList(true);
252
+
253
+ for (let i = 0; i < list.length; i++) {
254
+ list[i].readSource(false, false);
255
+ }
256
+
257
+ this.entry.writeObjectMap(opt);
258
+ }
259
+
260
+ /**
261
+ * 오토모듈의 모록을 파일로 저장하는 태스트 실행
262
+ * @param {number} opt 0:전체, 1:요약, 2:세부, 3:이력
263
+ */
264
+ do_list(opt) {
265
+ this.cursor = 'LIST';
266
+ // 로딩
267
+ this._load();
268
+
269
+ // 대상 오토 조회
270
+ let list = this.entry._getAllList(true);
271
+
272
+ for (let i = 0; i < list.length; i++) {
273
+ list[i].readSource(false, false);
274
+ }
275
+
276
+ this.entry.writeObjectList(opt);
277
+ }
278
+
279
+ /**
280
+ * 리셋 태스크 실행 (파일 및 폴더 삭제, 객체 초기화)
281
+ */
282
+ do_reset() {
283
+
284
+ let dir, entry, delPath;
285
+
286
+ this.cursor = 'RESET';
287
+ // 로딩
288
+ this._load();
289
+ // 배치 파일 삭제
290
+ this.batch.clear();
291
+ this.#event.unsubscribeAll();
292
+
293
+ // 디렉토리 삭제
294
+ entry = this.entry;
295
+ dir = entry.dir;
296
+ // dir = __dirname;
297
+
298
+ delPath = dir +path.sep+ entry.LOC.DIS;
299
+ if (fs.existsSync(delPath)) fs.rmSync(delPath, { recursive: true });
300
+ delPath = dir +path.sep+ entry.LOC.DEP;
301
+ if (fs.existsSync(delPath)) fs.rmSync(delPath, { recursive: true });
302
+ delPath = dir +path.sep+ entry.LOC.INS;
303
+ if (fs.existsSync(delPath)) fs.rmSync(delPath, { recursive: true });
304
+ delPath = dir +path.sep+ entry.LOC.PUB;
305
+ if (fs.existsSync(delPath)) fs.rmSync(delPath, { recursive: true });
306
+
307
+ // 대상 오토 조회
308
+ let list = this.entry._getAllList(true);
309
+ for (let i = 0; i < list.length; i++) {
310
+ delPath = list[i].dir +path.sep+ entry.LOC.DIS;
311
+ if (fs.existsSync(delPath)) fs.rmSync(delPath, { recursive: true });
312
+ }
313
+ }
314
+
315
+ /*_______________________________________*/
316
+ // protected method
317
+
318
+ /**
319
+ * 앤트리 오토 조회 및 적재
320
+ */
321
+ _load() {
322
+ if (this.isLog) console.log('_load()....');
323
+
324
+ // 현재 폴더의 auto.js 파일 로딩
325
+ let entryFile = this.#dir + '/auto.js'
326
+ // 다양한 조건에 예외조건을 수용해야함
327
+ const EntryAuto = require(entryFile);
328
+ // 타입 검사해야함
329
+ this.entry = new EntryAuto();
330
+ // 초기화
331
+ this.entry.init();
332
+
333
+ this.batch._batchFile = this.entry._file;
334
+
335
+ // 이벤트 발생
336
+ this._onLoad();
337
+ }
338
+
339
+ /*_______________________________________*/
340
+ // event call
341
+
342
+ // 오토 객체 생성후 호출 이벤트
343
+ _onLoad() {
344
+ this.#event.publish('load', this.cursor, this.entry);
345
+ }
346
+ // 저장전 호출 이벤트
347
+ _onSave() {
348
+ this.#event.publish('save', this.cursor, this.entry);
349
+ }
350
+ // 저장후 호출 이벤트
351
+ _onSaved() {
352
+ this.#event.publish('saved', this.cursor, this.entry);
353
+ }
354
+
355
+ }
356
+
357
+ exports.AutoTask = AutoTask;