feat: add file name as the third argument which passed to module post processor

This commit is contained in:
LeoYuan 袁力皓 2023-03-02 10:38:31 +08:00
parent bb770b8e5a
commit a2d857b143
3 changed files with 27 additions and 33 deletions

View File

@ -15,7 +15,6 @@ module.exports = {
'no-prototype-builtins': 1,
'no-useless-constructor': 1,
'no-empty-function': 1,
'@typescript-eslint/member-ordering': 0,
'lines-between-class-members': 0,
'no-await-in-loop': 0,
'no-plusplus': 0,
@ -35,22 +34,23 @@ module.exports = {
'@typescript-eslint/indent': 0,
'import/no-cycle': 0,
'@typescript-eslint/no-shadow': 0,
"@typescript-eslint/method-signature-style": 0,
"@typescript-eslint/consistent-type-assertions": 0,
"@typescript-eslint/no-useless-constructor": 0,
'@typescript-eslint/method-signature-style': 0,
'@typescript-eslint/consistent-type-assertions': 0,
'@typescript-eslint/no-useless-constructor': 0,
'@typescript-eslint/dot-notation': 0, // for lint performance
'@typescript-eslint/restrict-plus-operands': 0, // for lint performance
'no-unexpected-multiline': 1,
'no-multiple-empty-lines': ['error', { "max": 1 }],
'no-multiple-empty-lines': ['error', { max: 1 }],
'lines-around-comment': ['error', {
"beforeBlockComment": true,
"afterBlockComment": false,
"afterLineComment": false,
"allowBlockStart": true,
beforeBlockComment: true,
afterBlockComment: false,
afterLineComment: false,
allowBlockStart: true,
}],
"@typescript-eslint/member-ordering": [
"error",
{ "default": ["signature", "field", "constructor", "method"] }
'comma-dangle': ['error', 'always-multiline'],
'@typescript-eslint/member-ordering': [
'error',
{ default: ['signature', 'field', 'constructor', 'method'] },
],
}
},
};

View File

@ -62,10 +62,9 @@ export function createModuleBuilder(
if (options.postProcessors.length > 0) {
files = files.map((file) => {
let { content } = file;
const type = file.ext;
let { content, ext: type, name } = file;
options.postProcessors.forEach((processer) => {
content = processer(content, type);
content = processer(content, type, name);
});
return createResultFile(file.name, type, content);

View File

@ -1,20 +1,15 @@
import {
IPublicTypeJSONArray,
IPublicTypeJSONObject,
IPublicTypeCompositeArray,
IPublicTypeCompositeObject,
ResultDir,
IPublicTypeCompositeObject, IPublicTypeJSExpression,
IPublicTypeJSFunction, IPublicTypeJSONArray,
IPublicTypeJSONObject, IPublicTypeJSSlot, IPublicTypeNodeDataType,
IPublicTypeProjectSchema, ResultDir,
ResultFile,
IPublicTypeNodeDataType,
IPublicTypeProjectSchema,
IPublicTypeJSExpression,
IPublicTypeJSFunction,
IPublicTypeJSSlot,
} from '@alilc/lowcode-types';
import { IParseResult } from './intermediate';
import { IScopeBindings } from '../utils/ScopeBindings';
import type { ProjectBuilderInitOptions } from '../generator/ProjectBuilder';
import { IScopeBindings } from '../utils/ScopeBindings';
import { IParseResult } from './intermediate';
export enum FileType {
CSS = 'css',
@ -69,16 +64,16 @@ export interface ICodeStruct extends IBaseCodeStruct {
/** 上下文数据,用来在插件之间共享一些数据 */
export interface IContextData extends IProjectBuilderOptions {
/**
* 使 Ref API (this.$/this.$$)
* */
useRefApi?: boolean;
/**
*
*
*/
[key: string]: any;
/**
* 使 Ref API (this.$/this.$$)
* */
useRefApi?: boolean;
}
export type BuilderComponentPlugin = (initStruct: ICodeStruct) => Promise<ICodeStruct>;
@ -202,7 +197,7 @@ export type ProjectPostProcessor = (
export type PostProcessorFactory<T> = (config?: T) => PostProcessor;
/** 模块级别的后置处理器 */
export type PostProcessor = (content: string, fileType: string) => string;
export type PostProcessor = (content: string, fileType: string, name: string) => string;
// TODO: temp interface, need modify
export interface IPluginOptions {