create-contextkit 0.1.0

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/dist/index.js ADDED
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/index.ts
4
+ import fs from "fs";
5
+ import path from "path";
6
+ import { fileURLToPath } from "url";
7
+ var __dirname = path.dirname(fileURLToPath(import.meta.url));
8
+ var templatesDir = path.resolve(__dirname, "..", "templates", "minimal");
9
+ function toKebabCase(input) {
10
+ return input.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
11
+ }
12
+ function toTitleCase(input) {
13
+ return input.replace(/[-_]+/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
14
+ }
15
+ function copyDir(src, dest, createdFiles, projectDir, projectName, displayName) {
16
+ const entries = fs.readdirSync(src, { withFileTypes: true });
17
+ for (const entry of entries) {
18
+ const srcPath = path.join(src, entry.name);
19
+ const destPath = path.join(dest, entry.name);
20
+ if (entry.isDirectory()) {
21
+ fs.mkdirSync(destPath, { recursive: true });
22
+ copyDir(srcPath, destPath, createdFiles, projectDir, projectName, displayName);
23
+ } else if (entry.name.endsWith(".template")) {
24
+ let content = fs.readFileSync(srcPath, "utf-8");
25
+ content = content.replace(/\{\{PROJECT_NAME\}\}/g, projectName);
26
+ content = content.replace(/\{\{PROJECT_DISPLAY_NAME\}\}/g, displayName);
27
+ const finalPath = destPath.replace(/\.template$/, "");
28
+ fs.writeFileSync(finalPath, content, "utf-8");
29
+ createdFiles.push(path.relative(projectDir, finalPath));
30
+ } else {
31
+ fs.copyFileSync(srcPath, destPath);
32
+ createdFiles.push(path.relative(projectDir, destPath));
33
+ }
34
+ }
35
+ }
36
+ function main() {
37
+ const projectNameArg = process.argv[2];
38
+ if (!projectNameArg) {
39
+ console.log("Usage: create-contextkit <project-name>");
40
+ console.log("");
41
+ console.log("Example:");
42
+ console.log(" npm create contextkit my-project");
43
+ console.log(" pnpm create contextkit my-project");
44
+ process.exit(1);
45
+ }
46
+ const projectName = toKebabCase(projectNameArg);
47
+ const displayName = toTitleCase(projectName);
48
+ const projectDir = path.resolve(process.cwd(), projectName);
49
+ if (fs.existsSync(projectDir)) {
50
+ console.error(`Error: Directory "${projectName}" already exists. Please choose a different name or remove the existing directory.`);
51
+ process.exit(1);
52
+ }
53
+ console.log(`Creating ContextKit project: ${projectName}`);
54
+ console.log("");
55
+ fs.mkdirSync(projectDir, { recursive: true });
56
+ const createdFiles = [];
57
+ copyDir(templatesDir, projectDir, createdFiles, projectDir, projectName, displayName);
58
+ const emptyDirs = ["context/entities", "context/terms"];
59
+ for (const dir of emptyDirs) {
60
+ const dirPath = path.join(projectDir, dir);
61
+ fs.mkdirSync(dirPath, { recursive: true });
62
+ }
63
+ for (const file of createdFiles) {
64
+ console.log(` Created ${file}`);
65
+ }
66
+ console.log("");
67
+ console.log("Done! Next steps:");
68
+ console.log(` cd ${projectName}`);
69
+ console.log(" pnpm add -D @runcontext/cli");
70
+ console.log(" npx context lint");
71
+ }
72
+ main();
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "create-contextkit",
3
+ "version": "0.1.0",
4
+ "description": "Scaffold a new ContextKit project",
5
+ "license": "MIT",
6
+ "author": "Eric Kittelson",
7
+ "homepage": "https://github.com/erickittelson/ContextKit",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/erickittelson/ContextKit.git",
11
+ "directory": "create-contextkit"
12
+ },
13
+ "keywords": ["contextkit", "scaffolder", "create", "init"],
14
+ "type": "module",
15
+ "bin": { "create-contextkit": "./dist/index.js" },
16
+ "files": ["dist", "templates"],
17
+ "scripts": {
18
+ "build": "tsup",
19
+ "clean": "rm -rf dist"
20
+ },
21
+ "devDependencies": {
22
+ "tsup": "^8.4.0",
23
+ "typescript": "^5.7.0"
24
+ }
25
+ }
@@ -0,0 +1,5 @@
1
+ id: example-concept
2
+ definition: An example concept to get you started.
3
+ owner: example-team
4
+ status: draft
5
+ tags: [example]
@@ -0,0 +1,3 @@
1
+ id: example-team
2
+ display_name: Example Team
3
+ email: team@example.com
@@ -0,0 +1,8 @@
1
+ id: example-policy
2
+ description: An example policy.
3
+ rules:
4
+ - priority: 100
5
+ when:
6
+ tags_any: [sensitive]
7
+ then:
8
+ require_role: admin
@@ -0,0 +1,4 @@
1
+ id: example-product
2
+ description: An example product to get you started.
3
+ owner: example-team
4
+ tags: [example]
@@ -0,0 +1,4 @@
1
+ project:
2
+ id: {{PROJECT_NAME}}
3
+ displayName: "{{PROJECT_DISPLAY_NAME}}"
4
+ version: "0.1.0"