Skip to content

Commit

Permalink
Merge pull request #167 from Cloud-Code-AI/166-bug-update-command-wit…
Browse files Browse the repository at this point in the history
…h-editor-installed-loses-the-scripts-to-run-editor

fix: update editor packages on update
  • Loading branch information
shreyashkgupta authored Dec 3, 2024
2 parents 139e8cf + cd7bff7 commit b0ae9cd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/create-app/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
35 changes: 35 additions & 0 deletions packages/create-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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'));
Expand Down

0 comments on commit b0ae9cd

Please sign in to comment.