cognite-create 0.1.6 → 0.1.7

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
@@ -7,6 +7,9 @@ const fs = require('node:fs/promises');
7
7
  // eslint-disable-next-line @typescript-eslint/no-require-imports
8
8
  const path = require('node:path');
9
9
 
10
+ const TW_ANIMATE_PACKAGE = 'tw-animate-css';
11
+ const TW_ANIMATE_VERSION = '^1.3.8';
12
+
10
13
  async function main() {
11
14
  const args = process.argv.slice(2);
12
15
 
@@ -57,6 +60,8 @@ async function addCogniteTemplates(projectDir) {
57
60
  throw error;
58
61
  }
59
62
 
63
+ await ensureTwAnimateCssInstalled(targetRoot);
64
+
60
65
  const srcDirectory = path.join(targetRoot, 'src');
61
66
  const templateFiles = await collectTemplateFiles(templateRoot);
62
67
 
@@ -140,6 +145,138 @@ function normalizeRelativePath(relativePath) {
140
145
  return relativePath.split(path.sep).join('/');
141
146
  }
142
147
 
148
+ async function ensureTwAnimateCssInstalled(targetRoot) {
149
+ const packageJsonPath = path.join(targetRoot, 'package.json');
150
+ let packageJson;
151
+
152
+ try {
153
+ const packageJsonContent = await fs.readFile(packageJsonPath, 'utf8');
154
+ packageJson = JSON.parse(packageJsonContent);
155
+ } catch (error) {
156
+ console.warn(
157
+ `\nUnable to read or parse ${path.relative(process.cwd(), packageJsonPath)}. ` +
158
+ `Install ${TW_ANIMATE_PACKAGE}@${TW_ANIMATE_VERSION} manually.`
159
+ );
160
+ return false;
161
+ }
162
+
163
+ const hasDependency = Boolean(
164
+ (packageJson.dependencies && packageJson.dependencies[TW_ANIMATE_PACKAGE]) ||
165
+ (packageJson.devDependencies && packageJson.devDependencies[TW_ANIMATE_PACKAGE])
166
+ );
167
+
168
+ if (hasDependency) {
169
+ return false;
170
+ }
171
+
172
+ const packageManager = await detectPackageManager(packageJson, targetRoot);
173
+
174
+ if (!packageManager) {
175
+ console.warn(
176
+ `\nCould not determine package manager for ${path.relative(process.cwd(), targetRoot)}. ` +
177
+ `Install ${TW_ANIMATE_PACKAGE}@${TW_ANIMATE_VERSION} manually.`
178
+ );
179
+ return false;
180
+ }
181
+
182
+ console.log(
183
+ `\nInstalling ${TW_ANIMATE_PACKAGE}@${TW_ANIMATE_VERSION} using ${packageManager}...`
184
+ );
185
+ await installDependency(packageManager, targetRoot, `${TW_ANIMATE_PACKAGE}@${TW_ANIMATE_VERSION}`);
186
+
187
+ return true;
188
+ }
189
+
190
+ async function detectPackageManager(packageJson, targetRoot) {
191
+ if (packageJson.packageManager && typeof packageJson.packageManager === 'string') {
192
+ const [name] = packageJson.packageManager.split('@');
193
+
194
+ if (name) {
195
+ return name;
196
+ }
197
+ }
198
+
199
+ const candidates = [
200
+ { name: 'pnpm', lockFile: 'pnpm-lock.yaml' },
201
+ { name: 'yarn', lockFile: 'yarn.lock' },
202
+ { name: 'bun', lockFile: 'bun.lockb' },
203
+ { name: 'npm', lockFile: 'package-lock.json' },
204
+ ];
205
+
206
+ for (const candidate of candidates) {
207
+ const lockFilePath = path.join(targetRoot, candidate.lockFile);
208
+
209
+ if (await pathExists(lockFilePath)) {
210
+ return candidate.name;
211
+ }
212
+ }
213
+
214
+ return null;
215
+ }
216
+
217
+ async function installDependency(packageManager, cwd, dependencySpec) {
218
+ const { command, args } = getInstallCommand(packageManager, dependencySpec);
219
+
220
+ if (!command) {
221
+ throw new Error(`Unsupported package manager: ${packageManager}`);
222
+ }
223
+
224
+ return new Promise((resolve, reject) => {
225
+ const child = spawn(command, args, { stdio: 'inherit', cwd });
226
+
227
+ child.on('error', reject);
228
+ child.on('close', (code) => {
229
+ if (code !== 0) {
230
+ const error = new Error(
231
+ `${packageManager} exited with code ${code} while installing ${dependencySpec}`
232
+ );
233
+ error.exitCode = code;
234
+ return reject(error);
235
+ }
236
+
237
+ resolve();
238
+ });
239
+ });
240
+ }
241
+
242
+ function getInstallCommand(packageManager, dependencySpec) {
243
+ const normalized = normalizeCommand(packageManager);
244
+
245
+ switch (packageManager) {
246
+ case 'npm':
247
+ return { command: normalized, args: ['install', dependencySpec] };
248
+ case 'pnpm':
249
+ return { command: normalized, args: ['add', dependencySpec] };
250
+ case 'yarn':
251
+ return { command: normalized, args: ['add', dependencySpec] };
252
+ case 'bun':
253
+ return { command: normalized, args: ['add', dependencySpec] };
254
+ default:
255
+ return { command: null, args: [] };
256
+ }
257
+ }
258
+
259
+ function normalizeCommand(command) {
260
+ if (process.platform === 'win32' && command !== 'bun') {
261
+ return `${command}.cmd`;
262
+ }
263
+
264
+ return command;
265
+ }
266
+
267
+ async function pathExists(filePath) {
268
+ try {
269
+ await fs.access(filePath);
270
+ return true;
271
+ } catch (error) {
272
+ if (error && error.code === 'ENOENT') {
273
+ return false;
274
+ }
275
+
276
+ throw error;
277
+ }
278
+ }
279
+
143
280
  main().catch((error) => {
144
281
  if (error && typeof error.exitCode === 'number') {
145
282
  process.exit(error.exitCode);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cognite-create",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
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
- Use the ShadCN MCP server to check the Cognite registry for components before making your own.
7
+ Use the ShadCN MCP server to check the Cognite registry for components you could use before making your own. If there are Cognite components available for what you are trying to do you must always use them over alternatives. We want to make sure our app aligns with the Cognite design system.