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 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 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
- });
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
- 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);
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 resolveGlobalsCssTarget(targetRoot) {
111
- const srcDirPath = path.join(targetRoot, 'src', 'app', 'globals.css');
112
- const appDirPath = path.join(targetRoot, 'app', 'globals.css');
114
+ async function collectTemplateFiles(rootDir) {
115
+ const files = [];
113
116
 
114
- if (await fileExists(srcDirPath)) {
115
- return srcDirPath;
116
- }
117
+ async function walk(currentDir) {
118
+ const dirents = await fs.readdir(currentDir, { withFileTypes: true });
117
119
 
118
- if (await fileExists(appDirPath)) {
119
- return appDirPath;
120
- }
120
+ for (const dirent of dirents) {
121
+ const fullPath = path.join(currentDir, dirent.name);
121
122
 
122
- return appDirPath;
123
- }
123
+ if (dirent.isDirectory()) {
124
+ await walk(fullPath);
125
+ continue;
126
+ }
124
127
 
125
- async function fileExists(filePath) {
126
- try {
127
- await fs.access(filePath);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cognite-create",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Create a Next.js app preconfigured with Cognite defaults.",
5
5
  "private": false,
6
6
  "bin": {
@@ -4,4 +4,4 @@ globs:
4
4
  alwaysApply: true
5
5
  ---
6
6
 
7
- Where possible check the Cognite ShadCN registry for components before making your own.
7
+ Use the ShadCN MCP server to check the Cognite registry for components before making your own.