cognite-create 0.1.4 → 0.1.6
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/bin/index.js +49 -44
- package/package.json +1 -1
- package/templates/.cursor/rules/general.mdc +1 -1
package/bin/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
3
4
|
const { spawn } = require('node:child_process');
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
4
6
|
const fs = require('node:fs/promises');
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
5
8
|
const path = require('node:path');
|
|
6
9
|
|
|
7
10
|
async function main() {
|
|
@@ -54,32 +57,33 @@ async function addCogniteTemplates(projectDir) {
|
|
|
54
57
|
throw error;
|
|
55
58
|
}
|
|
56
59
|
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
target: path.join(targetRoot, '.cursor', 'mcp.json'),
|
|
66
|
-
overwrite: false,
|
|
67
|
-
},
|
|
68
|
-
];
|
|
69
|
-
|
|
70
|
-
const globalsCssTarget = await resolveGlobalsCssTarget(targetRoot);
|
|
71
|
-
filesToCopy.push({
|
|
72
|
-
source: path.join(templateRoot, 'globals.css'),
|
|
73
|
-
target: globalsCssTarget,
|
|
74
|
-
overwrite: true,
|
|
75
|
-
});
|
|
60
|
+
const srcDirectory = path.join(targetRoot, 'src');
|
|
61
|
+
const templateFiles = await collectTemplateFiles(templateRoot);
|
|
62
|
+
|
|
63
|
+
await fs.mkdir(srcDirectory, { recursive: true });
|
|
64
|
+
|
|
65
|
+
for (const relativePath of templateFiles) {
|
|
66
|
+
const normalizedPath = normalizeRelativePath(relativePath);
|
|
67
|
+
const source = path.join(templateRoot, relativePath);
|
|
76
68
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
69
|
+
const pathSegments = normalizedPath.split('/');
|
|
70
|
+
|
|
71
|
+
if (pathSegments[0] === 'app' || pathSegments[0] === 'lib') {
|
|
72
|
+
const target = path.join(srcDirectory, ...pathSegments);
|
|
73
|
+
const isGlobalsCss =
|
|
74
|
+
pathSegments[0] === 'app' && pathSegments.length === 2 && pathSegments[1] === 'globals.css';
|
|
75
|
+
|
|
76
|
+
if (isGlobalsCss) {
|
|
77
|
+
await copyFileWithOverwrite(source, target);
|
|
78
|
+
} else {
|
|
79
|
+
await copyFileIfMissing(source, target);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
continue;
|
|
82
83
|
}
|
|
84
|
+
|
|
85
|
+
const target = path.join(targetRoot, relativePath);
|
|
86
|
+
await copyFileIfMissing(source, target);
|
|
83
87
|
}
|
|
84
88
|
|
|
85
89
|
console.log('\nCognite templates copied successfully.');
|
|
@@ -107,32 +111,33 @@ async function copyFileWithOverwrite(source, target) {
|
|
|
107
111
|
console.log(`Replaced ${path.relative(process.cwd(), target)}`);
|
|
108
112
|
}
|
|
109
113
|
|
|
110
|
-
async function
|
|
111
|
-
const
|
|
112
|
-
const appDirPath = path.join(targetRoot, 'app', 'globals.css');
|
|
114
|
+
async function collectTemplateFiles(rootDir) {
|
|
115
|
+
const files = [];
|
|
113
116
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
+
async function walk(currentDir) {
|
|
118
|
+
const dirents = await fs.readdir(currentDir, { withFileTypes: true });
|
|
117
119
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
120
|
+
for (const dirent of dirents) {
|
|
121
|
+
const fullPath = path.join(currentDir, dirent.name);
|
|
121
122
|
|
|
122
|
-
|
|
123
|
-
|
|
123
|
+
if (dirent.isDirectory()) {
|
|
124
|
+
await walk(fullPath);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
124
127
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return true;
|
|
129
|
-
} catch (error) {
|
|
130
|
-
if (error.code === 'ENOENT') {
|
|
131
|
-
return false;
|
|
128
|
+
if (dirent.isFile()) {
|
|
129
|
+
files.push(path.relative(rootDir, fullPath));
|
|
130
|
+
}
|
|
132
131
|
}
|
|
133
|
-
|
|
134
|
-
throw error;
|
|
135
132
|
}
|
|
133
|
+
|
|
134
|
+
await walk(rootDir);
|
|
135
|
+
|
|
136
|
+
return files.sort((a, b) => a.localeCompare(b));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function normalizeRelativePath(relativePath) {
|
|
140
|
+
return relativePath.split(path.sep).join('/');
|
|
136
141
|
}
|
|
137
142
|
|
|
138
143
|
main().catch((error) => {
|
package/package.json
CHANGED