@nexical/cli 0.11.0 → 0.11.2
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/.github/workflows/deploy.yml +1 -1
- package/.husky/pre-commit +1 -0
- package/.prettierignore +8 -0
- package/.prettierrc +7 -0
- package/GEMINI.md +36 -30
- package/README.md +85 -56
- package/dist/chunk-AC4B3HPJ.js +93 -0
- package/dist/chunk-AC4B3HPJ.js.map +1 -0
- package/dist/{chunk-JYASTIIW.js → chunk-PJIOCW2A.js} +1 -1
- package/dist/chunk-PJIOCW2A.js.map +1 -0
- package/dist/{chunk-WKERTCM6.js → chunk-Q7YLW5HJ.js} +5 -2
- package/dist/chunk-Q7YLW5HJ.js.map +1 -0
- package/dist/index.js +41 -12
- package/dist/index.js.map +1 -1
- package/dist/src/commands/init.d.ts +4 -1
- package/dist/src/commands/init.js +8 -4
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/module/add.d.ts +3 -1
- package/dist/src/commands/module/add.js +24 -13
- package/dist/src/commands/module/add.js.map +1 -1
- package/dist/src/commands/module/list.js +9 -5
- package/dist/src/commands/module/list.js.map +1 -1
- package/dist/src/commands/module/remove.d.ts +3 -1
- package/dist/src/commands/module/remove.js +13 -7
- package/dist/src/commands/module/remove.js.map +1 -1
- package/dist/src/commands/module/update.d.ts +3 -1
- package/dist/src/commands/module/update.js +7 -5
- package/dist/src/commands/module/update.js.map +1 -1
- package/dist/src/commands/run.d.ts +4 -1
- package/dist/src/commands/run.js +10 -2
- package/dist/src/commands/run.js.map +1 -1
- package/dist/src/commands/setup.js +9 -4
- package/dist/src/commands/setup.js.map +1 -1
- package/dist/src/utils/discovery.js +1 -1
- package/dist/src/utils/git.js +1 -1
- package/dist/src/utils/url-resolver.js +1 -1
- package/eslint.config.mjs +67 -0
- package/index.ts +34 -20
- package/package.json +56 -32
- package/src/commands/init.ts +79 -76
- package/src/commands/module/add.ts +158 -148
- package/src/commands/module/list.ts +61 -50
- package/src/commands/module/remove.ts +59 -54
- package/src/commands/module/update.ts +44 -42
- package/src/commands/run.ts +89 -81
- package/src/commands/setup.ts +70 -60
- package/src/utils/discovery.ts +98 -113
- package/src/utils/git.ts +35 -28
- package/src/utils/url-resolver.ts +50 -45
- package/test/e2e/lifecycle.e2e.test.ts +139 -131
- package/test/integration/commands/init.integration.test.ts +64 -64
- package/test/integration/commands/module.integration.test.ts +122 -122
- package/test/integration/commands/run.integration.test.ts +70 -63
- package/test/integration/utils/command-loading.integration.test.ts +40 -53
- package/test/unit/commands/init.test.ts +163 -128
- package/test/unit/commands/module/add.test.ts +312 -245
- package/test/unit/commands/module/list.test.ts +108 -91
- package/test/unit/commands/module/remove.test.ts +74 -67
- package/test/unit/commands/module/update.test.ts +74 -70
- package/test/unit/commands/run.test.ts +253 -201
- package/test/unit/commands/setup.test.ts +138 -128
- package/test/unit/utils/command-discovery.test.ts +138 -125
- package/test/unit/utils/git.test.ts +135 -117
- package/test/unit/utils/integration-helpers.test.ts +59 -49
- package/test/unit/utils/url-resolver.test.ts +46 -34
- package/test/utils/integration-helpers.ts +36 -29
- package/tsconfig.json +15 -25
- package/tsup.config.ts +14 -14
- package/vitest.config.ts +10 -10
- package/vitest.e2e.config.ts +6 -6
- package/vitest.integration.config.ts +17 -17
- package/dist/chunk-JYASTIIW.js.map +0 -1
- package/dist/chunk-OKXOCNXP.js +0 -105
- package/dist/chunk-OKXOCNXP.js.map +0 -1
- package/dist/chunk-WKERTCM6.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/commands/module/update.ts"],"sourcesContent":["import { type CommandDefinition, BaseCommand, logger, runCommand } from '@nexical/cli-core';\nimport fs from 'fs-extra';\nimport path from 'path';\n\nexport default class ModuleUpdateCommand extends BaseCommand {\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/commands/module/update.ts"],"sourcesContent":["import { type CommandDefinition, BaseCommand, logger, runCommand } from '@nexical/cli-core';\nimport fs from 'fs-extra';\nimport path from 'path';\n\nexport default class ModuleUpdateCommand extends BaseCommand {\n static usage = 'module update [name]';\n static description = 'Update a specific module or all modules.';\n static requiresProject = true;\n\n static args: CommandDefinition = {\n args: [{ name: 'name', required: false, description: 'Name of the module to update' }],\n };\n\n async run(options: { name?: string }) {\n const projectRoot = this.projectRoot as string;\n const { name } = options;\n\n this.info(name ? `Updating module ${name}...` : 'Updating all modules...');\n logger.debug('Update context:', { name, projectRoot: projectRoot });\n\n try {\n if (name) {\n const relativePath = `modules/${name}`;\n const fullPath = path.resolve(projectRoot, relativePath);\n\n if (!(await fs.pathExists(fullPath))) {\n this.error(`Module ${name} not found.`);\n return;\n }\n\n // Update specific module\n // We enter the directory and pull? Or generic submodule update?\n // Generic submodule update --remote src/modules/name\n await runCommand(`git submodule update --remote --merge ${relativePath}`, projectRoot);\n } else {\n // Update all\n await runCommand('git submodule update --remote --merge', projectRoot);\n }\n\n this.info('Syncing workspace dependencies...');\n await runCommand('npm install', projectRoot);\n\n this.success('Modules updated successfully.');\n } catch (e: unknown) {\n if (e instanceof Error) {\n this.error(`Failed to update modules: ${e.message}`);\n } else {\n this.error(`Failed to update modules: ${String(e)}`);\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;AAAA;AACA,sBAAe;AADf,SAAiC,aAAa,QAAQ,kBAAkB;AAExE,OAAO,UAAU;AAEjB,IAAqB,sBAArB,cAAiD,YAAY;AAAA,EAC3D,OAAO,QAAQ;AAAA,EACf,OAAO,cAAc;AAAA,EACrB,OAAO,kBAAkB;AAAA,EAEzB,OAAO,OAA0B;AAAA,IAC/B,MAAM,CAAC,EAAE,MAAM,QAAQ,UAAU,OAAO,aAAa,+BAA+B,CAAC;AAAA,EACvF;AAAA,EAEA,MAAM,IAAI,SAA4B;AACpC,UAAM,cAAc,KAAK;AACzB,UAAM,EAAE,KAAK,IAAI;AAEjB,SAAK,KAAK,OAAO,mBAAmB,IAAI,QAAQ,yBAAyB;AACzE,WAAO,MAAM,mBAAmB,EAAE,MAAM,YAAyB,CAAC;AAElE,QAAI;AACF,UAAI,MAAM;AACR,cAAM,eAAe,WAAW,IAAI;AACpC,cAAM,WAAW,KAAK,QAAQ,aAAa,YAAY;AAEvD,YAAI,CAAE,MAAM,gBAAAA,QAAG,WAAW,QAAQ,GAAI;AACpC,eAAK,MAAM,UAAU,IAAI,aAAa;AACtC;AAAA,QACF;AAKA,cAAM,WAAW,yCAAyC,YAAY,IAAI,WAAW;AAAA,MACvF,OAAO;AAEL,cAAM,WAAW,yCAAyC,WAAW;AAAA,MACvE;AAEA,WAAK,KAAK,mCAAmC;AAC7C,YAAM,WAAW,eAAe,WAAW;AAE3C,WAAK,QAAQ,+BAA+B;AAAA,IAC9C,SAAS,GAAY;AACnB,UAAI,aAAa,OAAO;AACtB,aAAK,MAAM,6BAA6B,EAAE,OAAO,EAAE;AAAA,MACrD,OAAO;AACL,aAAK,MAAM,6BAA6B,OAAO,CAAC,CAAC,EAAE;AAAA,MACrD;AAAA,IACF;AAAA,EACF;AACF;","names":["fs"]}
|
|
@@ -5,7 +5,10 @@ declare class RunCommand extends BaseCommand {
|
|
|
5
5
|
static description: string;
|
|
6
6
|
static requiresProject: boolean;
|
|
7
7
|
static args: CommandDefinition;
|
|
8
|
-
run(options:
|
|
8
|
+
run(options: {
|
|
9
|
+
script: string;
|
|
10
|
+
args?: string[];
|
|
11
|
+
}): Promise<void>;
|
|
9
12
|
}
|
|
10
13
|
|
|
11
14
|
export { RunCommand as default };
|
package/dist/src/commands/run.js
CHANGED
|
@@ -20,7 +20,11 @@ var RunCommand = class extends BaseCommand {
|
|
|
20
20
|
static requiresProject = true;
|
|
21
21
|
static args = {
|
|
22
22
|
args: [
|
|
23
|
-
{
|
|
23
|
+
{
|
|
24
|
+
name: "script",
|
|
25
|
+
required: true,
|
|
26
|
+
description: "The script to run (script-name OR module:script-name)"
|
|
27
|
+
},
|
|
24
28
|
{ name: "args...", required: false, description: "Arguments for the script" }
|
|
25
29
|
]
|
|
26
30
|
};
|
|
@@ -56,7 +60,11 @@ var RunCommand = class extends BaseCommand {
|
|
|
56
60
|
return;
|
|
57
61
|
}
|
|
58
62
|
} catch (e) {
|
|
59
|
-
|
|
63
|
+
if (e instanceof Error) {
|
|
64
|
+
this.error(`Failed to read package.json at ${execPath}: ${e.message}`);
|
|
65
|
+
} else {
|
|
66
|
+
this.error(`Failed to read package.json at ${execPath}: ${String(e)}`);
|
|
67
|
+
}
|
|
60
68
|
return;
|
|
61
69
|
}
|
|
62
70
|
const finalArgs = ["run", scriptName, "--", ...scriptArgs];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/run.ts"],"sourcesContent":["import { type CommandDefinition, BaseCommand, logger } from '@nexical/cli-core';\nimport fs from 'fs-extra';\nimport path from 'path';\nimport { spawn } from 'child_process';\nimport process from 'node:process';\n\nexport default class RunCommand extends BaseCommand {\n
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/run.ts"],"sourcesContent":["import { type CommandDefinition, BaseCommand, logger } from '@nexical/cli-core';\nimport fs from 'fs-extra';\nimport path from 'path';\nimport { spawn } from 'child_process';\nimport process from 'node:process';\n\nexport default class RunCommand extends BaseCommand {\n static usage = 'run <script> [args...]';\n static description = 'Run a script inside the Nexical environment.';\n static requiresProject = true;\n\n static args: CommandDefinition = {\n args: [\n {\n name: 'script',\n required: true,\n description: 'The script to run (script-name OR module:script-name)',\n },\n { name: 'args...', required: false, description: 'Arguments for the script' },\n ],\n };\n\n async run(options: { script: string; args?: string[] }) {\n const projectRoot = this.projectRoot as string;\n const script = options.script;\n const scriptArgs = options.args || [];\n\n if (!script) {\n this.error('Please specify a script to run.');\n return;\n }\n\n logger.debug('Run command context:', { script, args: scriptArgs, projectRoot });\n\n let execPath = projectRoot;\n let scriptName = script;\n\n // Handle module:script syntax\n if (script.includes(':')) {\n const [moduleName, name] = script.split(':');\n execPath = path.resolve(projectRoot, 'modules', moduleName);\n scriptName = name;\n\n logger.debug(`Resolving module script: ${moduleName}:${scriptName} at ${execPath}`);\n } else {\n logger.debug(`Resolving core script: ${scriptName} at ${execPath}`);\n }\n\n // Validate script existence\n const pkgJsonPath = path.join(execPath, 'package.json');\n if (!(await fs.pathExists(pkgJsonPath))) {\n this.error(`Failed to find package.json at ${execPath}`);\n return;\n }\n\n try {\n const pkg = await fs.readJson(pkgJsonPath);\n if (!pkg.scripts || !pkg.scripts[scriptName]) {\n const type = script.includes(':') ? `module ${script.split(':')[0]}` : 'Nexical core';\n this.error(`Script \"${scriptName}\" does not exist in ${type}`);\n return;\n }\n } catch (e: unknown) {\n if (e instanceof Error) {\n this.error(`Failed to read package.json at ${execPath}: ${e.message}`);\n } else {\n this.error(`Failed to read package.json at ${execPath}: ${String(e)}`);\n }\n return;\n }\n\n const finalArgs = ['run', scriptName, '--', ...scriptArgs];\n logger.debug(`Executing: npm ${finalArgs.join(' ')} in ${execPath}`);\n\n const child = spawn('npm', finalArgs, {\n cwd: execPath,\n stdio: 'inherit',\n env: {\n ...process.env,\n FORCE_COLOR: '1',\n },\n });\n\n // Handle process termination to kill child\n const cleanup = () => {\n child.kill();\n process.exit();\n };\n\n process.on('SIGINT', cleanup);\n process.on('SIGTERM', cleanup);\n\n await new Promise<void>((resolve) => {\n child.on('close', (code) => {\n // Remove listeners to prevent memory leaks if this command is run multiple times in-process (e.g. tests)\n process.off('SIGINT', cleanup);\n process.off('SIGTERM', cleanup);\n\n if (code !== 0) {\n process.exit(code || 1);\n }\n resolve();\n });\n });\n }\n}\n"],"mappings":";;;;;;;;;;AAAA;AACA,sBAAe;AADf,SAAiC,aAAa,cAAc;AAE5D,OAAO,UAAU;AACjB,SAAS,aAAa;AACtB,OAAO,aAAa;AAEpB,IAAqB,aAArB,cAAwC,YAAY;AAAA,EAClD,OAAO,QAAQ;AAAA,EACf,OAAO,cAAc;AAAA,EACrB,OAAO,kBAAkB;AAAA,EAEzB,OAAO,OAA0B;AAAA,IAC/B,MAAM;AAAA,MACJ;AAAA,QACE,MAAM;AA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AAE,OAAO,EAAE;AAAA,MACvE,OAAO;AACL,aAAK,MAAM,kCAAkC,QAAQ,KAAK,OAAO,CAAC,CAAC,EAAE;AAAA,MACvE;AACA;AAAA,IACF;AAEA,UAAM,YAAY,CAAC,OAAO,YAAY,MAAM,GAAG,UAAU;AACzD,WAAO,MAAM,kBAAkB,UAAU,KAAK,GAAG,CAAC,OAAO,QAAQ,EAAE;AAEnE,UAAM,QAAQ,MAAM,OAAO,WAAW;AAAA,MACpC,KAAK;AAAA,MACL,OAAO;AAAA,MACP,KAAK;AAAA,QACH,GAAG,QAAQ;AAAA,QACX,aAAa;AAAA,MACf;AAAA,IACF,CAAC;AAGD,UAAM,UAAU,MAAM;AACpB,YAAM,KAAK;AACX,cAAQ,KAAK;AAAA,IACf;AAEA,YAAQ,GAAG,UAAU,OAAO;AAC5B,YAAQ,GAAG,WAAW,OAAO;AAE7B,UAAM,IAAI,QAAc,CAAC,YAAY;AACnC,YAAM,GAAG,SAAS,CAAC,SAAS;AAE1B,gBAAQ,IAAI,UAAU,OAAO;AAC7B,gBAAQ,IAAI,WAAW,OAAO;AAE9B,YAAI,SAAS,GAAG;AACd,kBAAQ,KAAK,QAAQ,CAAC;AAAA,QACxB;AACA,gBAAQ;AAAA,MACV,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;","names":["fs"]}
|
|
@@ -21,7 +21,7 @@ var SetupCommand = class extends BaseCommand {
|
|
|
21
21
|
process.exit(1);
|
|
22
22
|
}
|
|
23
23
|
const apps = ["frontend", "backend"];
|
|
24
|
-
const sharedAssets = ["prisma", "src", "public", "locales", "scripts"
|
|
24
|
+
const sharedAssets = ["prisma", "src", "public", "locales", "scripts"];
|
|
25
25
|
for (const app of apps) {
|
|
26
26
|
const appDir = path.join(rootDir, "apps", app);
|
|
27
27
|
if (!import_fs_extra.default.existsSync(appDir)) {
|
|
@@ -40,16 +40,21 @@ var SetupCommand = class extends BaseCommand {
|
|
|
40
40
|
const destDir = path.dirname(dest);
|
|
41
41
|
await import_fs_extra.default.ensureDir(destDir);
|
|
42
42
|
try {
|
|
43
|
-
|
|
43
|
+
import_fs_extra.default.lstatSync(dest);
|
|
44
44
|
import_fs_extra.default.removeSync(dest);
|
|
45
45
|
} catch (e) {
|
|
46
|
-
if (e.code !== "ENOENT")
|
|
46
|
+
if (e && typeof e === "object" && "code" in e && e.code !== "ENOENT")
|
|
47
|
+
throw e;
|
|
47
48
|
}
|
|
48
49
|
const relSource = path.relative(destDir, source);
|
|
49
50
|
await import_fs_extra.default.symlink(relSource, dest);
|
|
50
51
|
logger.debug(`Symlinked ${asset} to ${app}`);
|
|
51
52
|
} catch (e) {
|
|
52
|
-
|
|
53
|
+
if (e instanceof Error) {
|
|
54
|
+
this.error(`Failed to symlink ${asset} to ${app}: ${e.message}`);
|
|
55
|
+
} else {
|
|
56
|
+
this.error(`Failed to symlink ${asset} to ${app}: ${String(e)}`);
|
|
57
|
+
}
|
|
53
58
|
}
|
|
54
59
|
}
|
|
55
60
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/commands/setup.ts"],"sourcesContent":["import { BaseCommand, logger } from '@nexical/cli-core';\nimport fs from 'fs-extra';\nimport path from 'path';\n\nexport default class SetupCommand extends BaseCommand {\n
|
|
1
|
+
{"version":3,"sources":["../../../src/commands/setup.ts"],"sourcesContent":["import { BaseCommand, logger } from '@nexical/cli-core';\nimport fs from 'fs-extra';\nimport path from 'path';\n\nexport default class SetupCommand extends BaseCommand {\n static description = 'Setup the application environment by symlinking core assets.';\n\n async run() {\n // We assume we are in the project root\n // But the CLI might be run from anywhere?\n // findProjectRoot in index.ts handles finding the root.\n // BaseCommand has this.projectRoot?\n\n // BaseCommand doesn't expose projectRoot directly in current implementation seen in memory, checking source if possible?\n // InitCommand used process.cwd().\n\n // Let's assume process.cwd() is project root if run via `npm run setup` from root.\n const rootDir = process.cwd();\n\n // Verify we are in the right place\n if (!fs.existsSync(path.join(rootDir, 'core'))) {\n this.error('Could not find \"core\" directory. Are you in the project root?');\n process.exit(1);\n }\n\n const apps = ['frontend', 'backend'];\n const sharedAssets = ['prisma', 'src', 'public', 'locales', 'scripts']; // tsconfig might be needed if extended\n\n for (const app of apps) {\n const appDir = path.join(rootDir, 'apps', app);\n if (!fs.existsSync(appDir)) {\n this.warn(`App directory ${app} not found. Skipping.`);\n continue;\n }\n\n this.info(`Setting up ${app}...`);\n\n for (const asset of sharedAssets) {\n const source = path.join(rootDir, 'core', asset);\n const dest = path.join(appDir, asset);\n\n if (!fs.existsSync(source)) {\n this.warn(`Source asset ${asset} not found in core.`);\n continue;\n }\n\n try {\n // Remove existing destination if it exists (to ensure clean symlink)\n // Be careful not to delete real files if they aren't symlinks?\n // For now, we assume setup controls these.\n\n const destDir = path.dirname(dest);\n await fs.ensureDir(destDir);\n\n try {\n fs.lstatSync(dest);\n fs.removeSync(dest);\n } catch (e: unknown) {\n if (\n e &&\n typeof e === 'object' &&\n 'code' in e &&\n (e as { code: string }).code !== 'ENOENT'\n )\n throw e;\n }\n\n const relSource = path.relative(destDir, source);\n await fs.symlink(relSource, dest);\n\n logger.debug(`Symlinked ${asset} to ${app}`);\n } catch (e: unknown) {\n if (e instanceof Error) {\n this.error(`Failed to symlink ${asset} to ${app}: ${e.message}`);\n } else {\n this.error(`Failed to symlink ${asset} to ${app}: ${String(e)}`);\n }\n }\n }\n }\n\n this.success('Application setup complete.');\n }\n}\n"],"mappings":";;;;;;;;;;AAAA;AACA,sBAAe;AADf,SAAS,aAAa,cAAc;AAEpC,OAAO,UAAU;AAEjB,IAAqB,eAArB,cAA0C,YAAY;AAAA,EACpD,OAAO,cAAc;AAAA,EAErB,MAAM,MAAM;AAUV,UAAM,UAAU,QAAQ,IAAI;AAG5B,QAAI,CAAC,gBAAAA,QAAG,WAAW,KAAK,KAAK,SAAS,MAAM,CAAC,GAAG;AAC9C,WAAK,MAAM,+DAA+D;AAC1E,cAAQ,KAAK,CAAC;AAAA,IAChB;AAEA,UAAM,OAAO,CAA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;AACF;","names":["fs"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire } from "module"; const require = createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
discoverCommandDirectories
|
|
4
|
-
} from "../../chunk-
|
|
4
|
+
} from "../../chunk-AC4B3HPJ.js";
|
|
5
5
|
import "../../chunk-OYFWMYPG.js";
|
|
6
6
|
export {
|
|
7
7
|
discoverCommandDirectories
|
package/dist/src/utils/git.js
CHANGED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import eslintPluginAstro from 'eslint-plugin-astro';
|
|
2
|
+
import eslintPluginReact from 'eslint-plugin-react';
|
|
3
|
+
import eslintPluginReactHooks from 'eslint-plugin-react-hooks';
|
|
4
|
+
import eslintPluginJsxA11y from 'eslint-plugin-jsx-a11y';
|
|
5
|
+
import eslintConfigPrettier from 'eslint-config-prettier';
|
|
6
|
+
import tseslint from 'typescript-eslint';
|
|
7
|
+
import globals from 'globals';
|
|
8
|
+
import js from '@eslint/js';
|
|
9
|
+
|
|
10
|
+
export default tseslint.config(
|
|
11
|
+
// Global ignore
|
|
12
|
+
{
|
|
13
|
+
ignores: ['**/dist/**', '**/node_modules/**', '**/coverage/**', '**/.astro/**', '**/.agent/**'],
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
// Base JS/TS configuration
|
|
17
|
+
js.configs.recommended,
|
|
18
|
+
...tseslint.configs.recommended,
|
|
19
|
+
|
|
20
|
+
// React configuration
|
|
21
|
+
{
|
|
22
|
+
files: ['**/*.{js,jsx,mjs,cjs,ts,tsx}'],
|
|
23
|
+
plugins: {
|
|
24
|
+
react: eslintPluginReact,
|
|
25
|
+
'react-hooks': eslintPluginReactHooks,
|
|
26
|
+
'jsx-a11y': eslintPluginJsxA11y,
|
|
27
|
+
},
|
|
28
|
+
languageOptions: {
|
|
29
|
+
parserOptions: {
|
|
30
|
+
ecmaFeatures: {
|
|
31
|
+
jsx: true,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
globals: {
|
|
35
|
+
...globals.browser,
|
|
36
|
+
...globals.node,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
settings: {
|
|
40
|
+
react: {
|
|
41
|
+
version: 'detect',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
rules: {
|
|
45
|
+
...eslintPluginReact.configs.recommended.rules,
|
|
46
|
+
...eslintPluginReactHooks.configs.recommended.rules,
|
|
47
|
+
...eslintPluginJsxA11y.configs.recommended.rules,
|
|
48
|
+
'react/react-in-jsx-scope': 'off', // Not needed in React 17+ or Astro
|
|
49
|
+
'react/no-unknown-property': 'off', // Conflicts with some Astro/Web Component patterns
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
// Astro configuration
|
|
54
|
+
...eslintPluginAstro.configs.recommended,
|
|
55
|
+
|
|
56
|
+
// Custom rules override
|
|
57
|
+
{
|
|
58
|
+
rules: {
|
|
59
|
+
'@typescript-eslint/no-unused-vars': ['error', { args: 'none', varsIgnorePattern: '^_' }],
|
|
60
|
+
'@typescript-eslint/no-explicit-any': 'warn', // Downgrade to warning for now as codebase has some anys
|
|
61
|
+
'no-console': ['warn', { allow: ['warn', 'error', 'info'] }],
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
// Prettier must be last to override conflicting rules
|
|
66
|
+
eslintConfigPrettier,
|
|
67
|
+
);
|
package/index.ts
CHANGED
|
@@ -8,31 +8,45 @@ import path from 'node:path';
|
|
|
8
8
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
9
9
|
|
|
10
10
|
const commandName = 'nexical';
|
|
11
|
-
const projectRoot = await findProjectRoot(commandName, process.cwd()) || process.cwd();
|
|
11
|
+
const projectRoot = (await findProjectRoot(commandName, process.cwd())) || process.cwd();
|
|
12
12
|
const coreCommandsDir = path.resolve(__dirname, './src/commands');
|
|
13
13
|
const additionalCommands = discoverCommandDirectories(projectRoot);
|
|
14
14
|
|
|
15
|
-
// Filter out
|
|
16
|
-
const filteredAdditional = additionalCommands.filter(dir => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
15
|
+
// Filter out duplicate core commands and source versions
|
|
16
|
+
const filteredAdditional = additionalCommands.filter((dir) => {
|
|
17
|
+
const resolvedDir = path.resolve(dir);
|
|
18
|
+
const resolvedCore = path.resolve(coreCommandsDir);
|
|
19
|
+
|
|
20
|
+
if (resolvedDir === resolvedCore) return false;
|
|
21
|
+
|
|
22
|
+
// Check if this is another instance of the core CLI commands (by checking path suffix)
|
|
23
|
+
const coreSuffix = path.join('@nexical', 'cli', 'dist', 'src', 'commands');
|
|
24
|
+
const coreSuffixSrc = path.join('packages', 'cli', 'dist', 'src', 'commands');
|
|
25
|
+
const coreSuffixRawSrc = path.join('packages', 'cli', 'src', 'commands');
|
|
26
|
+
|
|
27
|
+
if (
|
|
28
|
+
resolvedDir.endsWith(coreSuffix) ||
|
|
29
|
+
resolvedDir.endsWith(coreSuffixSrc) ||
|
|
30
|
+
resolvedDir.endsWith(coreSuffixRawSrc)
|
|
31
|
+
) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Handle mismatch between dist/src and src/
|
|
36
|
+
if (resolvedCore.includes(path.join(path.sep, 'dist', 'src', 'commands'))) {
|
|
37
|
+
const srcVersion = resolvedCore.replace(
|
|
38
|
+
path.join(path.sep, 'dist', 'src', 'commands'),
|
|
39
|
+
path.join(path.sep, 'src', 'commands'),
|
|
40
|
+
);
|
|
41
|
+
if (resolvedDir === srcVersion) return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return true;
|
|
28
45
|
});
|
|
29
46
|
|
|
30
47
|
const app = new CLI({
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
coreCommandsDir,
|
|
35
|
-
...filteredAdditional
|
|
36
|
-
])]
|
|
48
|
+
version: pkg.version,
|
|
49
|
+
commandName: commandName,
|
|
50
|
+
searchDirectories: [...new Set([coreCommandsDir, ...filteredAdditional])],
|
|
37
51
|
});
|
|
38
52
|
app.start();
|
package/package.json
CHANGED
|
@@ -1,34 +1,58 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
2
|
+
"name": "@nexical/cli",
|
|
3
|
+
"version": "0.11.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"bin": {
|
|
6
|
+
"nexical": "./dist/index.js"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsup",
|
|
10
|
+
"dev": "tsup --watch",
|
|
11
|
+
"start": "node dist/index.js",
|
|
12
|
+
"test": "npm run test:unit && npm run test:integration && npm run test:e2e",
|
|
13
|
+
"test:unit": "vitest run --config vitest.config.ts --coverage",
|
|
14
|
+
"test:integration": "vitest run --config vitest.integration.config.ts",
|
|
15
|
+
"test:e2e": "npm run build && vitest run --config vitest.e2e.config.ts",
|
|
16
|
+
"test:watch": "vitest",
|
|
17
|
+
"format": "prettier --write .",
|
|
18
|
+
"lint": "eslint .",
|
|
19
|
+
"lint:fix": "eslint . --fix",
|
|
20
|
+
"prepare": "husky"
|
|
21
|
+
},
|
|
22
|
+
"lint-staged": {
|
|
23
|
+
"**/*": [
|
|
24
|
+
"prettier --write --ignore-unknown"
|
|
25
|
+
],
|
|
26
|
+
"**/*.{js,jsx,ts,tsx,astro}": [
|
|
27
|
+
"eslint --fix"
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@nexical/cli-core": "^0.1.12",
|
|
32
|
+
"yaml": "^2.3.4",
|
|
33
|
+
"fast-glob": "^3.3.3"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/fs-extra": "^11.0.4",
|
|
37
|
+
"@types/node": "^20.10.0",
|
|
38
|
+
"@vitest/coverage-v8": "^4.0.15",
|
|
39
|
+
"execa": "^9.6.1",
|
|
40
|
+
"fs-extra": "^11.3.2",
|
|
41
|
+
"tsup": "^8.0.1",
|
|
42
|
+
"tsx": "^4.21.0",
|
|
43
|
+
"typescript": "^5.3.3",
|
|
44
|
+
"vitest": "^4.0.15",
|
|
45
|
+
"@eslint/js": "^9.39.2",
|
|
46
|
+
"eslint": "^9.39.2",
|
|
47
|
+
"eslint-config-prettier": "^10.1.8",
|
|
48
|
+
"eslint-plugin-astro": "^1.5.0",
|
|
49
|
+
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
50
|
+
"eslint-plugin-react": "^7.37.5",
|
|
51
|
+
"eslint-plugin-react-hooks": "^7.0.1",
|
|
52
|
+
"globals": "^17.2.0",
|
|
53
|
+
"husky": "^9.1.7",
|
|
54
|
+
"lint-staged": "^16.2.7",
|
|
55
|
+
"prettier": "^3.8.1",
|
|
56
|
+
"typescript-eslint": "^8.54.0"
|
|
57
|
+
}
|
|
34
58
|
}
|
package/src/commands/init.ts
CHANGED
|
@@ -5,82 +5,85 @@ import fs from 'fs-extra';
|
|
|
5
5
|
import path from 'path';
|
|
6
6
|
|
|
7
7
|
export default class InitCommand extends BaseCommand {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
try {
|
|
45
|
-
this.info('Cloning starter repository...');
|
|
46
|
-
await git.clone(repoUrl, targetPath, { recursive: true });
|
|
47
|
-
|
|
48
|
-
this.info('Updating submodules...');
|
|
49
|
-
await git.updateSubmodules(targetPath);
|
|
50
|
-
|
|
51
|
-
this.info('Installing dependencies...');
|
|
52
|
-
await runCommand('npm install', targetPath);
|
|
53
|
-
|
|
54
|
-
this.info('Setting up upstream remote...');
|
|
55
|
-
await git.renameRemote('origin', 'upstream', targetPath);
|
|
56
|
-
|
|
57
|
-
// Run setup script
|
|
58
|
-
this.info('Running project setup...');
|
|
59
|
-
await runCommand('npm run setup', targetPath);
|
|
60
|
-
|
|
61
|
-
// Check for nexical.yaml, if not present create a default one
|
|
62
|
-
const configPath = path.join(targetPath, 'nexical.yaml');
|
|
63
|
-
if (!await fs.pathExists(configPath)) {
|
|
64
|
-
this.info('Creating default nexical.yaml...');
|
|
65
|
-
await fs.writeFile(configPath, 'name: ' + path.basename(targetPath) + '\nmodules: []\n');
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Create VERSION file
|
|
69
|
-
const versionPath = path.join(targetPath, 'VERSION');
|
|
70
|
-
// Check if version file exists, if not create it
|
|
71
|
-
if (!await fs.pathExists(versionPath)) {
|
|
72
|
-
this.info('Creating VERSION file with 0.1.0...');
|
|
73
|
-
await fs.writeFile(versionPath, '0.1.0');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
await git.addAll(targetPath);
|
|
77
|
-
await git.commit('Initial site commit', targetPath);
|
|
78
|
-
|
|
79
|
-
this.success(`Project initialized successfully in ${directory}!`);
|
|
8
|
+
static usage = 'init';
|
|
9
|
+
static description = 'Initialize a new Nexical project.';
|
|
10
|
+
static requiresProject = false;
|
|
11
|
+
|
|
12
|
+
static args: CommandDefinition = {
|
|
13
|
+
args: [
|
|
14
|
+
{ name: 'directory', required: true, description: 'Directory to initialize the project in' },
|
|
15
|
+
],
|
|
16
|
+
options: [
|
|
17
|
+
{
|
|
18
|
+
name: '--repo <url>',
|
|
19
|
+
description: 'Starter repository URL (supports gh@owner/repo syntax)',
|
|
20
|
+
default: 'gh@nexical/app-starter',
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
async run(options: { directory: string; repo: string }) {
|
|
26
|
+
const directory = options.directory;
|
|
27
|
+
const targetPath = path.resolve(process.cwd(), directory);
|
|
28
|
+
const repoUrl = resolveGitUrl(options.repo);
|
|
29
|
+
|
|
30
|
+
logger.debug('Init options:', { directory, targetPath, repoUrl });
|
|
31
|
+
|
|
32
|
+
this.info(`Initializing project in: ${targetPath}`);
|
|
33
|
+
this.info(`Using starter repository: ${repoUrl}`);
|
|
34
|
+
|
|
35
|
+
if (await fs.pathExists(targetPath)) {
|
|
36
|
+
if ((await fs.readdir(targetPath)).length > 0) {
|
|
37
|
+
this.error(`Directory ${directory} is not empty.`);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
await fs.mkdir(targetPath, { recursive: true });
|
|
42
|
+
}
|
|
80
43
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
44
|
+
try {
|
|
45
|
+
this.info('Cloning starter repository...');
|
|
46
|
+
await git.clone(repoUrl, targetPath, { recursive: true });
|
|
47
|
+
|
|
48
|
+
this.info('Updating submodules...');
|
|
49
|
+
await git.updateSubmodules(targetPath);
|
|
50
|
+
|
|
51
|
+
this.info('Installing dependencies...');
|
|
52
|
+
await runCommand('npm install', targetPath);
|
|
53
|
+
|
|
54
|
+
this.info('Setting up upstream remote...');
|
|
55
|
+
await git.renameRemote('origin', 'upstream', targetPath);
|
|
56
|
+
|
|
57
|
+
// Run setup script
|
|
58
|
+
this.info('Running project setup...');
|
|
59
|
+
await runCommand('npm run setup', targetPath);
|
|
60
|
+
|
|
61
|
+
// Check for nexical.yaml, if not present create a default one
|
|
62
|
+
const configPath = path.join(targetPath, 'nexical.yaml');
|
|
63
|
+
if (!(await fs.pathExists(configPath))) {
|
|
64
|
+
this.info('Creating default nexical.yaml...');
|
|
65
|
+
await fs.writeFile(configPath, 'name: ' + path.basename(targetPath) + '\nmodules: []\n');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Create VERSION file
|
|
69
|
+
const versionPath = path.join(targetPath, 'VERSION');
|
|
70
|
+
// Check if version file exists, if not create it
|
|
71
|
+
if (!(await fs.pathExists(versionPath))) {
|
|
72
|
+
this.info('Creating VERSION file with 0.1.0...');
|
|
73
|
+
await fs.writeFile(versionPath, '0.1.0');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
await git.addAll(targetPath);
|
|
77
|
+
await git.commit('Initial site commit', targetPath);
|
|
78
|
+
|
|
79
|
+
this.success(`Project initialized successfully in ${directory}!`);
|
|
80
|
+
} catch (error: unknown) {
|
|
81
|
+
if (error instanceof Error) {
|
|
82
|
+
this.error(`Failed to initialize project: ${error.message}`);
|
|
83
|
+
} else {
|
|
84
|
+
this.error(`Failed to initialize project: ${String(error)}`);
|
|
85
|
+
}
|
|
86
|
+
process.exit(1);
|
|
85
87
|
}
|
|
88
|
+
}
|
|
86
89
|
}
|