Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(shadcn-ui): Rename add executor to add-component #265

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions packages/firebase-hosting/src/executors/deploy/deploy.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@ export interface ExecutorSchema {
message?: string
}

export function deployExecutor(
export async function deployExecutor(
options: ExecutorSchema
// context: ExecutorContext
): Promise<{ success: boolean }> {
// Make sure the deployment target is defined
execPackageManagerCommand(buildCommand([
'firebase target:apply',
'firebase-tools target:apply',
`hosting ${options.site} ${options.identifier || options.site}`,

options.project && `--project=${options.project}`
]))

return Promise.resolve(execPackageManagerCommand(buildCommand([
'firebase deploy',
`--only=hosting:${options.site}`,
return execPackageManagerCommand(buildCommand([
'firebase-tools deploy',
`--only=hosting:${options.site}`,

options.project && `--project=${options.project}`,
options.message && `-m "${options.message}"`
])
))
options.project && `--project=${options.project}`,
options.message && `-m "${options.message}"`
]))
}

export default deployExecutor
9 changes: 9 additions & 0 deletions packages/shadcn-ui/migrations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"generators": {
"change-add-executor": {
"version": "1.1.1",
"description": "'add' executor became reserved, changed to 'add-component'.",
"implementation": "./src/migrations/change-add-executor/change-add-executor"
}
}
}
2 changes: 1 addition & 1 deletion packages/shadcn-ui/src/generators/init/init.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default async function (tree: Tree, options: ShadecnUiSchema) {
updateProjectConfiguration(tree, uiLibOptions.projectName, {
...readProjectConfiguration(tree, uiLibOptions.projectName),
targets: {
add: {
'add-component': {
executor: '@nx-extend/shadcn-ui:add'
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { addProjectConfiguration, readProjectConfiguration } from '@nx/devkit'
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'

import type { Tree } from '@nx/devkit'

import update from './change-add-executor'

describe('change-function-gen migration', () => {
let tree: Tree

beforeEach(() => {
tree = createTreeWithEmptyWorkspace()
})

it('should run successfully', async () => {
addProjectConfiguration(tree, 'renamedAdd', {
root: 'renamedAdd',
targets: {
addComponent: {
executor: '@nx-extend/shadcn-ui:add'
}
}
})

addProjectConfiguration(tree, 'oldAdd', {
root: 'oldAdd',
targets: {
add: {
executor: '@nx-extend/shadcn-ui:add',
options: {
foo: 'bar'
}
}
}
})

await update(tree)

expect(readProjectConfiguration(tree, 'renamedAdd')).toEqual(expect.objectContaining({
root: 'renamedAdd',
targets: {
addComponent: {
executor: '@nx-extend/shadcn-ui:add'
}
}
}))

expect(readProjectConfiguration(tree, 'oldAdd')).toEqual(expect.objectContaining({
root: 'oldAdd',
targets: {
'add-component': {
executor: '@nx-extend/shadcn-ui:add',
options: {
foo: 'bar'
}
}
}
}))
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Tree, updateProjectConfiguration } from '@nx/devkit'
import { getProjects } from 'nx/src/generators/utils/project-configuration'

/**
* Migrates all "add" targets with @nx-extend/shadcn-ui:add target to become "add-component"
*/
export default function update(tree: Tree) {
const projects = getProjects(tree)

for (const [name, project] of projects) {
const addTarget = Object.keys(project.targets).find((target) => (
project.targets[target].executor === '@nx-extend/shadcn-ui:add'
))

if (addTarget && addTarget === 'add') {
project.targets['add-component'] = project.targets[addTarget]
delete project.targets[addTarget]

updateProjectConfiguration(tree, name, project)
}
}
}
Loading