@@ -2,7 +2,7 @@ import * as fs from 'fs-extra';
2
2
import * as _ from 'lodash' ;
3
3
import * as path from 'path' ;
4
4
import * as pkg from '../../../../package.json' ;
5
- import { pluginEntry , pri } from '../../../node' ;
5
+ import { pluginEntry , pri , srcPath } from '../../../node' ;
6
6
import { PRI_PACKAGE_NAME } from '../../../utils/constants' ;
7
7
import { globalState } from '../../../utils/global-state' ;
8
8
import { logSuccess , logText } from '../../../utils/log' ;
@@ -23,6 +23,26 @@ function ensureEntry() {
23
23
}
24
24
25
25
const prettier = await import ( 'prettier' ) ;
26
+
27
+ return prettier . format ( `
28
+ export const getPlugin = () => import('./plugin');
29
+
30
+ export const getConfig = () => ({
31
+ name: 'pri-plugin-${ pri . projectPackageJson . name } '
32
+ });
33
+ ` ) ;
34
+ }
35
+ } ) ;
36
+
37
+ pri . project . addProjectFiles ( {
38
+ fileName : path . join ( path . format ( srcPath ) , 'plugin/index.ts' ) ,
39
+ pipeContent : async text => {
40
+ if ( text ) {
41
+ return text ;
42
+ }
43
+
44
+ const prettier = await import ( 'prettier' ) ;
45
+
26
46
return prettier . format (
27
47
`
28
48
import * as path from "path"
@@ -34,38 +54,36 @@ function ensureEntry() {
34
54
}
35
55
}
36
56
37
- export default async () => {
38
- pri.commands.registerCommand({
39
- name: ["deploy"],
40
- action: async () => {
41
- //
42
- }
43
- })
57
+ pri.commands.registerCommand({
58
+ name: ["deploy"],
59
+ action: async () => {
60
+ //
61
+ }
62
+ })
44
63
45
- pri.commands.expandCommand({
46
- name: ["init"],
47
- beforeAction: async (...args: any[]) => {
48
- //
49
- }
50
- })
64
+ pri.commands.expandCommand({
65
+ name: ["init"],
66
+ beforeAction: async (...args: any[]) => {
67
+ //
68
+ }
69
+ })
51
70
52
- pri.project.onAnalyseProject(files => {
53
- return { customPlugin: { hasComponents: judgeHasComponents(pri.projectRootPath, files) } } as IResult
54
- })
71
+ pri.project.onAnalyseProject(files => {
72
+ return { customPlugin: { hasComponents: judgeHasComponents(pri.projectRootPath, files) } } as IResult
73
+ })
55
74
56
- pri.project.onCreateEntry((analyseInfo: IResult, entry) => {
57
- if (!analyseInfo.customPlugin.hasComponents) {
58
- return
59
- }
75
+ pri.project.onCreateEntry((analyseInfo: IResult, entry) => {
76
+ if (!analyseInfo.customPlugin.hasComponents) {
77
+ return
78
+ }
60
79
61
- entry.pipeAppHeader(header => {
62
- return \`
63
- \${header}
64
- import "src/components/xxx"
65
- \`
66
- })
80
+ entry.pipeAppHeader(header => {
81
+ return \`
82
+ \${header}
83
+ import "src/components/xxx"
84
+ \`
67
85
})
68
- }
86
+ })
69
87
70
88
export function judgeHasComponents(projectRootPath: string, files: path.ParsedPath[]) {
71
89
return files.some(file => {
0 commit comments