Hey everybody, I am building a custom local package for a theme that I have and there are a few hundred files that I need to include in the package.js file. Is there a wildcard that I can use, or something to specify all files in this directory so that I don’t have to individually include all those?
I do something like this:
Write a helper script that will just give you all of the file paths you need to include, then copy-paste that into package.js.
Example script:
dir = require 'node-dir'
fs = require 'fs'
path = require 'path'
dir.files __dirname + '/public/images', (err, files) ->
paths = JSON.stringify(files.map (f) -> path.relative __dirname, f)
fs.writeFile 'assets.json', paths
It reads everything from the public/images
directory in the script’s folder and then dumps all those paths into an assets.json
file as a json array – which you can handily copy and paste into package.js.
(npm install node-dir
if you decide to use this particular script; but best to just write your own, using the idea.)
You’re a programmer, so you can program things to do things for you – use it
ps. My use case here was also making a theme work within Meteor. And of course it would be lovely if there was a wildcard path syntax or similar, but with the solution above it becomes a really small nice-to-have.
EDIT: Yeah, shock’s solution one post down is even simpler. I’m not very good with awk so I need to resort to writing more than just a couple of shell commands.
I usually go simple unix way
Roberts-MacBook-Pro:shockitv-twitch shock$ find lib -type f | awk '{print "\"" $1 "\"\,"}'
"lib/server/clear_twitch.js",
"lib/server/core.js",
"lib/server/cron.js",
"lib/server/startup.js",
"lib/server/twitch_fetch.js",
Roberts-MacBook-Pro:shockitv-twitch shock$
Thanks guys. Good suggestions. I was using tree with some switches, but then I would still need to get it into JSON format. Sometimes it doesn’t even occur to you to write a program to help you write a program, lol. Awesome, appreciate the help!
I have tried so many different ways to integrate this theme, but it won’t render correctly. Is there any way you could help me to get it working? I would be happy to compensate you via paypal for your time and effort. I really want to get this theme working.
well, you never mentioned what kind of theme it is, it if is some bunch of css or what exactly
so hard to comment on that.