-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove all yaml meta file, change them to JSON (#138)
* feat: remove all yaml meta file, change them to JSON * refactor(utils): loadMetaFile check condition * refactor(utils): loadMetaFile arguments and pre-logic
- Loading branch information
1 parent
7161703
commit 8392260
Showing
42 changed files
with
145 additions
and
128 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"ARTUS:GLOBAL_TEST": { | ||
"desc": "全局测试错误,仅用于单元测试", | ||
"detailUrl": "https://github.com/artusjs/spec" | ||
}, | ||
"ARTUS:GLOBAL_TEST_I18N": { | ||
"desc": { | ||
"zh": "全局测试错误,仅用于单元测试", | ||
"en": "This is a test exception, only valid in unit-test" | ||
}, | ||
"detailUrl": "https://github.com/artusjs/spec" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,9 @@ | ||
import yaml from 'js-yaml'; | ||
import { readFile } from 'fs/promises'; | ||
import { ManifestItem } from '../loader/types'; | ||
import compatibleRequire from './compatible_require'; | ||
|
||
type ParserFunction = <T = Record<string, any>>(content: string) => T; | ||
|
||
const YamlParser: ParserFunction = <T = Record<string, any>>(content: string) => { | ||
return yaml.load(content, { | ||
json: true, | ||
}) as T; | ||
}; | ||
const JsonParser: ParserFunction = <T = Record<string, any>>(content: string) => { | ||
return JSON.parse(content) as T; | ||
}; | ||
|
||
export const loadMetaFile = async <T = Record<string, any>>(item: ManifestItem): Promise<T> => { | ||
let parserFunc: ParserFunction; | ||
if (item.extname === '.yaml' || item.extname === '.yml') { | ||
parserFunc = YamlParser; | ||
} else if (item.extname === '.json') { | ||
parserFunc = JsonParser; | ||
} else { | ||
throw new Error(`[Artus-Loader] Unsupported file extension: ${item.extname} in ${item.path}`); | ||
} | ||
const content = await readFile(item.path, { | ||
encoding: 'utf-8', | ||
}); | ||
if (!content) { | ||
throw new Error(`[Artus-Loader] File content is empty in ${item.path}.`); | ||
export const loadMetaFile = async <T = Record<string, any>>(path: string): Promise<T> => { | ||
const metaObject = await compatibleRequire(path); | ||
if (!metaObject || typeof metaObject !== 'object') { | ||
throw new Error(`[loadMetaFile] ${path} is not a valid json file.`); | ||
} | ||
const resultMap = parserFunc<T>(content); | ||
return resultMap; | ||
return metaObject; | ||
}; |
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,13 @@ | ||
{ | ||
"ARTUS:GLOBAL_TEST": { | ||
"desc": "全局测试错误,仅用于单元测试", | ||
"detailUrl": "https://github.com/artusjs/spec" | ||
}, | ||
"ARTUS:GLOBAL_TEST_I18N": { | ||
"desc": { | ||
"zh": "全局测试错误,仅用于单元测试", | ||
"en": "This is a test exception, only valid in unit-test" | ||
}, | ||
"detailUrl": "https://github.com/artusjs/spec" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
{ | ||
"name": "mysql" | ||
} |
This file was deleted.
Oops, something went wrong.
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,7 @@ | ||
{ | ||
"name": "redis", | ||
"exclude": [ | ||
"not_to_be_scanned_dir", | ||
"not_to_be_scanned_file.ts" | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
test/fixtures/app_koa_with_ts/src/test_duplicate_plugin/meta.json
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,3 @@ | ||
{ | ||
"name": "testDuplicate" | ||
} |
1 change: 0 additions & 1 deletion
1
test/fixtures/app_koa_with_ts/src/test_duplicate_plugin/meta.yaml
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
test/fixtures/artus_application/src/plugins/artus_plugin_base/meta.json
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,3 @@ | ||
{ | ||
"name": "base" | ||
} |
1 change: 0 additions & 1 deletion
1
test/fixtures/artus_application/src/plugins/artus_plugin_base/meta.yml
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
test/fixtures/artus_application/src/plugins/artus_plugin_mysql_ob/meta.json
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,9 @@ | ||
{ | ||
"name": "mysql", | ||
"configDir": "src/custom_config", | ||
"dependencies": [ | ||
{ | ||
"name": "base" | ||
} | ||
] | ||
} |
4 changes: 0 additions & 4 deletions
4
test/fixtures/artus_application/src/plugins/artus_plugin_mysql_ob/meta.yml
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
test/fixtures/artus_application/src/plugins/artus_plugin_mysql_rds/meta.json
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,3 @@ | ||
{ | ||
"name": "mysql" | ||
} |
1 change: 0 additions & 1 deletion
1
test/fixtures/artus_application/src/plugins/artus_plugin_mysql_rds/meta.yml
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
test/fixtures/artus_application/src/plugins/artus_plugin_redis/meta.json
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,3 @@ | ||
{ | ||
"name": "redis" | ||
} |
1 change: 0 additions & 1 deletion
1
test/fixtures/artus_application/src/plugins/artus_plugin_redis/meta.yml
This file was deleted.
Oops, something went wrong.
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,6 @@ | ||
{ | ||
"APP:TEST_ERROR": { | ||
"desc": "这是一个测试用的错误", | ||
"detailUrl": "https://github.com/artusjs" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,12 @@ | ||
{ | ||
"name": "plugin-a", | ||
"dependencies": [ | ||
{ | ||
"name": "plugin-b" | ||
}, | ||
{ | ||
"name": "plugin-c", | ||
"optional": true | ||
} | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
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,8 @@ | ||
{ | ||
"name": "plugin-b", | ||
"dependencies": [ | ||
{ | ||
"name": "plugin-c" | ||
} | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
{ | ||
"name": "plugin-c" | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.