@baeta/plugin-gitignore 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/index.cjs +54 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/package.json +62 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @baeta/plugin-gitignore
|
|
2
|
+
|
|
3
|
+
## 0.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#117](https://github.com/andreisergiu98/baeta/pull/117) [`18db339`](https://github.com/andreisergiu98/baeta/commit/18db339719aa309c619372d2161c5fdbc08fa316) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - create gitignore plugin
|
|
8
|
+
|
|
9
|
+
- [#119](https://github.com/andreisergiu98/baeta/pull/119) [`643a2eb`](https://github.com/andreisergiu98/baeta/commit/643a2eb17c2789cd25361ddeede149a0e459e68a) Thanks [@andreisergiu98](https://github.com/andreisergiu98)! - update dependencies
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`18db339`](https://github.com/andreisergiu98/baeta/commit/18db339719aa309c619372d2161c5fdbc08fa316), [`643a2eb`](https://github.com/andreisergiu98/baeta/commit/643a2eb17c2789cd25361ddeede149a0e459e68a)]:
|
|
12
|
+
- @baeta/generator-sdk@0.0.11
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
|
|
2
|
+
var _generatorsdk = require('@baeta/generator-sdk');
|
|
3
|
+
var _promises = require('fs/promises');
|
|
4
|
+
var _path = require('path');
|
|
5
|
+
function gitignorePlugin() {
|
|
6
|
+
return _generatorsdk.createPluginV1.call(void 0, {
|
|
7
|
+
name: "gitignore-plugin",
|
|
8
|
+
actionName: "add generated files to .gitignore",
|
|
9
|
+
generate: async (ctx, next) => {
|
|
10
|
+
await next();
|
|
11
|
+
const filePaths = ctx.fileManager.files.map((file2) => file2.filename);
|
|
12
|
+
const modulesDir = ctx.generatorOptions.modulesDir;
|
|
13
|
+
const moduleDefinitionName = ctx.generatorOptions.moduleDefinitionName;
|
|
14
|
+
const generatedPaths = filePaths.map((file2) => _path.relative.call(void 0, ctx.generatorOptions.cwd, file2)).filter((file2) => !file2.endsWith(moduleDefinitionName));
|
|
15
|
+
generatedPaths.push(
|
|
16
|
+
`${_path.relative.call(void 0, ctx.generatorOptions.cwd, modulesDir)}/**/${moduleDefinitionName}`
|
|
17
|
+
);
|
|
18
|
+
generatedPaths.sort((a, b) => a.localeCompare(b));
|
|
19
|
+
const gitignoreStart = "# Generated by Baeta - Begin";
|
|
20
|
+
const gitignoreInner = generatedPaths.join("\n");
|
|
21
|
+
const gitignoreEnd = "# Generated by Baeta - End";
|
|
22
|
+
const gitignoreContent = `${gitignoreStart}
|
|
23
|
+
${gitignoreInner}
|
|
24
|
+
${gitignoreEnd}`;
|
|
25
|
+
const file = new (0, _generatorsdk.File)(".gitignore", "", "gitignore", {
|
|
26
|
+
addEslintDisableHeader: false,
|
|
27
|
+
addGenerationNoticeHeader: false
|
|
28
|
+
});
|
|
29
|
+
const exists = await _promises.stat.call(void 0, _path.resolve.call(void 0, ctx.generatorOptions.cwd, ".gitignore")).then(() => true).catch(() => false);
|
|
30
|
+
if (!exists) {
|
|
31
|
+
file.content = gitignoreContent;
|
|
32
|
+
return file.write();
|
|
33
|
+
}
|
|
34
|
+
const currentContent = await _promises.readFile.call(void 0,
|
|
35
|
+
_path.resolve.call(void 0, ctx.generatorOptions.cwd, ".gitignore"),
|
|
36
|
+
"utf-8"
|
|
37
|
+
);
|
|
38
|
+
const startMarkerIndex = currentContent.indexOf(gitignoreStart);
|
|
39
|
+
const endMarkerIndex = currentContent.indexOf(gitignoreEnd);
|
|
40
|
+
if (startMarkerIndex === -1 || endMarkerIndex === -1) {
|
|
41
|
+
file.content = `${currentContent}
|
|
42
|
+
|
|
43
|
+
${gitignoreContent}`;
|
|
44
|
+
return file.write();
|
|
45
|
+
}
|
|
46
|
+
file.content = currentContent.slice(0, startMarkerIndex) + gitignoreContent + currentContent.slice(endMarkerIndex + gitignoreEnd.length);
|
|
47
|
+
return file.write();
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
exports.gitignorePlugin = gitignorePlugin;
|
|
54
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../index.ts"],"names":["file"],"mappings":";AAAA,SAAS,gBAAgB,YAAY;AACrC,SAAS,UAAU,YAAY;AAC/B,SAAS,UAAU,eAAe;AAE3B,SAAS,kBAAkB;AAChC,SAAO,eAAe;AAAA,IACpB,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,UAAU,OAAO,KAAK,SAAS;AAC7B,YAAM,KAAK;AAEX,YAAM,YAAY,IAAI,YAAY,MAAM,IAAI,CAACA,UAASA,MAAK,QAAQ;AACnE,YAAM,aAAa,IAAI,iBAAiB;AACxC,YAAM,uBAAuB,IAAI,iBAAiB;AAElD,YAAM,iBAAiB,UACpB,IAAI,CAACA,UAAS,SAAS,IAAI,iBAAiB,KAAKA,KAAI,CAAC,EACtD,OAAO,CAACA,UAAS,CAACA,MAAK,SAAS,oBAAoB,CAAC;AAExD,qBAAe;AAAA,QACb,GAAG,SAAS,IAAI,iBAAiB,KAAK,UAAU,CAAC,OAAO,oBAAoB;AAAA,MAC9E;AAEA,qBAAe,KAAK,CAAC,GAAG,MAAM,EAAE,cAAc,CAAC,CAAC;AAEhD,YAAM,iBAAiB;AACvB,YAAM,iBAAiB,eAAe,KAAK,IAAI;AAC/C,YAAM,eAAe;AACrB,YAAM,mBAAmB,GAAG,cAAc;AAAA,EAAK,cAAc;AAAA,EAAK,YAAY;AAI9E,YAAM,OAAO,IAAI,KAAK,cAAc,IAAI,aAAa;AAAA,QACnD,wBAAwB;AAAA,QACxB,2BAA2B;AAAA,MAC7B,CAAC;AAED,YAAM,SAAS,MAAM,KAAK,QAAQ,IAAI,iBAAiB,KAAK,YAAY,CAAC,EACtE,KAAK,MAAM,IAAI,EACf,MAAM,MAAM,KAAK;AAEpB,UAAI,CAAC,QAAQ;AACX,aAAK,UAAU;AACf,eAAO,KAAK,MAAM;AAAA,MACpB;AAEA,YAAM,iBAAiB,MAAM;AAAA,QAC3B,QAAQ,IAAI,iBAAiB,KAAK,YAAY;AAAA,QAC9C;AAAA,MACF;AAEA,YAAM,mBAAmB,eAAe,QAAQ,cAAc;AAC9D,YAAM,iBAAiB,eAAe,QAAQ,YAAY;AAE1D,UAAI,qBAAqB,MAAM,mBAAmB,IAAI;AACpD,aAAK,UAAU,GAAG,cAAc;AAAA;AAAA,EAAO,gBAAgB;AACvD,eAAO,KAAK,MAAM;AAAA,MACpB;AAEA,WAAK,UACH,eAAe,MAAM,GAAG,gBAAgB,IACxC,mBACA,eAAe,MAAM,iBAAiB,aAAa,MAAM;AAE3D,aAAO,KAAK,MAAM;AAAA,IACpB;AAAA,EACF,CAAC;AACH","sourcesContent":["import { createPluginV1, File } from '@baeta/generator-sdk';\nimport { readFile, stat } from 'node:fs/promises';\nimport { relative, resolve } from 'node:path';\n\nexport function gitignorePlugin() {\n return createPluginV1({\n name: 'gitignore-plugin',\n actionName: 'add generated files to .gitignore',\n generate: async (ctx, next) => {\n await next();\n\n const filePaths = ctx.fileManager.files.map((file) => file.filename);\n const modulesDir = ctx.generatorOptions.modulesDir;\n const moduleDefinitionName = ctx.generatorOptions.moduleDefinitionName;\n\n const generatedPaths = filePaths\n .map((file) => relative(ctx.generatorOptions.cwd, file))\n .filter((file) => !file.endsWith(moduleDefinitionName));\n\n generatedPaths.push(\n `${relative(ctx.generatorOptions.cwd, modulesDir)}/**/${moduleDefinitionName}`,\n );\n\n generatedPaths.sort((a, b) => a.localeCompare(b));\n\n const gitignoreStart = '# Generated by Baeta - Begin';\n const gitignoreInner = generatedPaths.join('\\n');\n const gitignoreEnd = '# Generated by Baeta - End';\n const gitignoreContent = `${gitignoreStart}\\n${gitignoreInner}\\n${gitignoreEnd}`;\n\n // We are making an exception for .gitignore and we won't add it to file manager.\n // Since it can be edited by the user, we won't track it in the file manager and we won't delete it if the plugin is disabled.\n const file = new File('.gitignore', '', 'gitignore', {\n addEslintDisableHeader: false,\n addGenerationNoticeHeader: false,\n });\n\n const exists = await stat(resolve(ctx.generatorOptions.cwd, '.gitignore'))\n .then(() => true)\n .catch(() => false);\n\n if (!exists) {\n file.content = gitignoreContent;\n return file.write();\n }\n\n const currentContent = await readFile(\n resolve(ctx.generatorOptions.cwd, '.gitignore'),\n 'utf-8',\n );\n\n const startMarkerIndex = currentContent.indexOf(gitignoreStart);\n const endMarkerIndex = currentContent.indexOf(gitignoreEnd);\n\n if (startMarkerIndex === -1 || endMarkerIndex === -1) {\n file.content = `${currentContent}\\n\\n${gitignoreContent}`;\n return file.write();\n }\n\n file.content =\n currentContent.slice(0, startMarkerIndex) +\n gitignoreContent +\n currentContent.slice(endMarkerIndex + gitignoreEnd.length);\n\n return file.write();\n },\n });\n}\n"]}
|
package/dist/index.d.cts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// index.ts
|
|
2
|
+
import { createPluginV1, File } from "@baeta/generator-sdk";
|
|
3
|
+
import { readFile, stat } from "node:fs/promises";
|
|
4
|
+
import { relative, resolve } from "node:path";
|
|
5
|
+
function gitignorePlugin() {
|
|
6
|
+
return createPluginV1({
|
|
7
|
+
name: "gitignore-plugin",
|
|
8
|
+
actionName: "add generated files to .gitignore",
|
|
9
|
+
generate: async (ctx, next) => {
|
|
10
|
+
await next();
|
|
11
|
+
const filePaths = ctx.fileManager.files.map((file2) => file2.filename);
|
|
12
|
+
const modulesDir = ctx.generatorOptions.modulesDir;
|
|
13
|
+
const moduleDefinitionName = ctx.generatorOptions.moduleDefinitionName;
|
|
14
|
+
const generatedPaths = filePaths.map((file2) => relative(ctx.generatorOptions.cwd, file2)).filter((file2) => !file2.endsWith(moduleDefinitionName));
|
|
15
|
+
generatedPaths.push(
|
|
16
|
+
`${relative(ctx.generatorOptions.cwd, modulesDir)}/**/${moduleDefinitionName}`
|
|
17
|
+
);
|
|
18
|
+
generatedPaths.sort((a, b) => a.localeCompare(b));
|
|
19
|
+
const gitignoreStart = "# Generated by Baeta - Begin";
|
|
20
|
+
const gitignoreInner = generatedPaths.join("\n");
|
|
21
|
+
const gitignoreEnd = "# Generated by Baeta - End";
|
|
22
|
+
const gitignoreContent = `${gitignoreStart}
|
|
23
|
+
${gitignoreInner}
|
|
24
|
+
${gitignoreEnd}`;
|
|
25
|
+
const file = new File(".gitignore", "", "gitignore", {
|
|
26
|
+
addEslintDisableHeader: false,
|
|
27
|
+
addGenerationNoticeHeader: false
|
|
28
|
+
});
|
|
29
|
+
const exists = await stat(resolve(ctx.generatorOptions.cwd, ".gitignore")).then(() => true).catch(() => false);
|
|
30
|
+
if (!exists) {
|
|
31
|
+
file.content = gitignoreContent;
|
|
32
|
+
return file.write();
|
|
33
|
+
}
|
|
34
|
+
const currentContent = await readFile(
|
|
35
|
+
resolve(ctx.generatorOptions.cwd, ".gitignore"),
|
|
36
|
+
"utf-8"
|
|
37
|
+
);
|
|
38
|
+
const startMarkerIndex = currentContent.indexOf(gitignoreStart);
|
|
39
|
+
const endMarkerIndex = currentContent.indexOf(gitignoreEnd);
|
|
40
|
+
if (startMarkerIndex === -1 || endMarkerIndex === -1) {
|
|
41
|
+
file.content = `${currentContent}
|
|
42
|
+
|
|
43
|
+
${gitignoreContent}`;
|
|
44
|
+
return file.write();
|
|
45
|
+
}
|
|
46
|
+
file.content = currentContent.slice(0, startMarkerIndex) + gitignoreContent + currentContent.slice(endMarkerIndex + gitignoreEnd.length);
|
|
47
|
+
return file.write();
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
export {
|
|
52
|
+
gitignorePlugin
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../index.ts"],"sourcesContent":["import { createPluginV1, File } from '@baeta/generator-sdk';\nimport { readFile, stat } from 'node:fs/promises';\nimport { relative, resolve } from 'node:path';\n\nexport function gitignorePlugin() {\n return createPluginV1({\n name: 'gitignore-plugin',\n actionName: 'add generated files to .gitignore',\n generate: async (ctx, next) => {\n await next();\n\n const filePaths = ctx.fileManager.files.map((file) => file.filename);\n const modulesDir = ctx.generatorOptions.modulesDir;\n const moduleDefinitionName = ctx.generatorOptions.moduleDefinitionName;\n\n const generatedPaths = filePaths\n .map((file) => relative(ctx.generatorOptions.cwd, file))\n .filter((file) => !file.endsWith(moduleDefinitionName));\n\n generatedPaths.push(\n `${relative(ctx.generatorOptions.cwd, modulesDir)}/**/${moduleDefinitionName}`,\n );\n\n generatedPaths.sort((a, b) => a.localeCompare(b));\n\n const gitignoreStart = '# Generated by Baeta - Begin';\n const gitignoreInner = generatedPaths.join('\\n');\n const gitignoreEnd = '# Generated by Baeta - End';\n const gitignoreContent = `${gitignoreStart}\\n${gitignoreInner}\\n${gitignoreEnd}`;\n\n // We are making an exception for .gitignore and we won't add it to file manager.\n // Since it can be edited by the user, we won't track it in the file manager and we won't delete it if the plugin is disabled.\n const file = new File('.gitignore', '', 'gitignore', {\n addEslintDisableHeader: false,\n addGenerationNoticeHeader: false,\n });\n\n const exists = await stat(resolve(ctx.generatorOptions.cwd, '.gitignore'))\n .then(() => true)\n .catch(() => false);\n\n if (!exists) {\n file.content = gitignoreContent;\n return file.write();\n }\n\n const currentContent = await readFile(\n resolve(ctx.generatorOptions.cwd, '.gitignore'),\n 'utf-8',\n );\n\n const startMarkerIndex = currentContent.indexOf(gitignoreStart);\n const endMarkerIndex = currentContent.indexOf(gitignoreEnd);\n\n if (startMarkerIndex === -1 || endMarkerIndex === -1) {\n file.content = `${currentContent}\\n\\n${gitignoreContent}`;\n return file.write();\n }\n\n file.content =\n currentContent.slice(0, startMarkerIndex) +\n gitignoreContent +\n currentContent.slice(endMarkerIndex + gitignoreEnd.length);\n\n return file.write();\n },\n });\n}\n"],"mappings":";AAAA,SAAS,gBAAgB,YAAY;AACrC,SAAS,UAAU,YAAY;AAC/B,SAAS,UAAU,eAAe;AAE3B,SAAS,kBAAkB;AAChC,SAAO,eAAe;AAAA,IACpB,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,UAAU,OAAO,KAAK,SAAS;AAC7B,YAAM,KAAK;AAEX,YAAM,YAAY,IAAI,YAAY,MAAM,IAAI,CAACA,UAASA,MAAK,QAAQ;AACnE,YAAM,aAAa,IAAI,iBAAiB;AACxC,YAAM,uBAAuB,IAAI,iBAAiB;AAElD,YAAM,iBAAiB,UACpB,IAAI,CAACA,UAAS,SAAS,IAAI,iBAAiB,KAAKA,KAAI,CAAC,EACtD,OAAO,CAACA,UAAS,CAACA,MAAK,SAAS,oBAAoB,CAAC;AAExD,qBAAe;AAAA,QACb,GAAG,SAAS,IAAI,iBAAiB,KAAK,UAAU,CAAC,OAAO,oBAAoB;AAAA,MAC9E;AAEA,qBAAe,KAAK,CAAC,GAAG,MAAM,EAAE,cAAc,CAAC,CAAC;AAEhD,YAAM,iBAAiB;AACvB,YAAM,iBAAiB,eAAe,KAAK,IAAI;AAC/C,YAAM,eAAe;AACrB,YAAM,mBAAmB,GAAG,cAAc;AAAA,EAAK,cAAc;AAAA,EAAK,YAAY;AAI9E,YAAM,OAAO,IAAI,KAAK,cAAc,IAAI,aAAa;AAAA,QACnD,wBAAwB;AAAA,QACxB,2BAA2B;AAAA,MAC7B,CAAC;AAED,YAAM,SAAS,MAAM,KAAK,QAAQ,IAAI,iBAAiB,KAAK,YAAY,CAAC,EACtE,KAAK,MAAM,IAAI,EACf,MAAM,MAAM,KAAK;AAEpB,UAAI,CAAC,QAAQ;AACX,aAAK,UAAU;AACf,eAAO,KAAK,MAAM;AAAA,MACpB;AAEA,YAAM,iBAAiB,MAAM;AAAA,QAC3B,QAAQ,IAAI,iBAAiB,KAAK,YAAY;AAAA,QAC9C;AAAA,MACF;AAEA,YAAM,mBAAmB,eAAe,QAAQ,cAAc;AAC9D,YAAM,iBAAiB,eAAe,QAAQ,YAAY;AAE1D,UAAI,qBAAqB,MAAM,mBAAmB,IAAI;AACpD,aAAK,UAAU,GAAG,cAAc;AAAA;AAAA,EAAO,gBAAgB;AACvD,eAAO,KAAK,MAAM;AAAA,MACpB;AAEA,WAAK,UACH,eAAe,MAAM,GAAG,gBAAgB,IACxC,mBACA,eAAe,MAAM,iBAAiB,aAAa,MAAM;AAE3D,aAAO,KAAK,MAAM;AAAA,IACpB;AAAA,EACF,CAAC;AACH;","names":["file"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@baeta/plugin-gitignore",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"baeta",
|
|
6
|
+
"graphql",
|
|
7
|
+
"schema",
|
|
8
|
+
"types",
|
|
9
|
+
"typescript",
|
|
10
|
+
"framework",
|
|
11
|
+
"builder"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://github.com/andreisergiu98/baeta#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/andreisergiu98/baeta/issues"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/andreisergiu98/baeta.git",
|
|
20
|
+
"directory": "packages/plugin-gitignore"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": {
|
|
24
|
+
"name": "Andrei Pampu",
|
|
25
|
+
"url": "https://github.com/andreisergiu98"
|
|
26
|
+
},
|
|
27
|
+
"type": "module",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"import": "./dist/index.js",
|
|
31
|
+
"require": "./dist/index.cjs",
|
|
32
|
+
"types": "./dist/index.d.ts"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"types": "dist/index.d.ts",
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"package.json"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsup",
|
|
42
|
+
"dev": "tsup --watch",
|
|
43
|
+
"prepack": "prep",
|
|
44
|
+
"postpack": "prep --clean",
|
|
45
|
+
"types": "tsc --noEmit"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@baeta/generator-sdk": "^0.0.11"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@baeta/builder": "^0.0.0",
|
|
52
|
+
"@baeta/tsconfig": "^0.0.0",
|
|
53
|
+
"@types/node": "^18.19.28",
|
|
54
|
+
"typescript": "^5.4.3"
|
|
55
|
+
},
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": ">=18.0.0"
|
|
58
|
+
},
|
|
59
|
+
"publishConfig": {
|
|
60
|
+
"access": "public"
|
|
61
|
+
}
|
|
62
|
+
}
|