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

View File

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

View File

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