From cd7bff7d7862b7a84e15f506de50c8ec58be897a Mon Sep 17 00:00:00 2001 From: Saurav Panda Date: Tue, 3 Dec 2024 08:47:16 -0800 Subject: [PATCH] fix: update editor packages on update --- packages/create-app/package.json | 2 +- packages/create-app/src/index.ts | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/packages/create-app/package.json b/packages/create-app/package.json index f31b0ad..84231e3 100644 --- a/packages/create-app/package.json +++ b/packages/create-app/package.json @@ -1,6 +1,6 @@ { "name": "create-akiradocs", - "version": "1.0.39", + "version": "1.0.40", "description": "Create Akira Docs documentation sites with one command", "main": "./dist/index.js", "type": "module", diff --git a/packages/create-app/src/index.ts b/packages/create-app/src/index.ts index f2ad2c0..5cda062 100644 --- a/packages/create-app/src/index.ts +++ b/packages/create-app/src/index.ts @@ -155,6 +155,16 @@ async function copyEditor(targetDir: string) { } } +async function isEditorInstalled(targetDir: string) { + try { + const editorDir = path.join(targetDir, 'editor'); + await readFile(path.join(editorDir, 'package.json'), 'utf-8'); + return true; + } catch (error) { + return false; + } +} + async function main() { const packageJsonPath = path.resolve(__dirname, '../package.json'); const packageJson = await readJson(packageJsonPath); @@ -236,6 +246,31 @@ async function main() { const templateDir = path.join(__dirname, '../template/default'); await updateDir(templateDir, '.'); + // Check if editor is installed + if (await isEditorInstalled('.')) { + spinner.text = 'Updating editor files...'; + const editorCopied = await copyEditor('.'); + + if (editorCopied) { + await updateEditorDependencies('.'); + + // Update package.json scripts + const pkgJsonPath = path.join('.', 'package.json'); + const pkgJson = JSON.parse(await readFile(pkgJsonPath, 'utf-8')); + pkgJson.scripts = { + ...pkgJson.scripts, + 'dev:editor': 'cd editor && npm run dev', + 'dev:docs': 'npm run dev', + 'dev:all': 'concurrently "npm run dev:docs" "npm run dev:editor"', + }; + pkgJson.devDependencies = { + ...pkgJson.devDependencies, + 'concurrently': '^8.0.0', + }; + await writeFile(pkgJsonPath, JSON.stringify(pkgJson, null, 2)); + } + } + spinner.succeed(chalk.green('Project updated successfully!')); console.log('\nNext steps:'); console.log(chalk.cyan(' npm install'));