-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #178 from SylarLong/feat-165
Feat: global configuration & plugin support
- Loading branch information
Showing
8 changed files
with
232 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { astro } from '../..'; | ||
import FunctionalAstrolabe from '../../astro/FunctionalAstrolabe'; | ||
|
||
export interface IAstrolabe extends FunctionalAstrolabe { | ||
myNewFunc: () => string; | ||
majorStar: () => string; | ||
} | ||
|
||
// 创建一个插件函数 | ||
export function myTestPlugin(this: IAstrolabe): void { | ||
// 实现插件应用逻辑 | ||
this.myNewFunc = () => { | ||
return this.fiveElementsClass; | ||
}; | ||
} | ||
|
||
// 创建二个插件函数 | ||
export function myTestPlugin2(this: IAstrolabe): void { | ||
// 实现插件应用逻辑 | ||
this.majorStar = () => { | ||
let stars = this.palace('命宫') | ||
?.majorStars.filter((item) => item.type === 'major' && !['禄存', '天马'].includes(item.name)) | ||
.map((item) => item.name) | ||
.join(','); | ||
|
||
if (!stars) { | ||
stars = this.palace('迁移') | ||
?.majorStars.filter((item) => item.type === 'major' && !['禄存', '天马'].includes(item.name)) | ||
.map((item) => item.name) | ||
.join(','); | ||
} | ||
|
||
return stars ?? ''; | ||
}; | ||
} | ||
|
||
astro.loadPlugins([myTestPlugin]); | ||
astro.loadPlugin(myTestPlugin2); | ||
|
||
astro.config({ | ||
mutagens: { 庚: ['太阳', '武曲', '天同', '天相'] }, | ||
brightness: { | ||
贪狼: ['旺', '旺', '旺', '旺', '旺', '旺', '旺', '旺', '旺', '旺', '旺', '旺'], | ||
}, | ||
}); | ||
|
||
describe('plugin test', () => { | ||
test('plugin', () => { | ||
const astrolabe = astro.bySolar<IAstrolabe>('2023-10-18', 4, 'female'); | ||
|
||
expect(astrolabe.myNewFunc()).toEqual('火六局'); | ||
expect(astrolabe.majorStar()).toEqual('七杀'); | ||
}); | ||
|
||
test('changed configuration', () => { | ||
const astrolabe = astro.bySolar<IAstrolabe>('2010-10-18', 4, 'female'); | ||
|
||
expect(astrolabe.palace('命宫')?.hasMutagen('忌')).toBeFalsy(); | ||
expect(astrolabe.palace('夫妻')?.hasMutagen('忌')).toBeTruthy(); | ||
expect(astrolabe.star('贪狼').withBrightness('旺')).toBeTruthy(); | ||
}); | ||
|
||
test('not changed configuration', () => { | ||
const astrolabe = astro.bySolar<IAstrolabe>('2011-10-18', 4, 'female'); | ||
|
||
expect(astrolabe.palace('命宫')?.hasMutagen('权')).toBeTruthy(); | ||
expect(astrolabe.palace('命宫')?.hasMutagen('忌')).toBeTruthy(); | ||
expect(astrolabe.palace('福德')?.hasMutagen('科')).toBeTruthy(); | ||
expect(astrolabe.palace('田宅')?.hasMutagen('禄')).toBeFalsy(); | ||
expect(astrolabe.palace('财帛')?.fliesTo('夫妻', '科')).toBeTruthy(); | ||
expect(astrolabe.palace('财帛')?.fliesTo('仆役', '忌')).toBeTruthy(); | ||
expect(astrolabe.star('紫微').withBrightness('旺')).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters