cognite-create 0.1.3 → 0.1.5

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 CHANGED
@@ -54,32 +54,30 @@ async function addCogniteTemplates(projectDir) {
54
54
  throw error;
55
55
  }
56
56
 
57
- const filesToCopy = [
58
- {
59
- source: path.join(templateRoot, 'components.json'),
60
- target: path.join(targetRoot, 'components.json'),
61
- overwrite: false,
62
- },
63
- {
64
- source: path.join(templateRoot, '.cursor', 'mcp.json'),
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
- });
57
+ const appDirectory = await resolveAppDirectory(targetRoot);
58
+ const templateFiles = await collectTemplateFiles(templateRoot);
59
+
60
+ for (const relativePath of templateFiles) {
61
+ const normalizedPath = normalizeRelativePath(relativePath);
62
+ const source = path.join(templateRoot, relativePath);
63
+
64
+ const pathSegments = normalizedPath.split('/');
76
65
 
77
- for (const file of filesToCopy) {
78
- if (file.overwrite) {
79
- await copyFileWithOverwrite(file.source, file.target);
80
- } else {
81
- await copyFileIfMissing(file.source, file.target);
66
+ if (pathSegments[0] === 'app') {
67
+ const target = path.join(appDirectory, ...pathSegments.slice(1));
68
+ const isGlobalsCss = pathSegments.length === 2 && pathSegments[1] === 'globals.css';
69
+
70
+ if (isGlobalsCss) {
71
+ await copyFileWithOverwrite(source, target);
72
+ } else {
73
+ await copyFileIfMissing(source, target);
74
+ }
75
+
76
+ continue;
82
77
  }
78
+
79
+ const target = path.join(targetRoot, relativePath);
80
+ await copyFileIfMissing(source, target);
83
81
  }
84
82
 
85
83
  console.log('\nCognite templates copied successfully.');
@@ -107,21 +105,6 @@ async function copyFileWithOverwrite(source, target) {
107
105
  console.log(`Replaced ${path.relative(process.cwd(), target)}`);
108
106
  }
109
107
 
110
- async function resolveGlobalsCssTarget(targetRoot) {
111
- const srcDirPath = path.join(targetRoot, 'src', 'app', 'globals.css');
112
- const appDirPath = path.join(targetRoot, 'app', 'globals.css');
113
-
114
- if (await fileExists(srcDirPath)) {
115
- return srcDirPath;
116
- }
117
-
118
- if (await fileExists(appDirPath)) {
119
- return appDirPath;
120
- }
121
-
122
- return appDirPath;
123
- }
124
-
125
108
  async function fileExists(filePath) {
126
109
  try {
127
110
  await fs.access(filePath);
@@ -135,6 +118,45 @@ async function fileExists(filePath) {
135
118
  }
136
119
  }
137
120
 
121
+ async function collectTemplateFiles(rootDir) {
122
+ const files = [];
123
+
124
+ async function walk(currentDir) {
125
+ const dirents = await fs.readdir(currentDir, { withFileTypes: true });
126
+
127
+ for (const dirent of dirents) {
128
+ const fullPath = path.join(currentDir, dirent.name);
129
+
130
+ if (dirent.isDirectory()) {
131
+ await walk(fullPath);
132
+ continue;
133
+ }
134
+
135
+ if (dirent.isFile()) {
136
+ files.push(path.relative(rootDir, fullPath));
137
+ }
138
+ }
139
+ }
140
+
141
+ await walk(rootDir);
142
+
143
+ return files.sort((a, b) => a.localeCompare(b));
144
+ }
145
+
146
+ function normalizeRelativePath(relativePath) {
147
+ return relativePath.split(path.sep).join('/');
148
+ }
149
+
150
+ async function resolveAppDirectory(targetRoot) {
151
+ const srcAppDir = path.join(targetRoot, 'src', 'app');
152
+
153
+ if (await fileExists(srcAppDir)) {
154
+ return srcAppDir;
155
+ }
156
+
157
+ return path.join(targetRoot, 'app');
158
+ }
159
+
138
160
  main().catch((error) => {
139
161
  if (error && typeof error.exitCode === 'number') {
140
162
  process.exit(error.exitCode);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cognite-create",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Create a Next.js app preconfigured with Cognite defaults.",
5
5
  "private": false,
6
6
  "bin": {
@@ -0,0 +1,7 @@
1
+ ---
2
+ description:
3
+ globs:
4
+ alwaysApply: true
5
+ ---
6
+
7
+ Where possible check the Cognite ShadCN registry for components before making your own.