mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-04-05 19:41:57 +08:00
feat: enums和vuex构建配置提示
This commit is contained in:
parent
abffcdb9a1
commit
972518ff9c
@ -29,5 +29,6 @@
|
||||
"peerDependencies": {
|
||||
"@fesjs/fes": "^2.0.0",
|
||||
"vue": "^3.0.5"
|
||||
}
|
||||
},
|
||||
"typings": "./types.d.ts"
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
import { readFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { name } from '../package.json';
|
||||
|
||||
const namespace = 'plugin-enums';
|
||||
|
||||
export default (api) => {
|
||||
const {
|
||||
utils: { Mustache }
|
||||
utils: { Mustache },
|
||||
} = api;
|
||||
|
||||
api.describe({
|
||||
@ -14,8 +15,8 @@ export default (api) => {
|
||||
schema(joi) {
|
||||
return joi.object();
|
||||
},
|
||||
onChange: api.ConfigChangeType.regenerateTmpFiles
|
||||
}
|
||||
onChange: api.ConfigChangeType.regenerateTmpFiles,
|
||||
},
|
||||
});
|
||||
|
||||
const absoluteFilePath = join(namespace, 'core.js');
|
||||
@ -24,25 +25,27 @@ export default (api) => {
|
||||
const enums = api.config.enums || {};
|
||||
api.writeTmpFile({
|
||||
path: absoluteFilePath,
|
||||
content: Mustache.render(
|
||||
readFileSync(join(__dirname, 'runtime/core.tpl'), 'utf-8'),
|
||||
{
|
||||
REPLACE_ENUMS: JSON.stringify(enums)
|
||||
}
|
||||
)
|
||||
content: Mustache.render(readFileSync(join(__dirname, 'runtime/core.tpl'), 'utf-8'), {
|
||||
REPLACE_ENUMS: JSON.stringify(enums),
|
||||
}),
|
||||
});
|
||||
|
||||
api.copyTmpFiles({
|
||||
namespace,
|
||||
path: join(__dirname, 'runtime'),
|
||||
ignore: ['.tpl']
|
||||
ignore: ['.tpl'],
|
||||
});
|
||||
});
|
||||
|
||||
api.addPluginExports(() => [
|
||||
{
|
||||
specifiers: ['enums'],
|
||||
source: absoluteFilePath
|
||||
}
|
||||
source: absoluteFilePath,
|
||||
},
|
||||
]);
|
||||
|
||||
api.addConfigType(() => ({
|
||||
source: name,
|
||||
build: ['EnumsBuildConfig'],
|
||||
}));
|
||||
};
|
||||
|
8
packages/fes-plugin-enums/types.d.ts
vendored
Normal file
8
packages/fes-plugin-enums/types.d.ts
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
export interface EnumsBuildConfig {
|
||||
enums: {
|
||||
[key: string]: [string | number, string | number][]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,39 +16,31 @@ export default (cwd, args) => {
|
||||
'!**/types/**',
|
||||
'!**/fixtures/**',
|
||||
'!**/examples/**',
|
||||
'!**/*.d.ts'
|
||||
'!**/*.d.ts',
|
||||
].filter(Boolean),
|
||||
moduleFileExtensions: [
|
||||
'js',
|
||||
'jsx',
|
||||
'json',
|
||||
// tell Jest to handle *.vue files
|
||||
'vue'
|
||||
'vue',
|
||||
],
|
||||
transform: {
|
||||
// process *.vue files with vue-jest
|
||||
'^.+\\.vue$': require.resolve('vue3-jest'),
|
||||
'.+\\.(css|styl|less|sass|scss|jpg|jpeg|png|svg|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
|
||||
require.resolve('jest-transform-stub'),
|
||||
'^.+\\.jsx?$': require.resolve(
|
||||
'../helpers/transformers/javascript'
|
||||
)
|
||||
'^.+\\.jsx?$': require.resolve('../helpers/transformers/javascript'),
|
||||
},
|
||||
transformIgnorePatterns: ['/node_modules/'],
|
||||
// support the same @ -> src alias mapping in source code
|
||||
moduleNameMapper: {
|
||||
'^@/(.*)$': '<rootDir>/src/$1'
|
||||
'^@/(.*)$': '<rootDir>/src/$1',
|
||||
},
|
||||
testMatch: [
|
||||
`**/tests/**/*.(${testMatchTypes.join('|')}).[jt]s?(x)`,
|
||||
'**/__tests__/**/*.[jt]s?(x)'
|
||||
],
|
||||
testMatch: [`**/tests/**/*.(${testMatchTypes.join('|')}).[jt]s?(x)`, '**/__tests__/**/*.[jt]s?(x)'],
|
||||
// https://github.com/facebook/jest/issues/6766
|
||||
testURL: 'http://localhost/',
|
||||
watchPlugins: [
|
||||
require.resolve('jest-watch-typeahead/filename'),
|
||||
require.resolve('jest-watch-typeahead/testname')
|
||||
],
|
||||
verbose: true
|
||||
watchPlugins: [require.resolve('jest-watch-typeahead/filename'), require.resolve('jest-watch-typeahead/testname')],
|
||||
verbose: true,
|
||||
};
|
||||
};
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
import assert from 'assert';
|
||||
import { join } from 'path';
|
||||
import { existsSync } from 'fs';
|
||||
@ -28,7 +27,10 @@ function getCommandOptiton() {
|
||||
}
|
||||
|
||||
export default function (api) {
|
||||
const { utils: { mergeConfig }, cwd } = api;
|
||||
const {
|
||||
utils: { mergeConfig },
|
||||
cwd,
|
||||
} = api;
|
||||
|
||||
api.registerCommand({
|
||||
command: 'test',
|
||||
@ -55,11 +57,7 @@ export default function (api) {
|
||||
|
||||
// Merge configs
|
||||
// user config and args config could have value function for modification
|
||||
const config = mergeConfig(
|
||||
createDefaultConfig(cwd, args),
|
||||
packageJestConfig,
|
||||
userJestConfig
|
||||
);
|
||||
const config = mergeConfig(createDefaultConfig(cwd, args), packageJestConfig, userJestConfig);
|
||||
args.debug && logger.log(`final config: ${JSON.stringify(config)}`);
|
||||
|
||||
// Generate jest options
|
||||
@ -85,14 +83,14 @@ export default function (api) {
|
||||
// 必须是单独的 config 配置,值为 string,否则不生效
|
||||
// @ts-ignore
|
||||
config: JSON.stringify(config),
|
||||
...argsConfig
|
||||
...argsConfig,
|
||||
},
|
||||
[cwd]
|
||||
[cwd],
|
||||
);
|
||||
args.debug && logger.log(result);
|
||||
|
||||
// Throw error when run failed
|
||||
assert(result.results.success, 'Test with jest failed');
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
module.exports = {
|
||||
copy: ['runtime']
|
||||
copy: ['runtime'],
|
||||
};
|
||||
|
@ -33,5 +33,6 @@
|
||||
"@fesjs/fes": "^2.0.0",
|
||||
"vue": "^3.0.5",
|
||||
"vuex": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"typings": "./types.d.ts"
|
||||
}
|
||||
|
@ -2,13 +2,14 @@ import { readFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { winPath } from '@fesjs/utils';
|
||||
import { parseStore } from './helper';
|
||||
import { name } from '../package.json';
|
||||
|
||||
const namespace = 'plugin-vuex';
|
||||
|
||||
export default (api) => {
|
||||
const {
|
||||
paths,
|
||||
utils: { Mustache }
|
||||
utils: { Mustache },
|
||||
} = api;
|
||||
|
||||
api.describe({
|
||||
@ -17,8 +18,8 @@ export default (api) => {
|
||||
schema(joi) {
|
||||
return joi.object();
|
||||
},
|
||||
onChange: api.ConfigChangeType.regenerateTmpFiles
|
||||
}
|
||||
onChange: api.ConfigChangeType.regenerateTmpFiles,
|
||||
},
|
||||
});
|
||||
|
||||
const absCoreFilePath = join(namespace, 'core.js');
|
||||
@ -30,9 +31,7 @@ export default (api) => {
|
||||
// 文件写出
|
||||
api.writeTmpFile({
|
||||
path: absCoreFilePath,
|
||||
content: Mustache.render(
|
||||
readFileSync(join(__dirname, 'runtime/core.tpl'), 'utf-8'),
|
||||
{
|
||||
content: Mustache.render(readFileSync(join(__dirname, 'runtime/core.tpl'), 'utf-8'), {
|
||||
IMPORT_MODULES: store.importModules.join('\n'),
|
||||
IMPORT_PLUGINS: store.importPlugins.join('\n'),
|
||||
MODULES: `{ ${store.modules.join(', ')} }`,
|
||||
@ -40,24 +39,28 @@ export default (api) => {
|
||||
MUTATION_TYPES: JSON.stringify(store.MUTATION_TYPES),
|
||||
ACTION_TYPES: JSON.stringify(store.ACTION_TYPES),
|
||||
GETTER_TYPES: JSON.stringify(store.GETTER_TYPES),
|
||||
VUEX_CONFIG: JSON.stringify(vuexConfig)
|
||||
}
|
||||
)
|
||||
VUEX_CONFIG: JSON.stringify(vuexConfig),
|
||||
}),
|
||||
});
|
||||
|
||||
api.copyTmpFiles({
|
||||
namespace,
|
||||
path: join(__dirname, 'runtime'),
|
||||
ignore: ['.tpl']
|
||||
ignore: ['.tpl'],
|
||||
});
|
||||
});
|
||||
|
||||
api.addPluginExports(() => [
|
||||
{
|
||||
specifiers: ['MUTATION_TYPES', 'ACTION_TYPES', 'GETTER_TYPES', 'store'],
|
||||
source: absCoreFilePath
|
||||
}
|
||||
source: absCoreFilePath,
|
||||
},
|
||||
]);
|
||||
|
||||
api.addRuntimePlugin(() => `@@/${absRuntimeFilePath}`);
|
||||
|
||||
api.addConfigType(() => ({
|
||||
source: name,
|
||||
build: ['VuexBuildConfig'],
|
||||
}));
|
||||
};
|
||||
|
9
packages/fes-plugin-vuex/types.d.ts
vendored
Normal file
9
packages/fes-plugin-vuex/types.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
export interface VuexBuildConfig {
|
||||
vuex: {
|
||||
strict: boolean;
|
||||
devtools: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user