mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-02-11 14:20:07 +08:00
feat(utils): Add jest-yaml-transform package.
This commit is contained in:
parent
ac9e07ef19
commit
dd9dbe4989
7
packages/utils/jest-yaml-transform/.swcrc
Normal file
7
packages/utils/jest-yaml-transform/.swcrc
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"exclude": [".*.test.js$", ".*/tests/.*", ".*/__mocks__/.*"],
|
||||
"$schema": "http://json.schemastore.org/swcrc",
|
||||
"module": {
|
||||
"type": "commonjs"
|
||||
}
|
||||
}
|
3
packages/utils/jest-yaml-transform/README.md
Normal file
3
packages/utils/jest-yaml-transform/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# @lowdefy/jest-yaml-transform
|
||||
|
||||
A jest transformer for YAML based off: https://github.com/sumwatshade/jest-transform-yaml
|
44
packages/utils/jest-yaml-transform/package.json
Normal file
44
packages/utils/jest-yaml-transform/package.json
Normal file
@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "@lowdefy/jest-yaml-transform",
|
||||
"version": "4.0.0-alpha.12",
|
||||
"licence": "Apache-2.0",
|
||||
"description": "A Jest Transform for YAML.",
|
||||
"main": "./dist/index.js",
|
||||
"homepage": "https://lowdefy.com",
|
||||
"keywords": [
|
||||
"lowdefy",
|
||||
"yaml",
|
||||
"jest",
|
||||
"jest-transform",
|
||||
"jest-yaml-transform"
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/lowdefy/lowdefy/issues"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Gerrie van Wyk",
|
||||
"url": "https://github.com/Gervwyk"
|
||||
}
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/lowdefy/lowdefy.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "yarn swc",
|
||||
"clean": "rm -rf dist",
|
||||
"prepare": "yarn build",
|
||||
"swc": "swc src --out-dir dist --config-file ./.swcrc --delete-dir-on-start"
|
||||
},
|
||||
"dependencies": {
|
||||
"@swc/cli": "0.1.57",
|
||||
"@swc/core": "1.2.194",
|
||||
"@swc/jest": "0.2.21",
|
||||
"jest": "28.1.0",
|
||||
"yaml": "2.1.1"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
}
|
||||
}
|
34
packages/utils/jest-yaml-transform/src/index.js
Normal file
34
packages/utils/jest-yaml-transform/src/index.js
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
Copyright 2020-2022 Lowdefy, Inc
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import YAML from 'yaml';
|
||||
import crypto from 'crypto';
|
||||
|
||||
function getCacheKey(fileData, filePath, options) {
|
||||
const optionsString = typeof options === 'string' ? options : JSON.stringify(options);
|
||||
return crypto.createHash('md5').update(fileData).update(optionsString).digest('hex');
|
||||
}
|
||||
|
||||
function process(sourceText) {
|
||||
return { code: `module.exports = ${JSON.stringify(YAML.parse(sourceText), null, '\t')}` };
|
||||
}
|
||||
|
||||
const transformer = {
|
||||
getCacheKey,
|
||||
process,
|
||||
};
|
||||
|
||||
export default transformer;
|
Loading…
Reference in New Issue
Block a user