Closed tunnckoCore closed 7 years ago
I expect to have templates dir, in which I'll have a few templates and $package.json
then running $ gen
or $ gen dest charlike
to scaffold project and install deps to that new project's $package.json
.
You need a task that will "process" the templates so the install task knows what to install.
Add something like
app.task('foo', function() {
return app.src('**/*', {cwd: 'templates'})
.pipe(app.dest(app.cwd));
});
I thought, but it still not works here generate-charlike-templates/generator.js#L39-L47, there I have the processing.
Add the 'install'
task to the charlike task's dependencies after default. They need to be run in the same process.
... sorry typing on my phone
doh, yea... forgot that. but actually it still not works.
btw, side questions: can i hide the timings? as verb's times
on/off (if i remember); and how to change template delims - tried with app.option('delims', [..])
and app.option('engineOpts.delims', ...)
?
The install
task needs to run after the default
task. You put it in the dependencies array of the default
task.
Try it like this:
app.task('charlike', ['default', 'install'])
task(app, 'default', ['**/*'], [
'editorconfig',
'license-mit',
'travis'
])
or you can chain tasks together at the command line so you don't have to always run the install
task:
$ gen charlike charlike:install
Basically... generate-install
sets up middleware that will execute after a file is written (with app.dest
). If the file has a .data.install
property, then the values are added to the app.cache.install
array.
Now that the dependencies are cached on the app.cache.install
, you can run the install
task through the api
in your generator.js
file or through the cli
. The install
task will check the app.cache.install
properties and determine if it needs to install dependencies.
The main thing is that install
needs to be run in the same process as the task writing the files with app.dest
and after that task is run.
btw, side questions: can i hide the timings?
Pass an options
object to the ask you want to "silence" with silence: true
.
Try it like this:
it's the same for me. Because, it will run install
task after the default
task ends and it ends when travis
task ends. And written in your way it won't run install
task when just run $ gen
.
Pass an options object to the ask you want to "silence" with silence: true.
I'm not asking for the questions, but for timings - the time, starting taskName
, finished taskName
etc. It would be much clear and good if it only outputs the questions :)
I tracked down what's happening...
There are a few configuration issues in your project and there are some bugs that I'll open up issues for in a minute:
You should add a dependencies
or devDependencies
property to the install
property the front-matter in templates/foo.js
:
---
rename:
basename: bar.js
install:
dependencies: ['mukla']
---
dest
generator to change the directory, the files are being copied but the install task is still using process.cwd()
to check for a package.json
. (btw... you need a package.json in the dest directory so you might want to use generate-package
too).
This should be using app.cwd
.base-npm
is not telling spawn
where to run the npm
command, so that needs to be updated to use the app.cwd || process.cwd()
. I've tested this locally and it's working, I'll open tickets in a minute.On another note, you should change your charlike
task to be doing something like what default
is doing and have default
run the charlike
task. This will let you run the generator from another folder when it's globally installed (at least it'll be easier):
$ gen charlike-templates
Right now, I'd have to run the following command to get the charlike
task to run:
$ gen charlike-templates:charlike
I hope all this makes sense. Thanks for opening the issue since it helped track down a couple of those other issues.
You should add a
dependencies
ordevDependencies
property to theinstall
property.
I doubled checked this and you can do install: ['mukla']
and it'll default to devDependencies
. The real issue is that generate-install
checking the wrong package.json
to see if it's already installed. I got a false-positive because I used dependencies
instead of devDependencies
when I tested it.
@doowb @jonschlinkert seems to work tonight. I was sure I reinstalled and cleaned cache few times before opening issues... yesterday didn't work, tonight yes. Let's stay open for few days?
Now I have another issue/thought/suggest and will open it.
seems to work tonight. I was sure I reinstalled and cleaned cache few times before opening issues... yesterday didn't work, tonight yes. Let's stay open for few days?
how about if we close instead and just reopen if it happens again. or we can start a new issue? that sound ok? thanks for the update.
:+1:
thanks!
There's something wrong. It seems it not works as expected, maybe I'm missing something.
But let's say we have directory
woo/
. In it we havetemplates/
in which we havepackage.json
andfoo.js
.foo.js contains
package.json contains (intentionally called
package.json
not$package.json
, even if it is prepend with$
things still not working)the woo/generator.js
Running
$ gen
errors with that there's nopackage.json
, okey I thought that it should be in the dir where thegenerator.js
is, so when I addedpackage.json
towoo/package.json
and running$ gen
now does not fail with error and exit with 0, but it seems it did nothing (didn't install themukla
).It's not actual example. Actual is https://github.com/tunnckoCore/generate-charlike-templates, which I adapted from
generate-project
where the things seems working.