Skip to content
This repository was archived by the owner on Nov 21, 2024. It is now read-only.

Commit d7d70a9

Browse files
committed
fix(refactor): Change attributes to one attribute as options object
1 parent 9ccbb26 commit d7d70a9

9 files changed

Lines changed: 77 additions & 64 deletions

File tree

src/lib/apps.ts

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,99 +8,126 @@ export class Apps extends Base {
88
constructor(public folders: string[], public rootFolder: string) {
99
super('', rootFolder);
1010
}
11-
async clear(customOptions: { package: any, packages?: any[], folder: string }) {
11+
async clear(customOptions?: { package?: any, packages?: any[], folder?: string }) {
1212
const results = [];
1313
for (let i = 0; i < this.folders.length; i++) {
1414
const app = new App(this.folders[i], this.rootFolder);
1515
app.debug = this.debug;
16+
if (!customOptions) {
17+
customOptions = {};
18+
}
1619
customOptions.package = customOptions.packages ? customOptions.packages[i] : null;
1720
results.push(await app.clear(customOptions));
1821
}
1922
return results.reduce((all: boolean, current: boolean) => { return all && current; }, true);
2023
}
21-
async build(customOptions: { package: any, packages?: any[], folder: string, srcFolder: string }) {
24+
async build(customOptions?: { package?: any, packages?: any[], folder?: string, srcFolder?: string }) {
2225
const results = [];
2326
for (let i = 0; i < this.folders.length; i++) {
2427
const app = new App(this.folders[i], this.rootFolder);
2528
app.debug = this.debug;
29+
if (!customOptions) {
30+
customOptions = {};
31+
}
2632
customOptions.package = customOptions.packages ? customOptions.packages[i] : null;
2733
results.push(await app.build(customOptions));
2834
}
2935
return results.reduce((all: boolean, current: boolean) => { return all && current; }, true);
3036
}
31-
async link(customOptions: { package: any, packages?: any[], folder: string, srcFolder: string }) {
37+
async link(customOptions?: { package?: any, packages?: any[], folder?: string, srcFolder?: string }) {
3238
const results = [];
3339
for (let i = 0; i < this.folders.length; i++) {
3440
const app = new App(this.folders[i], this.rootFolder);
3541
app.debug = this.debug;
42+
if (!customOptions) {
43+
customOptions = {};
44+
}
3645
customOptions.package = customOptions.packages ? customOptions.packages[i] : null;
3746
results.push(await app.link(customOptions));
3847
}
3948
return results.reduce((all: boolean, current: boolean) => { return all && current; }, true);
4049
}
41-
async linkNpm(customOptions: { package: any, packages?: any[], folder: string, srcFolder: string }) {
50+
async linkNpm(customOptions?: { package?: any, packages?: any[], folder?: string, srcFolder?: string }) {
4251
const results = [];
4352
for (let i = 0; i < this.folders.length; i++) {
4453
const app = new App(this.folders[i], this.rootFolder);
4554
app.debug = this.debug;
55+
if (!customOptions) {
56+
customOptions = {};
57+
}
4658
customOptions.package = customOptions.packages ? customOptions.packages[i] : null;
4759
results.push(await app.linkNpm(customOptions));
4860
}
4961
return results.reduce((all: boolean, current: boolean) => { return all && current; }, true);
5062
}
51-
async changeVersion(customOptions: { package: any, packages?: any[], rootPackagePath: string, srcPackagePath: string }) {
63+
async changeVersion(customOptions?: { package?: any, packages?: any[], rootPackagePath?: string, srcPackagePath?: string }) {
5264
const results = [];
5365
for (let i = 0; i < this.folders.length; i++) {
5466
const app = new App(this.folders[i], this.rootFolder);
5567
app.debug = this.debug;
68+
if (!customOptions) {
69+
customOptions = {};
70+
}
5671
customOptions.package = customOptions.packages ? customOptions.packages[i] : null;
5772
results.push(await app.changeVersion(customOptions));
5873
}
5974
return results.reduce((all: boolean, current: boolean) => { return all && current; }, true);
6075
}
61-
async extractTranslate(customOptions: { package: any, packages?: any[], srcFolder: string }) {
76+
async extractTranslate(customOptions?: { package?: any, packages?: any[], srcFolder?: string }) {
6277
const results = [];
6378
for (let i = 0; i < this.folders.length; i++) {
6479
const app = new App(this.folders[i], this.rootFolder);
6580
app.debug = this.debug;
81+
if (!customOptions) {
82+
customOptions = {};
83+
}
6684
customOptions.package = customOptions.packages ? customOptions.packages[i] : null;
6785
results.push(await app.extractTranslate(customOptions));
6886
}
6987
return results.reduce((all: boolean, current: boolean) => { return all && current; }, true);
7088
}
71-
async po2ts(customOptions: { package: any, packages?: any[], i18nFolder: string }) {
89+
async po2ts(customOptions?: { package?: any, packages?: any[], i18nFolder?: string }) {
7290
const results = [];
7391
for (let i = 0; i < this.folders.length; i++) {
7492
const app = new App(this.folders[i], this.rootFolder);
7593
app.debug = this.debug;
94+
if (!customOptions) {
95+
customOptions = {};
96+
}
7697
customOptions.package = customOptions.packages ? customOptions.packages[i] : null;
7798
results.push(await app.po2ts(customOptions));
7899
}
79100
return results.reduce((all: boolean, current: boolean) => { return all && current; }, true);
80101
}
81-
async prepare(customOptions: {
82-
package: any,
102+
async prepare(customOptions?: {
103+
package?: any,
83104
packages?: any[],
84-
i18nFolder: string,
85-
srcFolder: string,
86-
listComponentsPostfix: string
87-
rootPackagePath: string,
88-
srcPackagePath: string
105+
i18nFolder?: string,
106+
srcFolder?: string,
107+
listComponentsPostfix?: string
108+
rootPackagePath?: string,
109+
srcPackagePath?: string
89110
}) {
90111
const results = [];
91112
for (let i = 0; i < this.folders.length; i++) {
92113
const app = new App(this.folders[i], this.rootFolder);
93114
app.debug = this.debug;
115+
if (!customOptions) {
116+
customOptions = {};
117+
}
94118
customOptions.package = customOptions.packages ? customOptions.packages[i] : null;
95119
results.push(await app.prepare(customOptions));
96120
}
97121
return results.reduce((all: boolean, current: boolean) => { return all && current; }, true);
98122
}
99-
async makeTsList(customOptions: { package: any, packages?: any[], listComponentsPostfix: string, srcFolder: string }) {
123+
async makeTsList(customOptions?: { package?: any, packages?: any[], listComponentsPostfix?: string, srcFolder?: string }) {
100124
const results = [];
101125
for (let i = 0; i < this.folders.length; i++) {
102126
const app = new App(this.folders[i], this.rootFolder);
103127
app.debug = this.debug;
128+
if (!customOptions) {
129+
customOptions = {};
130+
}
104131
customOptions.package = customOptions.packages ? customOptions.packages[i] : null;
105132
results.push(await app.makeTsList(customOptions));
106133
}

src/lib/base.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ export class Base {
3232
this.log().setLevel('info');
3333
}
3434
}
35-
timeout(customOptions: { ms: number }) {
35+
timeout(customOptions?: { ms?: number }) {
36+
if (!customOptions) {
37+
customOptions = {};
38+
}
39+
customOptions.ms = customOptions && customOptions.ms ? customOptions.ms : 1000;
3640
this.log('timeout').debug('start');
3741
this.log('timeout').debug(customOptions.ms);
3842
return new Promise(resolve =>

test/app-spec.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,10 @@ describe('App', () => {
2525
it('srcgen -x -t make.list.ts.files -f ./srcgen/app1-make.list.ts.files.json', (done) => {
2626
const app = new App(dir, dirRoot);
2727
app.debug = debug;
28-
app.makeTsList({
29-
package: '',
30-
listComponentsPostfix: ''
31-
}).then((data: any) => {
28+
app.makeTsList().then((data: any) => {
3229
assert.equal(fsExtra.existsSync(indexTsFile), true);
3330
done();
34-
}).catch(function (e) {
31+
}).catch((e: any) => {
3532
done(e);
3633
});
3734
});
@@ -53,7 +50,7 @@ describe('App', () => {
5350
app.extractTranslate({}).then((data: any) => {
5451
assert.equal(fsExtra.existsSync(indexFile), true);
5552
done();
56-
}).catch(function (e) {
53+
}).catch((e: any) => {
5754
done(e);
5855
});
5956
});
@@ -73,10 +70,10 @@ describe('App', () => {
7370
it('srcgen -x -t convert.po.to.ts -f ./srcgen/convert.po.to.ts.json', (done) => {
7471
const app = new App(dir, dirRoot);
7572
app.debug = debug;
76-
app.po2ts({ package: { name: '' } }).then((data: any) => {
73+
app.po2ts().then((data: any) => {
7774
assert.equal(fsExtra.existsSync(translateTsFile), true);
7875
done();
79-
}).catch(function (e) {
76+
}).catch((e: any) => {
8077
done(e);
8178
});
8279
});
@@ -103,18 +100,11 @@ describe('App', () => {
103100
it('npm-run-all app1:tools-extract_translate app1:tools-po2ts app1:tools-make_ts_list', (done) => {
104101
const app = new App(dir, dirRoot);
105102
app.debug = debug;
106-
app.prepare({
107-
i18nFolder: '',
108-
srcFolder: '',
109-
package: { name: '' },
110-
listComponentsPostfix: '',
111-
rootPackagePath: '',
112-
srcPackagePath: ''
113-
}).then((data: any) => {
103+
app.prepare().then((data: any) => {
114104
assert.equal(fsExtra.existsSync(translateTsFile), true);
115105
assert.equal(fsExtra.existsSync(indexTsFile), true);
116106
done();
117-
}).catch(function (e) {
107+
}).catch((e: any) => {
118108
done(e);
119109
});
120110
});

test/apps-spec.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,7 @@ describe('Apps', () => {
5555
const dirs = items.map((item: any) => item.dir);
5656
const app = new Apps(dirs, dirRoot);
5757
app.debug = debug;
58-
app.prepare({
59-
i18nFolder: '',
60-
srcFolder: '',
61-
package: { name: '' },
62-
packages: [],
63-
listComponentsPostfix: '',
64-
rootPackagePath: '',
65-
srcPackagePath: ''
66-
}).then((data: boolean) => {
58+
app.prepare().then((data: boolean) => {
6759
items.forEach(({
6860
dir: dir,
6961
translateTsFile: translateTsFile,
@@ -73,7 +65,7 @@ describe('Apps', () => {
7365
assert.equal(fsExtra.existsSync(indexTsFile), true);
7466
});
7567
done();
76-
}).catch(function (e) {
68+
}).catch((e: any) => {
7769
done(e);
7870
});
7971
});

test/cmd-apps-spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('Apps: run from console', () => {
6262
base.commandRunner(commandString).then((data: boolean) => {
6363
assert.equal(fsExtra.existsSync(file), true);
6464
done();
65-
}).catch(function (e) {
65+
}).catch((e: any) => {
6666
done(e);
6767
});
6868
});
@@ -84,7 +84,7 @@ describe('Apps: run from console', () => {
8484
assert.equal(fsExtra.existsSync(indexTsFile), true);
8585
});
8686
done();
87-
}).catch(function (e) {
87+
}).catch((e: any) => {
8888
done(e);
8989
});
9090
});

test/cmd-commands-spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('Apps-commands: run from console', () => {
6262
base.commandRunner(commandString).then((data: boolean) => {
6363
assert.equal(fsExtra.existsSync(file), true);
6464
done();
65-
}).catch(function (e) {
65+
}).catch((e: any) => {
6666
done(e);
6767
});
6868
});
@@ -84,7 +84,7 @@ describe('Apps-commands: run from console', () => {
8484
assert.equal(fsExtra.existsSync(indexTsFile), true);
8585
});
8686
done();
87-
}).catch(function (e) {
87+
}).catch((e: any) => {
8888
done(e);
8989
});
9090
});

test/cmd-libs-spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('Libs: run from console', () => {
6060
base.commandRunner(commandString).then((data: boolean) => {
6161
assert.equal(fsExtra.existsSync(file), true);
6262
done();
63-
}).catch(function (e) {
63+
}).catch((e: any) => {
6464
done(e);
6565
});
6666
});
@@ -82,7 +82,7 @@ describe('Libs: run from console', () => {
8282
assert.equal(fsExtra.existsSync(indexTsFile), true);
8383
});
8484
done();
85-
}).catch(function (e) {
85+
}).catch((e: any) => {
8686
done(e);
8787
});
8888
});

0 commit comments

Comments
 (0)