@@ -2,7 +2,7 @@ import * as fs from 'fs-extra';
22import * as _ from 'lodash' ;
33import * as path from 'path' ;
44import * as pkg from '../../../../package.json' ;
5- import { pluginEntry , pri } from '../../../node' ;
5+ import { pluginEntry , pri , srcPath } from '../../../node' ;
66import { PRI_PACKAGE_NAME } from '../../../utils/constants' ;
77import { globalState } from '../../../utils/global-state' ;
88import { logSuccess , logText } from '../../../utils/log' ;
@@ -23,6 +23,26 @@ function ensureEntry() {
2323 }
2424
2525 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+
2646 return prettier . format (
2747 `
2848 import * as path from "path"
@@ -34,38 +54,36 @@ function ensureEntry() {
3454 }
3555 }
3656
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+ })
4463
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+ })
5170
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+ })
5574
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+ }
6079
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+ \`
6785 })
68- }
86+ })
6987
7088 export function judgeHasComponents(projectRootPath: string, files: path.ParsedPath[]) {
7189 return files.some(file => {
0 commit comments