repo_name stringlengths 1 62 | dataset stringclasses 1
value | lang stringclasses 11
values | pr_id int64 1 20.1k | owner stringlengths 2 34 | reviewer stringlengths 2 39 | diff_hunk stringlengths 15 262k | code_review_comment stringlengths 1 99.6k |
|---|---|---|---|---|---|---|---|
create-neat | github_2023 | typescript | 294 | xun082 | uaenaTzx | @@ -1,27 +1,22 @@
-const globalProtocol = {
+export const globalProtocol = {
ENTRY_FILE: "ENTRY_FILE", // 入口文件配置,如:入口文件引入全局 less、scss
+ UPDATE_EXPORT_CONTENT_PROTOCOL: "UPDATE_EXPORT_CONTENT_PROTOCOL", | 没有 get 到 UPDATE 的语义,INSERT_EXPORT 感觉合适一些 |
create-neat | github_2023 | typescript | 294 | xun082 | uaenaTzx | @@ -1,27 +1,22 @@
-const globalProtocol = {
+export const globalProtocol = {
ENTRY_FILE: "ENTRY_FILE", // 入口文件配置,如:入口文件引入全局 less、scss
+ UPDATE_EXPORT_CONTENT_PROTOCOL: "UPDATE_EXPORT_CONTENT_PROTOCOL",
};
// 插件对框架的协议
-const pluginToTemplateProtocol = {
+export const pluginToTemplateProtocol = {
...globalProt... | 统一导出在性能上会更好 |
create-neat | github_2023 | typescript | 294 | xun082 | uaenaTzx | @@ -11,7 +13,7 @@ import { Protocol } from "../../types/protocol";
class ProtocolGeneratorAPI {
protected protocols: Record<string, object>; // todo 类型考虑优化
protected props: ProtocolProps;
- protected protocol: Protocol;
+ protected protocol: string; | 为啥不用 Protocol 了 |
create-neat | github_2023 | typescript | 294 | xun082 | uaenaTzx | @@ -52,3 +52,13 @@ export const createCallExpression = (
*/
export const createObjectProperty = (name: string, value: Parameters<typeof objectProperty>[1]) =>
objectProperty(identifier(name), value);
+
+/**
+ * 封装遍历ast中ExportDefaultDeclaration的通用函数 | ExportDefaultDeclaration的通用函数,需要结合上下文才能看懂是什么意思
可以尝试给一个更清晰的说明 |
create-neat | github_2023 | others | 292 | xun082 | uaenaTzx | @@ -1,8 +1,61 @@
+const path = require('path');
+const protocol = require("../../../core/src/configs/protocol.ts");
+const pluginToTemplateProtocol = protocol.pluginToTemplateProtocol; | require 放最前面,这个穿插些有点乱 |
create-neat | github_2023 | typescript | 292 | xun082 | uaenaTzx | @@ -0,0 +1,106 @@
+// todo 因为文件中的函数或方法被index.cjs调用,导致无法用ts和esm导出写法
+
+// 定义 LocationCode 枚举,用于指定插件内容插入的位置
+/**
+ * 插入位置
+ * @enum
+ * @property {number} BeforeMatchStructure - 在匹配结构之前
+ * @property {number} InMatchStructure - 在匹配结构中
+ * @property {number} AfterMatchStructureImport - 在匹配结构导入之后
+ * @property {number} Aft... | 那应该定义成 enum 更好吧 |
create-neat | github_2023 | typescript | 292 | xun082 | uaenaTzx | @@ -0,0 +1,106 @@
+// todo 因为文件中的函数或方法被index.cjs调用,导致无法用ts和esm导出写法
+
+// 定义 LocationCode 枚举,用于指定插件内容插入的位置
+/**
+ * 插入位置
+ * @enum
+ * @property {number} BeforeMatchStructure - 在匹配结构之前
+ * @property {number} InMatchStructure - 在匹配结构中
+ * @property {number} AfterMatchStructureImport - 在匹配结构导入之后
+ * @property {number} Aft... | 注释尽可能加上去 |
create-neat | github_2023 | typescript | 292 | xun082 | uaenaTzx | @@ -0,0 +1,106 @@
+// todo 因为文件中的函数或方法被index.cjs调用,导致无法用ts和esm导出写法
+
+// 定义 LocationCode 枚举,用于指定插件内容插入的位置
+/**
+ * 插入位置
+ * @enum
+ * @property {number} BeforeMatchStructure - 在匹配结构之前
+ * @property {number} InMatchStructure - 在匹配结构中
+ * @property {number} AfterMatchStructureImport - 在匹配结构导入之后
+ * @property {number} Aft... | 这块其实是和 AST 息息相关的,我觉得得和 AST 同学沟通一下,整理在一块 |
create-neat | github_2023 | others | 292 | xun082 | uaenaTzx | @@ -1,8 +1,61 @@
+const path = require('path');
+const protocol = require("../../../core/src/configs/protocol.ts");
+const pluginToTemplateProtocol = protocol.pluginToTemplateProtocol;
+const { applyPluginTransformation, LocationCode, RegExpMap } = require('../../../core/src/utils/transformFileData.ts')
+
+const reactM... | mobx 如果评估下来只可能对 react 造成侵入的话,是不是 ejs 更优?
可以看看是否存在对构建工具的影响 |
create-neat | github_2023 | typescript | 292 | xun082 | uaenaTzx | @@ -215,6 +215,25 @@ class PluginToTemplateAPI extends ProtocolGeneratorAPI {
console.log(error);
}
}
+
+ /**
+ * 框架类插件协议
+ * @param params
+ */
+ PROCESS_TEMPLATE_PLUGIN(params) {
+ const content = params.params.content;
+ const plugins = this.props.preset.plugins;
+ const fileData: Fil... | 这块还不能和 scss 的保持一致,因为随着插件的增多,这里的判断逻辑会越来越复杂,我想的是既然协议是在固定的插件里面触发的,那执行什么应该可以从入参去判断
比如:PROCESS_TEMPLATE_PLUGIN 被 aaa 中调用了,处理的时候,直接执行回调就行了。
processReactFiles 就统一命名为 callback 这类的 |
create-neat | github_2023 | typescript | 292 | xun082 | uaenaTzx | @@ -0,0 +1,157 @@
+// todo 因为文件中的函数或方法被index.cjs调用,导致无法用ts和esm导出写法
+
+// 定义 LocationCode 枚举,用于指定插件内容插入的位置
+/**
+ * 插入位置
+ * @enum {number}
+ * @property {number} BeforeMatchStructure - 在匹配结构之前
+ * @property {number} InMatchStructure - 在匹配结构中
+ * @property {number} AfterMatchStructureImport - 在匹配结构导入之后
+ * @property {nu... | 这种映射比较特化,如果每个插件都有很多特化会导致 regexpmap 难以维护,遇到这种情况还是尽量想着抽象一些 |
create-neat | github_2023 | others | 292 | xun082 | uaenaTzx | @@ -1,8 +1,62 @@
+const path = require('path');
+const protocol = require("../../../core/src/configs/protocol.ts");
+const { applyPluginTransformation, LocationCode, RegExpMap } = require('../../../core/src/utils/transformFileData.ts')
+
+const pluginToTemplateProtocol = protocol.pluginToTemplateProtocol;
+
+const reac... | 这个方法大部分都围绕在从 filetree 中找到目标路径,那我觉得可以把找路径的过程抽象成一个方法,这样能很大程度被复用 |
create-neat | github_2023 | others | 292 | xun082 | uaenaTzx | @@ -1,8 +1,62 @@
+const path = require('path');
+const protocol = require("../../../core/src/configs/protocol.ts");
+const { applyPluginTransformation, LocationCode, RegExpMap } = require('../../../core/src/utils/transformFileData.ts')
+
+const pluginToTemplateProtocol = protocol.pluginToTemplateProtocol;
+
+const reac... | 协议抽象,提取 mobx 对 react 的侵入特征 |
create-neat | github_2023 | others | 293 | xun082 | uaenaTzx | @@ -1,7 +1,81 @@
+const path = require("path");
+
+const protocol = require("../../../core/src/configs/protocol.ts");
+const pluginToTemplateProtocol = protocol.pluginToTemplateProtocol;
+
+/**
+ * 处理 Pinia 文件函数
+ */
+function processPiniaFiles(plugin, fileData) {
+ const importRegex = /^import.*$/gm;
+ const mountRe... | 协议这样子太特化了,我们预期的是协议复用 |
create-neat | github_2023 | others | 293 | xun082 | uaenaTzx | @@ -1,7 +1,28 @@
+const protocol = require("../../../core/src/configs/protocol.ts"); | 可以配一下 alias |
create-neat | github_2023 | typescript | 293 | xun082 | uaenaTzx | @@ -66,7 +66,7 @@ class FileTree {
describe: { fileName: path.basename(rootDirectory) },
};
// 初始化 PluginToTemplateAPI,传入所需协议
- this.pluginToTemplateAPI = new PluginToTemplateAPI({}, {});
+ this.pluginToTemplateAPI = new PluginToTemplateAPI({}, {}, {}); | 这样传不如在 PluginToTemplateAPI 设置默认值吧 |
create-neat | github_2023 | typescript | 293 | xun082 | uaenaTzx | @@ -215,6 +44,93 @@ class PluginToTemplateAPI extends ProtocolGeneratorAPI {
console.log(error);
}
}
+
+ /**
+ * Import语句插入协议
+ * @param params 包含导入信息的参数对象
+ */
+ INSERT_IMPORT(params) { | 不需要做这个判断,协议被调用就说明这个插件被引入了(所以,目标插件的协议是一定能成功地)
所以判断可以去掉,同样的,传参可以少一层
额外的,可以评估一下是否还需要 content 这一层 |
create-neat | github_2023 | typescript | 293 | xun082 | uaenaTzx | @@ -215,6 +44,93 @@ class PluginToTemplateAPI extends ProtocolGeneratorAPI {
console.log(error);
}
}
+
+ /**
+ * Import语句插入协议
+ * @param params 包含导入信息的参数对象
+ */
+ INSERT_IMPORT(params) {
+ const content = params.params.content;
+ const plugins = this.props.preset.plugins;
+ const fileDat... | 这个应该是 IMPORT 协议独有的,直接写协议处理器里面就好了 |
create-neat | github_2023 | typescript | 293 | xun082 | uaenaTzx | @@ -215,6 +44,93 @@ class PluginToTemplateAPI extends ProtocolGeneratorAPI {
console.log(error);
}
}
+
+ /**
+ * Import语句插入协议
+ * @param params 包含导入信息的参数对象
+ */
+ INSERT_IMPORT(params) {
+ const content = params.params.content;
+ const plugins = this.props.preset.plugins;
+ const fileDat... | 遍历找文件的方法我记得 @四十 抽出来过,但你们代码没对齐
这个可以提取出来的,你们可以对一下 |
create-neat | github_2023 | typescript | 293 | xun082 | uaenaTzx | @@ -10,16 +10,19 @@ import { ProtocolProps } from "../BaseAPI";
class ProtocolGeneratorAPI {
protected protocols: Record<string, object>; // todo 类型考虑优化
protected props: ProtocolProps;
+ protected protocol: any;
- constructor(protocols) {
+ constructor(protocols, props, protocol) {
this.protocols = pro... | 这样无法保证一个插件的多个协议被调用吧 |
create-neat | github_2023 | typescript | 293 | xun082 | uaenaTzx | @@ -215,6 +44,45 @@ class PluginToTemplateAPI extends ProtocolGeneratorAPI {
console.log(error);
}
}
+
+ /**
+ * Import语句插入协议
+ * @param params 包含导入信息的参数对象
+ */
+ INSERT_IMPORT(params) { | 协议内部的操作适当加一些注释,以及一些地方可以加可选链吧
比如 path.node.loc.end.line 就比较不清晰,得结合上下文看懂 |
create-neat | github_2023 | typescript | 293 | xun082 | uaenaTzx | @@ -10,9 +10,12 @@ import { ProtocolProps } from "../BaseAPI";
class ProtocolGeneratorAPI {
protected protocols: Record<string, object>; // todo 类型考虑优化
protected props: ProtocolProps;
+ protected protocol: any; | any 不好吧 |
create-neat | github_2023 | typescript | 293 | xun082 | uaenaTzx | @@ -6,12 +6,16 @@ const globalProtocol = {
const pluginToTemplateProtocol = {
...globalProtocol,
PROCESS_STYLE_PLUGIN: "PROCESS_STYLE_PLUGIN",
+ PROCESS_PINIA_PLUGIN: "PROCESS_PINIA_PLUGIN", | 那这些协议可以删了 |
create-neat | github_2023 | others | 291 | xun082 | uaenaTzx | @@ -0,0 +1,116 @@
+.container { | 这个为啥要加,本身应该在模板里面去定义的,如果写了一个 less 插件,会有重复工作 |
create-neat | github_2023 | typescript | 291 | xun082 | uaenaTzx | @@ -27,8 +36,24 @@ class BaseAPI {
// todo: jsdoc + protocols 的类型
protocolGenerate(protocols) {
- const pluginToTemplate = new PluginToTemplateAPI(protocols);
- pluginToTemplate.generator();
+ const preset = this.generator.getPreset();
+ const buildToolConfigAst = this.generator.buildToolConfigAst;
... | 那我觉得要把注释讲清楚,BaseAPI 越来越复杂了 |
create-neat | github_2023 | typescript | 291 | xun082 | uaenaTzx | @@ -103,6 +116,34 @@ class PluginToTemplateAPI extends ProtocolGeneratorAPI {
return processedContent;
}
+ PROCESS_SASS(params) {
+ const { template, plugins } = params.perset;
+ const fileData = params.files.fileData;
+ if ("sass" in plugins) { | 这里判断显得不太合适,建议从 params 里面取作用的插件是什么
如果这个协议给很多个插件使用,判断就麻烦了 |
create-neat | github_2023 | typescript | 291 | xun082 | uaenaTzx | @@ -103,6 +116,34 @@ class PluginToTemplateAPI extends ProtocolGeneratorAPI {
return processedContent;
}
+ PROCESS_SASS(params) {
+ const { template, plugins } = params.perset;
+ const fileData = params.files.fileData;
+ if ("sass" in plugins) {
+ for (let i = 0; i < fileData.children.length; i... | 这块能不能抽象(如果抽象有难度可以考虑统一模板的格式 |
create-neat | github_2023 | typescript | 291 | xun082 | uaenaTzx | @@ -103,6 +116,34 @@ class PluginToTemplateAPI extends ProtocolGeneratorAPI {
return processedContent;
}
+ PROCESS_SASS(params) { | 能不能把协议抽象,比如抽象给 sass、less 等
甚至抽象成 xx 文件的引入 |
create-neat | github_2023 | javascript | 291 | xun082 | uaenaTzx | @@ -124,6 +124,16 @@ module.exports = {
},
},
},
+ <% if (plugin ==='sass' ) { %>
+ {
+ test: /\.s[ac]ss$/i,
+ use: [
+ 'style-loader',
+ 'css-loader',
+ 'sass-loader',
+ ],
+ },
+ <% } %> | 你觉得好做不,或者把这块的诉求抛群里
目前这种协作模式我建议不要关心 xx 对 xx 协议我来做,而是 xx 插件的所有协议我来做 |
create-neat | github_2023 | others | 291 | xun082 | uaenaTzx | @@ -1,6 +1,6 @@
{
- "name": "@laconic/plugin-scss",
- "description": "scss",
+ "name": "@laconic/plugin-sass", | sass 和 scss 统一一下吧,有的地方还是 scss |
create-neat | github_2023 | typescript | 291 | xun082 | uaenaTzx | @@ -3,11 +3,20 @@ import path from "path";
import Generator from "./Generator";
import PluginToTemplateAPI from "./protocolGenerator/PluginToTemplateAPI";
+import TemplateToBuildToolAPI from "./protocolGenerator/TemplateToBuildToolAPI";
+
+const { | cjs 和 esm 语法不要混用 |
create-neat | github_2023 | typescript | 291 | xun082 | uaenaTzx | @@ -38,6 +42,19 @@ interface WriteConfigIntoTemplate {
wrapStructures?: string[];
}
+/**
+ * 样式插件参数
+ * @interface
+ * @param {Preset} preset - 用户预设
+ * @param {FileTree} files - 文件树,包含了基础的 src 目录
+ * @param {Record<'content', string>} params - 传入的 content,适用于一些需要添加字段的特殊情况。
+ */
+interface StyleParams { | 协议的传参能不能在独立的一个地方定义导出,在插件里面注册协议的时候也能保证引用
(考虑给插件的 cjs 换了吧) |
create-neat | github_2023 | typescript | 291 | xun082 | uaenaTzx | @@ -51,9 +68,12 @@ class PluginToTemplateAPI extends ProtocolGeneratorAPI {
private fileImport: RegExp = /^import.*$/gm;
// 匹配 createApp 语句
private createAppRegex: RegExp = /const\s+app\s*=\s*createApp\s*\(\s*App\s*\)/;
+ // 匹配 index.css 语句
+ private cssRegex: RegExp = /import\s+["']\.\/index\.css["'];/; | 协议多起来了的话,会很乱,这些应该在协议处理器里面维护,而不是在整个 PluginToTemplateAPI 里面 |
create-neat | github_2023 | typescript | 291 | xun082 | uaenaTzx | @@ -102,6 +130,23 @@ class PluginToTemplateAPI extends ProtocolGeneratorAPI {
return processedContent;
}
+ /**
+ * 样式类插件协议
+ * @param params
+ */
+ PROCESS_STYLE_PLUGIN(params: StyleParams) { | PROCESS_STYLE_PLUGIN 相关的全都收敛到这里去 |
create-neat | github_2023 | typescript | 291 | xun082 | uaenaTzx | @@ -83,7 +103,15 @@ class PluginToTemplateAPI extends ProtocolGeneratorAPI {
wrapStructures: ["return (%*#$)", ""],
};
- this.plugins = [reactRouter, vuePinia];
+ const sass: WriteConfigIntoTemplate = { | 也是的,太特化了
内部的抽象还是没想到好方法,我觉得你可以考虑把这些内容不抽象了,作为传参提取出去,在插件的协议里作为参数传递进来(甚至可以给个回调函数)
如果你觉得不可用的协议有优化空间,甚至可以去直接改 |
create-neat | github_2023 | typescript | 291 | xun082 | uaenaTzx | @@ -183,6 +228,31 @@ class PluginToTemplateAPI extends ProtocolGeneratorAPI {
content.slice(match.index! + match[0].length)
);
}
+
+ private processSass(fileData: FileData, template: string): FileData { | 还是要尽可能的抽象一些,参考前面评论的,实在不行作为回调函数提取出来 |
create-neat | github_2023 | typescript | 291 | xun082 | uaenaTzx | @@ -268,6 +268,7 @@ class Generator {
framework: this.templateName,
bundler: this.buildTool,
language: "typescript" in this.plugins ? "typescript" : "javascript",
+ plugin: "sass" in this.preset.plugins ? "sass" : "", | 为啥需要给 ejs 加个参数,而且加的太特化了吧 |
create-neat | github_2023 | typescript | 291 | xun082 | uaenaTzx | @@ -102,6 +123,23 @@ class PluginToTemplateAPI extends ProtocolGeneratorAPI {
return processedContent;
}
+ /**
+ * 样式类插件协议
+ * @param params
+ */
+ PROCESS_STYLE_PLUGIN() {
+ const { template, plugins } = this.props.preset;
+ const fileData: FileData = this.props.files.getFileData();
+ try {
... | 为啥要改成 sass,统一一下吧
现在有的地方 sass,有的地方 scss |
create-neat | github_2023 | typescript | 291 | xun082 | uaenaTzx | @@ -102,6 +123,23 @@ class PluginToTemplateAPI extends ProtocolGeneratorAPI {
return processedContent;
}
+ /**
+ * 样式类插件协议
+ * @param params
+ */
+ PROCESS_STYLE_PLUGIN() {
+ const { template, plugins } = this.props.preset; | 这个协议里面也不需要做额外的 plugins 判断,这是协议处理器,如果被调用了,肯定是有相关的插件去调用
那具体操作哪个插件?应该从 PROCESS_STYLE_PLUGIN() 的入参去获取 |
create-neat | github_2023 | typescript | 291 | xun082 | uaenaTzx | @@ -183,6 +221,64 @@ class PluginToTemplateAPI extends ProtocolGeneratorAPI {
content.slice(match.index! + match[0].length)
);
}
+
+ // 处理 sass 的回调函数,这里传入props 的原因是因为回调函数无法找到 API 的 this。
+ private processSass(fileData: FileData, props: ProtocolProps): FileData { | 虽然他被作为回调函数被传入,但他的定义应该在插件里面,不然这个文件会随着插件越来越多而越来越复杂
会很难维护 |
create-neat | github_2023 | others | 278 | xun082 | uaenaTzx | @@ -1,223 +1,86 @@
-## Create-Neat
-### README.md
-- zh_CN [简体中文](README.md)
-- en [English](readme/README-EN.md)
+<h1 align="center" style="font-size: 2.5em; color: #333;">Create-Neat</h1>
+<hr style="border: 1px solid #ccc;"/>
+<p align="center" style="font-size: 1.2em; color: #555; max-width: 800px; line-height:... | 要不额外开一个板块,介绍我们的社区,把这两个放进去。
因为这个不能算是这个 cn 的技术特点 |
create-neat | github_2023 | others | 278 | xun082 | uaenaTzx | @@ -1,223 +1,86 @@
-## Create-Neat
-### README.md
-- zh_CN [简体中文](README.md)
-- en [English](readme/README-EN.md)
+<h1 align="center" style="font-size: 2.5em; color: #333;">Create-Neat</h1>
+<hr style="border: 1px solid #ccc;"/>
+<p align="center" style="font-size: 1.2em; color: #555; max-width: 800px; line-height:... | 链接没有 |
create-neat | github_2023 | others | 278 | xun082 | uaenaTzx | @@ -1,223 +1,86 @@
-## Create-Neat
-### README.md
-- zh_CN [简体中文](README.md)
-- en [English](readme/README-EN.md)
+<h1 align="center" style="font-size: 2.5em; color: #333;">Create-Neat</h1>
+<hr style="border: 1px solid #ccc;"/>
+<p align="center" style="font-size: 1.2em; color: #555; max-width: 800px; line-height:... | 图片上有掘金水印 |
create-neat | github_2023 | others | 278 | xun082 | uaenaTzx | @@ -1,223 +1,89 @@
-## Create-Neat
-### README.md
-- zh_CN [简体中文](README.md)
-- en [English](readme/README-EN.md)
+<h1 align="center" style="font-size: 2.5em; color: #333;">Create-Neat</h1>
+<hr style="border: 1px solid #ccc;"/>
+<p align="center" style="font-size: 1.2em; color: #555; max-width: 800px; line-height:... | 微信群二维码会失效的,换成微信号吧 |
create-neat | github_2023 | typescript | 285 | xun082 | uaenaTzx | @@ -1,9 +1,14 @@
// 插件对框架的协议
-export const pluginToTemplateProtocol = {
+exports.pluginToTemplateProtocol = {
ENTRY_FILE: "ENTRY_FILE", // 入口文件配置,如:入口文件引入全局 less、scss
// ……
};
// 插件对构建工具的协议
-
+exports.pluginToBuildToolProtocol = {};
// 框架对构建工具的协议
+exports.templateToBuildToolProtocol = {
+ ENTRY_FILE: "ENTR... | 我感觉通用协议可以维护在一个对象里面,通过 ...XXX 的方式存入每个 protocol 中 |
create-neat | github_2023 | typescript | 285 | xun082 | uaenaTzx | @@ -3,6 +3,13 @@ import path from "path";
import Generator from "./Generator";
import PluginToTemplateAPI from "./protocolGenerator/PluginToTemplateAPI";
+import TemplateToBuildToolAPI from "./protocolGenerator/TemplateToBuildToolAPI";
+
+const { | 怎么一会 esm 一会 cjs 的写法 |
create-neat | github_2023 | typescript | 285 | xun082 | uaenaTzx | @@ -0,0 +1,76 @@
+import path from "path";
+
+import { createConfigByParseAst } from "../../utils/ast/parseAst";
+import { relativePathToRoot } from "../../utils/constants";
+
+import ProtocolGeneratorAPI from "./ProtocolGeneratorAPI";
+
+/**
+ * 框架对构建工具协议
+ * @param protocols 协议内容
+ */
+class TemplateToBuildToolAPI ex... | 强烈建议 ts 类型声明一下 |
create-neat | github_2023 | others | 285 | xun082 | uaenaTzx | @@ -7,4 +9,17 @@ module.exports = (templateAPI) => {
"vue-template-compiler": "^2.7.16",
},
});
+
+ templateAPI.protocolGenerate({
+ [templateToBuildToolProtocol.ADD_CONFIG]: {
+ params: {
+ content: {
+ buildToolName: 'webpack', //这里怎么拿选项呢? | 不应该在这里传入吧,preset 在 Generator 里面就可以拿到 |
create-neat | github_2023 | typescript | 281 | xun082 | uaenaTzx | @@ -1,7 +1,102 @@
+// 通用协议
+export const commonProtocol = { | 有问题,configs 只是定义有什么协议,但是具体做什么事情是要在插件里面做的
比如 scss,不应该在这里定义,而是在 plugin-scss 里去配置,注意看看我之前的实现视频 |
create-neat | github_2023 | typescript | 279 | xun082 | uaenaTzx | @@ -0,0 +1,24 @@
+export type BuildToolType = "webpack" | "vite" | "rollup"; | 感觉和 packages/core/src/constants/ast.ts 那块有耦合 |
create-neat | github_2023 | typescript | 279 | xun082 | uaenaTzx | @@ -0,0 +1,24 @@
+export type BuildToolType = "webpack" | "vite" | "rollup";
+
+interface Import { | 类名可以再精准一些,直接看 Import 看不出什么东西
可以用 ASTImport 之类的,提高语义 |
create-neat | github_2023 | typescript | 279 | xun082 | uaenaTzx | @@ -0,0 +1,83 @@
+import traverse from "@babel/traverse";
+import { objectExpression, stringLiteral, arrayExpression } from "@babel/types";
+
+import type { Plugin } from "../../../types/ast";
+import { Build_Tool } from "../../../constants/ast";
+import {
+ createImportDeclaration,
+ createCallExpression,
+ createO... | 应该是 VitePackAst 吧 |
create-neat | github_2023 | typescript | 279 | xun082 | uaenaTzx | @@ -0,0 +1,112 @@
+import traverse from "@babel/traverse";
+import { objectExpression, regExpLiteral, stringLiteral, arrayExpression } from "@babel/types";
+
+import { Build_Tool } from "../../../constants/ast";
+import { createObjectProperty, createNewExpression } from "../uno/commonAst";
+
+import { BaseAst } from ".... | 这块感觉可以抽离出来,我看有复用 |
create-neat | github_2023 | typescript | 279 | xun082 | uaenaTzx | @@ -0,0 +1,112 @@
+import traverse from "@babel/traverse";
+import { objectExpression, regExpLiteral, stringLiteral, arrayExpression } from "@babel/types";
+
+import { Build_Tool } from "../../../constants/ast";
+import { createObjectProperty, createNewExpression } from "../uno/commonAst";
+
+import { BaseAst } from ".... | 这个函数可以注释的更清楚一些,我看着有些迷糊 |
create-neat | github_2023 | others | 248 | xun082 | uaenaTzx | @@ -0,0 +1,9 @@
+module.exports = (generatorAPI) => {
+ generatorAPI.extendPackage({
+ devDependencies: {
+ "element-plus": "^2.7.8",
+ "unplugin-auto-import": "^0.18.2", | 为什么需要两个 unplugin 的插件 |
create-neat | github_2023 | others | 248 | xun082 | uaenaTzx | @@ -0,0 +1,4 @@
+{
+ "recommendations": ["Vue.volar"] | 这个为什么要做 |
create-neat | github_2023 | typescript | 274 | xun082 | uaenaTzx | @@ -166,16 +166,28 @@ async function projectSelect() {
],
};
+ const useSpecilPligins = await select({ | 感觉可以进一步优化一下
从用户直觉,看特殊插件,其实看不出来有啥,那也不好做选择,那么最好就把这个选择合并到下面的 specialPlugins 里面去,高亮显示 |
create-neat | github_2023 | typescript | 276 | xun082 | IsDyh01 | @@ -225,14 +225,14 @@ class FileTree {
*/
async renderAllFiles(parentDir: string, fileData: FileData = this.fileData) {
// 渲染根fileTree对象中的children中的内容 --> 根目录内的文件
- fileData.children.forEach(async (item: FileData) => {
+ for (const item of fileData.children) { | 为什么要把forEach替换成for of? |
create-neat | github_2023 | others | 267 | xun082 | uaenaTzx | @@ -5,4 +5,5 @@
rollup.config.js
commitlint.config.js
packages/*/dist/
-apps/
\ No newline at end of file
+apps/
+packages/core/src/**/webpack.config.ejs | ejs 格式不需要忽略,忽略的应该是 文件格式不是 ejs 但是写了 ejs 语法的 |
create-neat | github_2023 | typescript | 258 | xun082 | uaenaTzx | @@ -126,15 +126,21 @@ export default async function createAppTest(projectName: string, options: Record
}
// 2. 初始化构建工具配置文件
+ | hack 的只是一个 element-plus,不应该把整个配置都拿出来 |
create-neat | github_2023 | typescript | 258 | xun082 | uaenaTzx | @@ -1,18 +1,7 @@
import ejs from "ejs";
-import { buildToolType } from "../types";
-
-export default function generateWebpackConfigFromEJS(
- framework: string,
- bundler: buildToolType,
- language: string,
- template: string,
-) {
- const config = ejs.render(template, {
- framework,
- bundler,
- langu... | 虽然不影响使用,但是这个命名标准没对上
generateBuildToolConfigFromEJS、generateWebpackConfigFromEJS |
create-neat | github_2023 | others | 258 | xun082 | uaenaTzx | @@ -104,7 +114,7 @@ const productionPlugins = isProduction ? [
module.exports = {
stats: 'errors-warnings',
- entry: '<% if (framework === "react") { %><% if (language === "typescript" || (bundler === "swc" && language === "typescript")) { %>./src/index.tsx<% } else if (language === "javascript" || (bundler === ... | 首先这个格式太乱了,该换行的换行,其次这样的判断可读性、维护性都很差,可以参考这种方式:
<%
const paths = {
react: {
typescript: "./src/index.tsx",
javascript: "./src/index.jsx",
},
vue: {
typescript: "./src/main.ts",
javascript: "./src/main.js",
}
};
// 默认路径(如果框架或者语言不匹配)
const defaultPath = "./src/... |
create-neat | github_2023 | typescript | 259 | xun082 | uaenaTzx | @@ -107,65 +112,116 @@ class FileTree {
return file;
}
+ /**
+ * 借助ejs构造文件树对象
+ * @static | static 和 private 不对应
|
create-neat | github_2023 | typescript | 259 | xun082 | uaenaTzx | @@ -107,65 +112,116 @@ class FileTree {
return file;
}
+ /**
+ * 借助ejs构造文件树对象
+ * @static
+ * @param {string} src - 文件或文件夹的真实路径
+ * @param {string} parentDir - 创建文件后的父文件夹路径
+ * @param {string} options - ejs渲染配置参数
+ * @returns {FileData} - 文件树对象
+ */
+ private buildFileDataByEjs(src: string, pa... | 用不到了就删了? |
create-neat | github_2023 | typescript | 254 | xun082 | uaenaTzx | @@ -283,6 +286,8 @@ class Generator {
useReactRouter: !!this.preset.plugins["react-router"],
},
};
+ console.log(111); | 日志 |
create-neat | github_2023 | typescript | 249 | xun082 | uaenaTzx | @@ -265,6 +266,7 @@ class Generator {
`template-${this.templateName}/generator/template`,
);
+ const preset = await projectSelect(); | preset 从 Generator 的 Constructor 里面传进来吧,前面群里说的 |
create-neat | github_2023 | javascript | 246 | xun082 | uaenaTzx | @@ -0,0 +1,95 @@
+// App.js.ejs
+import React from "react"; | 这个文件如果加进去了,会和 template-react 冲突吧,之前说是在 ejs 渲染阶段传入 router 是否使用的一个参数,然后控制 template-reat 中的代码片段是否展示(ejs) |
create-neat | github_2023 | typescript | 246 | xun082 | uaenaTzx | @@ -176,7 +176,7 @@ class FileTree {
*/
async fileRender(src: string, file: FileData, options: any) {
const rendered = ejs.render(file.describe?.fileContent, options, {});
- await fs.writeFile(src, rendered);
+ await fs.writeFile(src, rendered,{flag: 'w'}); | 这个新增是为了什么 |
create-neat | github_2023 | typescript | 226 | xun082 | IsDyh01 | @@ -4,12 +4,12 @@ import { exec } from "child_process";
import { confirm } from "@clack/prompts";
import chalk from "chalk";
import { parse } from "@babel/parser";
-import path from "path";
+import path, { join } from "path"; | 这个直接用path.join()不用再引入了吧 |
create-neat | github_2023 | typescript | 225 | xun082 | uaenaTzx | @@ -151,6 +151,33 @@ async function projectSelect() {
required: false,
})) as string[];
+ // 根据不同框架加载对应的插件列表 | 这一步的逻辑可以抽象出来,比如用一个 map
vue => {
plugins:[
{key,value}
],
description:“xxxxx”
} |
create-neat | github_2023 | others | 225 | xun082 | uaenaTzx | @@ -0,0 +1,9 @@
+module.exports = (generatorAPI) => {
+ generatorAPI.extendPackage({
+ devDependencies: {
+ mobx: "^6.6.4",
+ "mobx-react":"^7.4.0",
+ },
+ });
+};
+ | template 文件里写一个初始配置,同时要确保生成的项目可以跑通 |
create-neat | github_2023 | others | 222 | xun082 | uaenaTzx | @@ -0,0 +1,158 @@
+// @see: https://cz-git.qbenben.com/zh/guide | 这个文件默认不需要配置那么多的,要考虑到初学者用户,这些配置反而造成复杂度和心智负担 |
create-neat | github_2023 | others | 222 | xun082 | uaenaTzx | @@ -0,0 +1,158 @@
+// @see: https://cz-git.qbenben.com/zh/guide
+/** @type {import('cz-git').UserConfig} */ | 插入用户路径的文件后缀用 cjs 不太好,用户应该默认 js 的 |
create-neat | github_2023 | others | 222 | xun082 | uaenaTzx | @@ -0,0 +1,26 @@
+module.exports = (generatorAPI) => {
+ generatorAPI.extendPackage({
+ scripts: {
+ prepare: "husky",
+ commit: "git-cz",
+ format: 'prettier --write "src/**/*.{js,jsx,ts,tsx,json,css,scss,md}"',
+ lint: 'eslint "**/*.{ts,tsx,js,jsx}" --fix', | husky 不应该有 script,就只要 lint-stage 就行了
|
create-neat | github_2023 | others | 222 | xun082 | uaenaTzx | @@ -0,0 +1,26 @@
+module.exports = (generatorAPI) => {
+ generatorAPI.extendPackage({
+ scripts: {
+ prepare: "husky",
+ commit: "git-cz",
+ format: 'prettier --write "src/**/*.{js,jsx,ts,tsx,json,css,scss,md}"',
+ lint: 'eslint "**/*.{ts,tsx,js,jsx}" --fix',
+ },
+ config: {
+ commit... | 这些依赖也确认一下,像 cz-git 这些,是没必要的功能 |
create-neat | github_2023 | others | 203 | xun082 | IsDyh01 | @@ -10,7 +10,7 @@ module.exports = {
cacheDirectory: true,
cacheCompression: false,
presets: [],
- // plugins: [require.resolve("react-refresh/babel")].filter(Boolean),
+ plugins: ["react-refresh/babel"], | 这个插件需要在generator/index.cjs里边得依赖写一下吗,安装的时候去下载 |
create-neat | github_2023 | others | 201 | xun082 | IsDyh01 | @@ -1,27 +1,66 @@
+// 通用的Babel预设和插件
+const commonBabelPresets = [
+ [
+ "@babel/preset-env",
+ {
+ useBuiltIns: "usage",
+ corejs: 3,
+ },
+ ],
+ "@babel/preset-typescript",
+];
+
+const commonBabelPlugins = [
+ "@babel/plugin-transform-runtime",
+ "@babel/plugin-syntax-dynamic-import",
+];
+
+/... | 这种结构extendPackage方法扩展pkg会有问题 |
create-neat | github_2023 | typescript | 182 | xun082 | uaenaTzx | @@ -31,3 +31,11 @@ export interface PackageJsonType {
}
export type buildToolType = "webpack" | "vite" | "rollup";
+ | 昨天说的就是这一块,没必要的 |
create-neat | github_2023 | typescript | 186 | xun082 | uaenaTzx | @@ -186,8 +225,22 @@ class FileTree {
*/
addToTreeByPath(path: string) {
this.fileData.children.push(FileTree.buildFileData(path));
- //根据process.env.isTs更改后缀
- process.env.isTs && this.changeFileExtensionToTs();
+ //如果有 ts 插件则更改相关文件后缀
+ function handleExt(file: FileData) { | 和 73 行重复了,仔细看看 |
create-neat | github_2023 | typescript | 190 | xun082 | xun082 | @@ -20,7 +23,11 @@ export async function removeDirectory(
*/
async function deleteDirectory() {
try {
- await fs.remove(fullPath);
+ if (CLIENT_OS === "mac") { | const platform:NodeJS.Platform = process.platform;
if(platform==="linux"){
xxx
}else{
xxx
}
直接在这里不是更间接吗,为什么还要额外封装函数 |
create-neat | github_2023 | typescript | 191 | xun082 | xun082 | @@ -163,7 +166,19 @@ export default async function createAppTest(projectName: string, options: Record
"README-EN.md": createReadmeString(packageManager, template, "README-EN.md"),
});
- createSuccessInfo(projectName, "npm");
+ // 添加.gitignore
+ console.log(chalk.blue(`\n📄 Generating gitignore...`));
+
+ ... | 用resolveApp这个函数来读取路径,在utils包封装有 |
create-neat | github_2023 | typescript | 184 | xun082 | uaenaTzx | @@ -0,0 +1,65 @@
+import fs from "fs";
+import path from "node:path";
+import os from "os";
+import process from "process";
+import chalk from "chalk";
+
+import { Preset } from "./preset";
+
+/**
+ * @description 获取用户系统主目录下保存预设的文件路径 | @description 按照规范是不需要的,直接说函数作用即可 |
create-neat | github_2023 | others | 175 | xun082 | xun082 | @@ -0,0 +1,6 @@
+module.exports = (templateAPI) => {
+ templateAPI.extendPackage({
+ dependencies: {}, | 添加一下相关的依赖,react这些 |
create-neat | github_2023 | others | 176 | xun082 | uaenaTzx | @@ -0,0 +1,15 @@
+
+const PluginConfig = require('./generator/index.cjs')
+
+
+const pluginPrettier = (buildTool)=>{
+
+ | 无用的空行 |
create-neat | github_2023 | others | 176 | xun082 | uaenaTzx | @@ -1,18 +1,22 @@
module.exports = (generatorAPI) => {
generatorAPI.extendPackage({
prettier: {
- singleQuote: false,
- tabWidth: 2,
- arrowParens: "always",
- bracketSpacing: true,
- proseWrap: "preserve",
- trailingComma: "all",
- jsxSingleQuote: false,
- printWidth: 1... | 这个不是必要依赖,得考虑后续在依赖处理中间件再做 |
create-neat | github_2023 | others | 179 | xun082 | uaenaTzx | @@ -0,0 +1,6 @@
+module.exports = (templateAPI) => {
+ templateAPI.extendPackage({ | vue 这些依赖需要加 |
create-neat | github_2023 | others | 179 | xun082 | uaenaTzx | @@ -0,0 +1,12 @@
+module.exports = (templateAPI) => {
+ templateAPI.extendPackage({
+ dependencies: {
+ vue: "^3.2.47",
+ },
+ devDependencies: {
+ "vue-template-compiler": "^3.2.47",
+ "css-loader": "^6.7.3", | 为啥要 css 相关的依赖 |
create-neat | github_2023 | typescript | 170 | xun082 | uaenaTzx | @@ -197,6 +198,58 @@ class Generator {
}
}
+ // 单独处理一个框架相关文件 | 这一块不要写死吧,而且和 pluginGenerate 有很大程度的耦合,看看能不能解藕操作一下? |
create-neat | github_2023 | typescript | 170 | xun082 | xun082 | @@ -0,0 +1,136 @@
+import Generator from "./Generator";
+import fs from "fs";
+import path from "path";
+
+interface ConfigFileData {
+ file: Record<string, string[]>;
+}
+
+/**
+ * 通用类,为 generator 和 template 提供 API
+ * @param plugin 插件名
+ * @param generator 生成器实例
+ * @param options 传入的生成器选项
+ * @param rootOptions 根目录... | ts类型尽量别写Object |
create-neat | github_2023 | typescript | 170 | xun082 | xun082 | @@ -0,0 +1,136 @@
+import Generator from "./Generator";
+import fs from "fs";
+import path from "path";
+
+interface ConfigFileData {
+ file: Record<string, string[]>;
+}
+
+/**
+ * 通用类,为 generator 和 template 提供 API
+ * @param plugin 插件名
+ * @param generator 生成器实例
+ * @param options 传入的生成器选项
+ * @param rootOptions 根目录... | 对象判断严谨一点,万一是个null呢,用typeof不太严谨 |
create-neat | github_2023 | typescript | 165 | xun082 | uaenaTzx | @@ -0,0 +1,135 @@
+import Generator from "./Generator";
+import fs from 'fs'
+import path from 'path';
+
+interface ConfigFileData{
+ file:Record<string,string[]>;
+}
+
+/**
+ * @description 通用类,为 generator 和 template 提供 API | @description 去掉,只要说明作用就好了 |
create-neat | github_2023 | typescript | 165 | xun082 | uaenaTzx | @@ -0,0 +1,135 @@
+import Generator from "./Generator";
+import fs from 'fs'
+import path from 'path';
+
+interface ConfigFileData{
+ file:Record<string,string[]>;
+}
+
+/**
+ * @description 通用类,为 generator 和 template 提供 API
+ * @param plugin 插件名
+ * @param generator 生成器实例
+ * @param options 传入的生成器选项
+ * @param root... | 这里看起来没有 prettier 格式化 |
create-neat | github_2023 | typescript | 165 | xun082 | uaenaTzx | @@ -0,0 +1,135 @@
+import Generator from "./Generator";
+import fs from 'fs'
+import path from 'path';
+
+interface ConfigFileData{
+ file:Record<string,string[]>;
+}
+
+/**
+ * @description 通用类,为 generator 和 template 提供 API
+ * @param plugin 插件名
+ * @param generator 生成器实例
+ * @param options 传入的生成器选项
+ * @param root... | 既然 extendPackage 已经满足了 addScrip 这类的插入,那就不用这样冗余了 |
create-neat | github_2023 | typescript | 165 | xun082 | uaenaTzx | @@ -1,80 +1,15 @@
-import fs from "fs";
-import path from "path";
-
+import BaseAPI from "./BaseAPI";
import Generator from "./Generator";
/**
* @description 为执行 generator 提供系一列 api
- * @param plugin 插件名
- * @param generator 生成器实例
- * @param options 传入的生成器选项
- * @param rootOptions 根目录执行选项
+ * @param generator Gen... | 不确定只用 super 能否实现一些特化的内容哈,可以看看是否需要根据 插件和框架 的不同,做一些方法的重写(目前看应该不需要)
如果判断后续都没有特化逻辑,其实现在就不需要统一父类,只留一个类就可以了,这个需要你再看一下 |
create-neat | github_2023 | others | 165 | xun082 | uaenaTzx | @@ -34,6 +34,7 @@
"ts"
],
"dependencies": {
+ "@angular/cli": "^15.2.11", | 为啥需要这个包 |
create-neat | github_2023 | typescript | 165 | xun082 | uaenaTzx | @@ -110,7 +116,7 @@ async function loadModule(modulePath: string, rootDirectory: string) {
class Generator {
private rootDirectory: string;
private plugins: Record<string, any>;
- private files: FileTree; // 键:文件名,值:文件内容
+ private files: Record<string, string> = {}; // 键:文件名,值:文件内容 | 明显是合并出现问题了, private files: FileTree 才是更新的内容 |
create-neat | github_2023 | typescript | 177 | xun082 | uaenaTzx | @@ -105,6 +106,15 @@ export default async function createAppTest(projectName: string, options: Record
sourceType: "module",
});
+ // 根据构建工具为 package.json 新增不同的依赖
+
+ if (buildTool === "webpack") { | 可以写个抽象一点的?webpack、vite…… |
create-neat | github_2023 | typescript | 177 | xun082 | uaenaTzx | @@ -29,3 +29,5 @@ export interface PackageJsonType {
config?: { [key: string]: any };
"lint-staged"?: { [globPattern: string]: string | string[] };
}
+
+export type buildToolType = "webpack" | "vite" | "rollup"; | 这个直接根据预设的构建工具的值消费就好了,不用额外搞个 Type 吧 |
create-neat | github_2023 | others | 172 | xun082 | uaenaTzx | @@ -0,0 +1,76 @@
+import "./App.css";
+
+function App() { | 应该参考 test 这个模版:

文件结构参照这个来 |
create-neat | github_2023 | others | 172 | xun082 | uaenaTzx | @@ -0,0 +1,76 @@
+import "./App.css";
+
+function App() {
+ return ( | 文件格式不用 ejs,按照原本的 jsx、css 来就可以了
我理解格式:
index.css
index.jsx |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.