From 2d8494ed635d7b8aa8c11908ca254fd8750fcd9e Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Sat, 25 Jan 2025 13:58:52 -0800 Subject: [PATCH] fix: migration for demo executors and workspace scripts --- .../migrations/update-5-5-0/update-5-5-0.ts | 56 ++++++++++++++++--- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/packages/plugin-tools/src/migrations/update-5-5-0/update-5-5-0.ts b/packages/plugin-tools/src/migrations/update-5-5-0/update-5-5-0.ts index 9817e83..4796f35 100644 --- a/packages/plugin-tools/src/migrations/update-5-5-0/update-5-5-0.ts +++ b/packages/plugin-tools/src/migrations/update-5-5-0/update-5-5-0.ts @@ -55,16 +55,40 @@ export default async function (tree: Tree) { '@nativescript/ios': '~8.8.0', }, }); - const angularDemoProject = 'apps/demo-angular/project.json'; - if (tree.exists(angularDemoProject)) { - updateJson(tree, angularDemoProject, (json) => { - if (json.targets?.build?.options) { - // ensure migrations to run against it - json.targets.build.options.tsConfig = 'apps/demo-angular/tsconfig.json'; - } - return json; - }); + // update demo project configs + const flavors = ['', 'angular', 'react', 'svelte', 'vue']; + for (const flavor of flavors) { + const projectBase = `apps/demo${flavor ? '-' + flavor : ''}`; + const projectConfigPath = `${projectBase}/project.json`; + if (tree.exists(projectConfigPath)) { + updateJson(tree, projectConfigPath, (json) => { + delete json.targets.ios; + delete json.targets.android; + json.targets.debug = { + executor: '@nativescript/nx:debug', + options: { + noHmr: true, + uglify: false, + release: false, + forDevice: false, + prepare: false, + }, + }; + json.targets.clean = { + executor: '@nativescript/nx:clean', + options: {}, + }; + + if (json.targets?.build?.options) { + json.targets.build.options.tsConfig = `${projectBase}/tsconfig.json`; + } + return json; + }); + } } + // update workspace scripts + fixWorkspaceScripts(tree); + updateJson(tree, 'nx.json', (json) => { json.release = { releaseTagPattern: '{version}-{projectName}', @@ -123,6 +147,20 @@ export default async function (tree: Tree) { console.log(`\n`); } +function fixWorkspaceScripts(tree: Tree) { + let workspaceScripts = tree.read('tools/workspace-scripts.js', 'utf-8'); + workspaceScripts = workspaceScripts.replace(`nx run demo:clean`, 'nx clean demo'); + workspaceScripts = workspaceScripts.replace(`nx run demo:ios`, 'nx debug demo ios'); + workspaceScripts = workspaceScripts.replace(`nx run demo:android`, 'nx debug demo android'); + const flavors = ['angular', 'react', 'svelte', 'vue']; + for (const flavor of flavors) { + workspaceScripts = workspaceScripts.replace(`nx run demo-${flavor}:clean`, `nx clean demo-${flavor}`); + workspaceScripts = workspaceScripts.replace(`nx run demo-${flavor}:ios`, `nx debug demo-${flavor} ios`); + workspaceScripts = workspaceScripts.replace(`nx run demo-${flavor}:android`, `nx debug demo-${flavor} android`); + } + tree.write('tools/workspace-scripts.js', workspaceScripts); +} + function updateDependencies(tree: Tree) { updateJson(tree, 'package.json', (json) => { if (json.devDependencies['@angular/core']) {