keen-project-create 1.0.1

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.mjs ADDED
@@ -0,0 +1,124 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'fs';
4
+ import fsp from 'fs/promises';
5
+ import path from 'path';
6
+ import { fileURLToPath } from 'url';
7
+ import { spawn } from 'child_process';
8
+
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = path.dirname(__filename);
11
+
12
+ const rawArgs = process.argv.slice(2);
13
+
14
+ // grab --type=... or --type ...
15
+ let typeFromFlag;
16
+ for (let i = 0; i < rawArgs.length; i++) {
17
+ if (rawArgs[i].startsWith('--type=')) {
18
+ typeFromFlag = rawArgs[i].split('=')[1];
19
+ break;
20
+ }
21
+ if (rawArgs[i] === '--type' && rawArgs[i + 1]) {
22
+ typeFromFlag = rawArgs[i + 1];
23
+ break;
24
+ }
25
+ }
26
+
27
+ const positional = rawArgs.filter(a => !a.startsWith('-'));
28
+ const projectNameArg = positional[0];
29
+ const positionalType = positional[1];
30
+
31
+ if (!projectNameArg) {
32
+ console.error('Usage: keen-project-create <project-name>');
33
+ process.exit(1);
34
+ }
35
+
36
+ const projectType = (typeFromFlag || positionalType || '').toLowerCase();
37
+
38
+ // Resolve paths
39
+ const TEMPLATE_DEFAULT = path.resolve(__dirname, '../templates/default');
40
+ const TEMPLATE_VSCODE = path.resolve(__dirname, '../templates/vscode');
41
+
42
+ const TEMPLATE_DIR = projectType === 'vscode' ? TEMPLATE_VSCODE : TEMPLATE_DEFAULT;
43
+
44
+ const targetDir = path.resolve(process.cwd(), projectNameArg);
45
+
46
+ async function ensureDirEmptyOrCreate(dir) {
47
+ try {
48
+ await fsp.mkdir(dir, { recursive: true });
49
+ const items = await fsp.readdir(dir);
50
+ if (items.length > 0) {
51
+ console.error(`Target directory is not empty: ${dir}`);
52
+ process.exit(1);
53
+ }
54
+ } catch (e) {
55
+ console.error('Failed creating target directory:', e);
56
+ process.exit(1);
57
+ }
58
+ }
59
+
60
+ async function copyDir(src, dest) {
61
+ await fsp.mkdir(dest, { recursive: true });
62
+ const entries = await fsp.readdir(src, { withFileTypes: true });
63
+ for (const entry of entries) {
64
+ const s = path.join(src, entry.name);
65
+ const d = path.join(dest, entry.name);
66
+ if (entry.isDirectory()) {
67
+ await copyDir(s, d);
68
+ } else {
69
+ await fsp.copyFile(s, d);
70
+ }
71
+ }
72
+ }
73
+
74
+ async function replaceInFile(filePath, replacements) {
75
+ const exists = fs.existsSync(filePath);
76
+ if (!exists) return;
77
+ let content = await fsp.readFile(filePath, 'utf-8');
78
+ for (const [from, to] of Object.entries(replacements)) {
79
+ content = content.replaceAll(from, to);
80
+ }
81
+ await fsp.writeFile(filePath, content);
82
+ }
83
+
84
+ // Choose package manager: npm by default
85
+ function detectPackageManager() {
86
+ // You could enhance to check for pnpm/yarn existence.
87
+ return 'npm';
88
+ }
89
+
90
+ function runInstall(cwd, pm = 'npm') {
91
+ return new Promise((resolve, reject) => {
92
+ const args = ['install'];
93
+ const child = spawn(pm, args, { stdio: 'inherit', cwd, shell: process.platform === 'win32' });
94
+ child.on('close', code => (code === 0 ? resolve() : reject(new Error(pm + ' install failed'))));
95
+ });
96
+ }
97
+
98
+ (async () => {
99
+ console.log(`> Creating project: ${projectNameArg}`);
100
+ await ensureDirEmptyOrCreate(targetDir);
101
+
102
+ console.log('> Copying template…');
103
+ await copyDir(TEMPLATE_DIR, targetDir);
104
+
105
+ // Optional: personalize package.json
106
+ const pkgJsonPath = path.join(targetDir, 'package.json');
107
+ await replaceInFile(pkgJsonPath, {
108
+ __APP_NAME__: projectNameArg
109
+ });
110
+
111
+ // Install deps
112
+ const pm = detectPackageManager();
113
+ console.log(`> Installing dependencies with ${pm}…`);
114
+ await runInstall(targetDir, pm);
115
+
116
+ console.log('\n✅ Done!');
117
+ console.log(`\nNext steps:
118
+ cd ${projectNameArg}
119
+ ${pm} run dev
120
+ `);
121
+ })().catch(err => {
122
+ console.error(err);
123
+ process.exit(1);
124
+ });
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "keen-project-create",
3
+ "description": "Project scaffolder for Keen projects",
4
+ "version": "1.0.1",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "bin": {
8
+ "keen-project-create": "dist/index.mjs"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/PaskalN/keen-project-create.git"
13
+ },
14
+ "files": [
15
+ "dist/",
16
+ "templates/",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "publishConfig": {
21
+ "access": "public",
22
+ "registry": "https://registry.npmjs.org/"
23
+ },
24
+ "scripts": {
25
+ "test": "echo \"Error: no test specified\" && exit 1"
26
+ },
27
+ "keywords": [],
28
+ "author": "Paskal Novakov",
29
+ "license": "ISC",
30
+ "dependencies": {
31
+ "husky": "^9.1.7",
32
+ "prettier": "^3.6.2"
33
+ }
34
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "project_name": "sketch",
3
+ "agent_name": "SketchAgent",
4
+ "keen_server": "__REPLACE__WITH__URL__",
5
+ "start_agent": "Project-Start",
6
+ "entry": "src",
7
+ "dist": "dist"
8
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "keen__sketch__project",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "keen-builder"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "description": "",
13
+ "dependencies": {
14
+ "@paskaln/keen-builder": "^1.0.1"
15
+ }
16
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "nodes": [],
3
+ "edges": [],
4
+ "viewport": { "x": 0, "y": 0, "zoom": 1 }
5
+ }
@@ -0,0 +1,5 @@
1
+ export function debux(debux_id) {
2
+ return debux_id;
3
+ }
4
+
5
+ global.debux = debux;
@@ -0,0 +1,7 @@
1
+ # Ignore artifacts:
2
+ dist
3
+
4
+ **/.git
5
+ **/.svn
6
+ **/.hg
7
+ **/node_modules
@@ -0,0 +1,10 @@
1
+ {
2
+ "semi": true,
3
+ "singleQuote": true,
4
+ "trailingComma": "none",
5
+ "tabWidth": 4,
6
+ "printWidth": 200,
7
+ "bracketSpacing": true,
8
+ "arrowParens": "avoid",
9
+ "endOfLine": "lf"
10
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "project_name": "sketch",
3
+ "agent_name": "SketchAgent",
4
+ "keen_server": "__REPLACE__WITH__URL__",
5
+ "start_agent": "Project-Start",
6
+ "entry": "src",
7
+ "dist": "dist"
8
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "keen__sketch__project",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "keen-builder"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "description": "",
13
+ "dependencies": {
14
+ "@paskaln/keen-builder": "^1.0.1",
15
+ "prettier": "^3.6.2"
16
+ }
17
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "nodes": [],
3
+ "edges": [],
4
+ "viewport": { "x": 0, "y": 0, "zoom": 1 }
5
+ }
@@ -0,0 +1,5 @@
1
+ export function debux(debux_id) {
2
+ return debux_id;
3
+ }
4
+
5
+ global.debux = debux;