update / updater-contributing

Moves CONTRIBUTING.md, ISSUE_TEMPLATE and PULL_REQUEST_TEMPLATE files to the `.github` directory (with or without `.md` extension). Use from the command line when Update's CLI is installed globally, or use as a plugin in your own updater.
MIT License
4 stars 1 forks source link

add rendering and loading from `templates/` directory, not just copying from cwd? #1

Open tunnckoCore opened 8 years ago

tunnckoCore commented 8 years ago

I'm opening this one for me, cuz I'm going to PR this tonight.

Because I have this CONTRIBUTING.md file template and need rendering.

Actually, is update trying to load templates from global ~/templates directory?

edit: btw, got the idea for something like is-template-file package - sounds reasonable to have such thing? So we will be able to skip render cycle if it's not needed. Maybe streaming plugin.

jonschlinkert commented 8 years ago

is-template-file package - sounds reasonable to have such thing?

I can't remember if ~/templates was implemented here as thoroughly as it was in generate. This is the code generate uses for resolving templates in user home:

app.onLoad(/(^|[\\\/])templates[\\\/]/, function(file, next) {
  var userDefined = app.home('templates', file.relative);
  if (utils.exists(userDefined)) {
    file.contents = fs.readFileSync(userDefined);
  } else {
    userDefined = app.home('templates', file.basename)
    if (utils.exists(userDefined)) {
      file.contents = fs.readFileSync(userDefined);
    }
  }
  if (/^templates[\\\/]/.test(file.relative)) {
    file.path = path.join(app.cwd, file.basename);
  }
  next(null, file);
});

So we will be able to skip render cycle if it's not needed

Can you clarify? Wouldn't render already be skipped if the file doesn't exist? lol

tunnckoCore commented 8 years ago

Wouldn't render already be skipped if the file doesn't exist? lol

Not sure enough. Should review assemble-render-file again lol, but yea, maybe.

tunnckoCore commented 8 years ago

@jonschlinkert actually index.js#L55-L57 yea it will skip the file. The idea is to skip the stuff before it, options mergin and etc. So if it is not a template file we can just use app.copy instead of app.src and app.render and etc. We will save some time.

it worth, imho.

jonschlinkert commented 8 years ago

So if it is not a template file we can just use app.copy instead of app.src and app.render and etc. We will save some time.

How would we differentiate between files that have templates variables that need to be resolved, and files that don't? might be nice to have a convention for this. I think

You can already disable rendering on individual files, I don't think options merging for a few files have any noticeable performance impact. I'm open to suggestions though

tunnckoCore commented 8 years ago

actually, i think i have idea. what about when src reads the contents check for currently used template delims and if exists, set file.data.render to true, otherwise false - then, in the renderfile we should add one more check to the file.isNull if - and it will skip da file. so it will automagically save some times.

sorry for not have formatting, but im on phone now

tunnckoCore commented 8 years ago

and to not forget, it should also be overidden if opts.render is given

edit: even if it not make sense to render if file isnt template edit2: nevermind. this issue is for totally other thing