Open jacobkossman opened 10 months ago
i got you: https://github.com/AlleyFord/schematic?tab=readme-ov-file#running-on-a-single-section-file
beware, zero testing outside of making sure it can resolve paths =) HMU with any probs you encounter and i'll be happy to get fixes worked in
Amazing. On CLI, currently it only works on the liquid file, correct? Seems a little backwards, ideally you'd save the .js file since that is what would change the schema inside the liquid file.
Can the command be updated to pass in the schema.js file and where to look for section files (and have a sane default)? Similar to the new Schematic()
with a paths
object.
Currently my watch command for schematic watches my src/schema
folder for changes and invokes .run()
when something changes.
Also I'm having to use npm exec
since npx
doesn't accept a --prefix
type option but it seems the code doesn't honor that and i get the error: could not find required directories from this path. run in the shopify theme root?
even though my prefix is the correct path to a theme structure
that's a really good point: you'd watch the schema dir for changes and want the shopify files updated. interestingly, the way it works now is it starts with the shopify files then works backwards to resolve schema files, then applies that schema to the shopify files.
i think i can work something up. what may be a gotcha though is it'll be difficult to then apply any updated schema that would affect multiple files back into those files. for example, you change some icon definitions that are pulled into header.liquid
and footer.liquid
. you'd run something akin to npx schematic header.js
, that would get the new icon definitions into header.liquid
, but since it's only being run on one file, footer.liquid
wouldn't get updated.
would have to work out some more complicated way to scan & then update anything where there would be changes to schema. i think i'll build in the ability to pass a schema file path, and then leave dependency resolution up to the user. but a single execution of npx schematic
prior to some more formal build/package process would do it. stay tuned!
npm exec
with --prefix
vs npx
: can you edit your watch process to do something more akin to cd /path/to/shopify/root && npx schematic && cd -
? should put the shell into the shopify theme root, run whatever schematic command, then put the shell back into the previous directory
Awesome re: running on the .js file. I think it's the "right" way to do it.
However, if it's too much of a pain because of dependencies and the gotcha mentioned: maybe just an option to suppress the "found no change" type messages? So it would still run on the whole folder but would only show messages if it actually had changes.
My (admittedly quite unique) use case for this I have a parent theme base
and a child theme which uses base
as a submodule and has an instance
folder for .json data and overrides / customizations. I have a build step that merges base
and instance
into build
. So ideally I'd be able to run the commands in both repos.
Currently, the theme dev has the choice to either cd into base
themselves and run the npm scripts from there, or be able to use --prefix
. With a manual cd
in the command you could only run it in one of the repos I think.
Theoretically i could just have a note that says "run the watch task inside base" but not as slick lol. Not a huge deal, but maybe being able to specify the theme folder in the npx command or something 🤔
pushed a new minor ver which supports passing in a single file which can be liquid or schema (npx schematic section path/to/file
). i've done some lightttttt testing, seems OK, if you want to do some more?
the theme setup you're talking about is actually super interesting to me. i've been thinking about a solve for the same use case: you develop 1 theme to rule them all, then shopify instances you spin up use the base theme as a package, and can have localized override files. think a main theme which includes some default icons, then each instance of it can have its own appended icons. if you add a new whizbang feature to the base theme, all themes that use it can get it automatically by using npm
.
i'm doing this manually right now for two sites. i think once i get the underlying theme in a more developed spot, i may try to create something usable and publish it.
for your use case currently, wouldn't hurt to create your own way of invoking schematic outside of npx
(like in code) and then you should be able to pass path overrides to the constructor?
I think you're right, I'm just gonna use Schematic.runSection()
with my .js file and pass a file path in there so I'll report back if I run into any issues with it.
Yeah that's exactly what I've set up. It's a heavily modified Dawn with Tailwind supporting the font sizing, colors, etc. I set up Schematic to use the tailwind theme
which has access to the config values so if I add a new font size etc it will get updated throughout the theme. It's pretty sick, let me know if you wanna take a peek.
Testing out the new runSection I get this error:
[schematic:watch] /Users/jacob/Sites/prodigy-child/instance/src/schema/sections/custom-section.js: no schematic code
instance/src/schema/sections/custom-section.js:
module.exports = {
name: "Custom Section",
settings: []
};
instance/sections/custom-section.liquid:
<div>hello</div>
{%- comment -%} schematic 'sections/custom-section' {%- endcomment -%}
schematic.runSection(argv.path);
argv.path: ../instance/src/schema/sections/custom-section.js
Not sure if I'm doing something wrong, lemme know if you need more info. If i run the normal schematic.run()
it works properly.
can whip up a local test prob later today. my gut thinks it's maybe an issue with where the script is being executed. it wants to be executed in the shopify theme root, even if would be a child theme. if you're up for it, i'm happy to clone your repo and noodle until i can get a solution for ya
I don't think so, it no longer fails preCheck()
which was giving the not in theme root error. this seems to be an issue of it looking for refSchemaEx
(the schematic comment) inside the .js file.
https://github.com/AlleyFord/schematic/blob/0c0ba3afa112d068b6d45b056d9ac800f9ea1109/src/schematic.js#L311C9-L311C9
Hi again! Love this package.
I'm using it in a watch type task but obviously it runs through all of the files regardless of changes / re-parses them etc.
I was wondering if there's an existing way (or possible to add as a feature) to only parse a single file? I'm using https://github.com/open-cli-tools/chokidar-cli and it allows passing the path. This would mostly just be to clean up the excess terminal output messages that show up when running my
node schematic.js
command.Thanks!