Is there a way to add a json item to an array without a key? #104
-
Here is an example to clarify, I'm replacing bash scripting, and trying to avoid forced installation of local software to make this more available to someone without macos, or without a specific homebrew installed app, so using something like In a preset I'm installing laravel-filament. One of the steps is adding something to composer.json post-update-cmd array. I previously would do this via bash script in a step as follows: echo "installing laravel-filament"
composer require filament/filament
git commit -a -m "Installed laravel-filament"
jq '."scripts"."post-update-cmd" += ["@php artisan filament:upgrade"]' composer.json
git commit -a -m "Added filament post-update-cmd"
since await editFiles({
title: 'add post update artisan command to composer.json',
files: 'composer.json',
operations: [{
type: 'update-content',
update: (content) => content.replace(
'"@php artisan vendor:publish --tag=laravel-assets --ansi --force"',
`"@php artisan vendor:publish --tag=laravel-assets --ansi --force",
"@php artisan filament:upgrade"`),
}],
}) In this situation I need to assume that they will not have anything else in the post-update-cmd array. I've tried everything I could think of in this strategy, but was unable to make it work: await editFiles({
files: 'composer.json',
operations: [
// {type: 'edit-json', delete: ['scripts', 'devDependencies']},
{type: 'edit-json', merge: {'scripts': {'post-update-cmd':'"@php artisan filament:upgrade"'}}},
],
title: 'update package.json',
}) Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello! The following should work: await editFiles({
files: 'composer.json',
operations: [
{ type: 'edit-json', merge: { scripts: { 'post-update-cmd': ['@php artisan filament:upgrade'] } } },
],
title: 'update package.json',
}) The difference with your snippet is that |
Beta Was this translation helpful? Give feedback.
Hello! The following should work:
The difference with your snippet is that
post-update-cmd
is treated as an array.