wclr / yalc

Work with yarn/npm packages locally like a boss.
MIT License
5.64k stars 147 forks source link

Add yalc publish for monorepos #131

Closed fivethreeo closed 4 years ago

fivethreeo commented 4 years ago

Would be great if it would be possible to do yalc publish —use-lerna

That would publish all packages and if you use —update it would propagate those to any dependent projects.

I could do this with jq output from lerna.json piped to xargs with yalc publish but if it was built in, that would be awesome 😀

fivethreeo commented 4 years ago

A workaround for now :)

jq '.packages | join(" ")' --raw-output lerna.json |
  xargs -I {} sh -c 'echo {}' |
  tr '[\n ]' '\n' |
  xargs -n1 -I {} bash -c '{\
    echo cd "{}" &&
    echo yalc publish --update &&
    echo cd .. \
  ;}'

jq '.packages | join(" ")' --raw-output lerna.json |
  xargs -I {} sh -c 'echo {}' |
  tr '[\n ]' '\n' |
  xargs -I {} basename {} |
  xargs -n1 -I {} bash -c '\
    echo yalc add {}'
wclr commented 4 years ago

Don't think that yalc should support such deep workspace logic which of differs for didfferent PMs and tools like lerna, it is ok to have your own script for such task, node based script would be more compact than bash though.

fivethreeo commented 4 years ago

Quite understandable, just do one task and do it well. 😀

But how is support for using yalc as a library? Has it got a stable api and is it decoupled from the cli?

wclr commented 4 years ago

Has it got a stable api and is it decoupled from the cli?

For what task, what should be exposed? Some methods are actually can be available using for example:

import { addPackages } from 'yalc/src/add'
mrassili commented 4 years ago

A workaround for now :)

jq '.packages | join(" ")' --raw-output lerna.json |
  xargs -I {} sh -c 'echo {}' |
  tr '[\n ]' '\n' |
  xargs -n1 -I {} bash -c '{\
    echo cd "{}" &&
    echo yalc publish --update &&
    echo cd .. \
  ;}'

jq '.packages | join(" ")' --raw-output lerna.json |
  xargs -I {} sh -c 'echo {}' |
  tr '[\n ]' '\n' |
  xargs -I {} basename {} |
  xargs -n1 -I {} bash -c '\
    echo yalc add {}'

how does this work? can you please elaborate

fivethreeo commented 4 years ago

First jq queries lerna json for the packages array and joins it with " " and returns it without quotes. Then it pipes the output to xargs that uses each space separated string as a {} placeholder then runs sh with echo so the glob string is expanded and printed. Then tr replaces all spaces with newlines then pipes to xargs that takes each line one by one and uses each line as a {} placeholder then runs bash with the publish command in the correct directory.

On Tue, 11 Aug 2020 at 17:57, Marouane R notifications@github.com wrote:

A workaround for now :)

jq '.packages | join(" ")' --raw-output lerna.json | xargs -I {} sh -c 'echo {}' | tr '[\n ]' '\n' | xargs -n1 -I {} bash -c '{\ echo cd "{}" && echo yalc publish --update && echo cd .. \ ;}'

jq '.packages | join(" ")' --raw-output lerna.json | xargs -I {} sh -c 'echo {}' | tr '[\n ]' '\n' | xargs -I {} basename {} | xargs -n1 -I {} bash -c '\ echo yalc add {}'

how does this work? can you please elaborate

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/whitecolor/yalc/issues/131#issuecomment-672042597, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAADGQ4EKILQL3TV7I5RHTSAFTAJANCNFSM4PSFEKRQ .

-- Øyvind Saltvik

mrassili commented 4 years ago

First jq queries lerna json for the packages array and joins it with " " and returns it without quotes. Then it pipes the output to xargs that uses each space separated string as a {} placeholder then runs sh with echo so the glob string is expanded and printed. Then tr replaces all spaces with newlines then pipes to xargs that takes each line one by one and uses each line as a {} placeholder then runs bash with the publish command in the correct directory. On Tue, 11 Aug 2020 at 17:57, Marouane R @.***> wrote: A workaround for now :) jq '.packages | join(" ")' --raw-output lerna.json | xargs -I {} sh -c 'echo {}' | tr '[\n ]' '\n' | xargs -n1 -I {} bash -c '{\ echo cd "{}" && echo yalc publish --update && echo cd .. \ ;}' jq '.packages | join(" ")' --raw-output lerna.json | xargs -I {} sh -c 'echo {}' | tr '[\n ]' '\n' | xargs -I {} basename {} | xargs -n1 -I {} bash -c '\ echo yalc add {}' how does this work? can you please elaborate — You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub <#131 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAADGQ4EKILQL3TV7I5RHTSAFTAJANCNFSM4PSFEKRQ . -- Øyvind Saltvik

Thanks @fivethreeo I'm not familiar with lerna, and don't have a lerna.json in my project But I followed the reasoning and cd'ed into the packages to publish 'em, still not so smooth :/

fivethreeo commented 4 years ago

Are you using workspaces?

On Wed, 12 Aug 2020 at 15:53, Marouane R notifications@github.com wrote:

First jq queries lerna json for the packages array and joins it with " " and returns it without quotes. Then it pipes the output to xargs that uses each space separated string as a {} placeholder then runs sh with echo so the glob string is expanded and printed. Then tr replaces all spaces with newlines then pipes to xargs that takes each line one by one and uses each line as a {} placeholder then runs bash with the publish command in the correct directory. … <#m-3911707517640715863> On Tue, 11 Aug 2020 at 17:57, Marouane R @.***> wrote: A workaround for now :) jq '.packages | join(" ")' --raw-output lerna.json | xargs -I {} sh -c 'echo {}' | tr '[\n ]' '\n' | xargs -n1 -I {} bash -c '{\ echo cd "{}" && echo yalc publish --update && echo cd .. \ ;}' jq '.packages | join(" ")' --raw-output lerna.json | xargs -I {} sh -c 'echo {}' | tr '[\n ]' '\n' | xargs -I {} basename {} | xargs -n1 -I {} bash -c '\ echo yalc add {}' how does this work? can you please elaborate — You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub <#131 (comment) https://github.com/whitecolor/yalc/issues/131#issuecomment-672042597>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAADGQ4EKILQL3TV7I5RHTSAFTAJANCNFSM4PSFEKRQ . -- Øyvind Saltvik

Thanks @fivethreeo https://github.com/fivethreeo I'm not familiar with lerna, and don't have a lerna.json in my project But I followed the reasoning and cd'ed into the packages to publish 'em, still not so smooth :/

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/whitecolor/yalc/issues/131#issuecomment-672884389, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAADGX7QEPG6CX2BIMIQULSAKNEXANCNFSM4PSFEKRQ .

-- Øyvind Saltvik

mrassili commented 4 years ago

yarn workspaces? we have npm

fivethreeo commented 4 years ago
find packages/ -maxdepth 1 -mindepth 1 |
  xargs -n1 -I {} bash -c '{\
    cd "{}" &&
    yalc publish --update &&
    cd .. \
    cd .. \
  ;}'

find packages/ -maxdepth 1 -mindepth 1 |
  xargs -n1 -I {} basename {} |
  xargs -n1 -I {} bash -c '\
    echo yalc add {}'