-
-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remote Templates #329
Remote Templates #329
Conversation
- with nice symbol & formatting
- uses *sync versions, but oh well
- will need to verify a destination before extracting/downloading - will prompt (TODO) if incomplete - will abort if unsafe
- use more partial import statements
- uses which.sync 🙊 - update function calls - remove `async` from `pkgScripts`
- instead of checking 5x per `setup` function - return `async` function directly from `initialize`
- template concern
- only `default` & `full` for now
- PRs are still built
- somehow `recursive-copy` was picked up?
- WTF HAPPENING
Is there any chance a Travis caching is making this error? 🤔 I've run this a few times locally (using the same Node 8.x version) and the |
} | ||
} else { | ||
// TODO: interactive |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@developit Should we really do this? This make it more complex for us to handle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's save this discussion for a future PR. I want to break it up instead of making this (even more) massive.
exports.default = [ | ||
'.gitignore', | ||
'package.json', | ||
'README.md', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even when we use node-glob
, it sorts in the alphabetical order AFAIK. This might be an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does. The above is alpha-sorted 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and it always fails in my machine 😛
- no need anymore! - templates responsible own dependecies - and style-* flags removed
- OCD strikes again
- tell user to run `npm install` first
Fixed the tests! I made the (silly) mistake of not passing the Travis flags to my local tests 🤦♂️ . Once I did, was clear that the failures did relate to the However, in fixing it, I realized we don't even need the Reason being, templates are responsible for themselves. The rest of this PR assumes that, with the tiny exception of adding package
It's no longer our job in remote-template world. 🎉 More PRs to come, which will address all tasks & gotchas I've mentioned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from these comments, its gold. 👍
src/commands/create.js
Outdated
root: 'examples/root', | ||
simple: 'examples/simple' | ||
full: 'preactjs-templates/default', | ||
default: 'preactjs-templates/default', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why both full
& default
? Since they do the same thing.
Instead we can just add default
& simple
from templates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add simple
. @developit requested in Slack that we make default an alias of full
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was just thinking "principle of least surprise" here, this makes it work quite similarly to how it does in 1.0.
filter(path) { | ||
// TODO: remove `/build/` ?? | ||
// TODO: read & respond to meta/hooks | ||
return path.includes('/template/') && !path.includes('/build/'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't find templates/
folder, we can throw an error saying that you need a specific folder structure or sth like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Let's do that in another PR.
return error(`No \`template\` directory found within ${ repo }!`);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could even detect template/
and if it doesn't exist, assume the template is at the root. I'm fine with either, and a subsequent PR seems fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to force a template structure. When things become too flexible they become less clear and harder to debug.
dev: 'preact watch', | ||
test: 'eslint src && preact test' | ||
start: `if-env NODE_ENV=production && ${cmd} run -s serve || ${cmd} run -s watch`, | ||
watch: 'preact watch' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should probably leave it to dev
, since most users expect that 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lol okay. I thought this would make more sense since the command name is watch
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I waffled on this incessantly when doing the original scripts. FWIW CRA does neither, they actually use npm start
for the dev server (that's why I added the env bit there).
I don't have a really compelling reason to go one way or the other here. It might be annoying for people to upgrade and find the command they know has a new name, but then it's only in the templated projects - anything created with 1.x will work just fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, however, it is a major release, so this would be the time to change it, if any.
tests/build.test.js
Outdated
|
||
// TODO | ||
// const ours = ['empty', 'full', 'simple', 'root']; | ||
const ours = ['default', 'full']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be default
& simple
here too! (coz we can run tests on those templates)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above ^^
exports.default = [ | ||
'.gitignore', | ||
'package.json', | ||
'README.md', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and it always fails in my machine 😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 LGTM!
ping @developit for further review on this 😄
src/commands/create.js
Outdated
root: 'examples/root', | ||
simple: 'examples/simple' | ||
full: 'preactjs-templates/default', | ||
default: 'preactjs-templates/default', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was just thinking "principle of least surprise" here, this makes it work quite similarly to how it does in 1.0.
src/commands/create.js
Outdated
process.exit(1); | ||
} | ||
let repo = TEMPLATES[argv.template] || argv.template; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be reasonable here to do something like: "if repo
has no /
, assume preactjs-templates/${repo}
"? That way any template we add to the preactjs-templates
org becomes a default option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Or just include new official templates (should not be often!) as patch releases.
filter(path) { | ||
// TODO: remove `/build/` ?? | ||
// TODO: read & respond to meta/hooks | ||
return path.includes('/template/') && !path.includes('/build/'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could even detect template/
and if it doesn't exist, assume the template is at the root. I'm fine with either, and a subsequent PR seems fine.
if (pkgFile) { | ||
pkgData = JSON.parse(await fs.readFile(pkgFile)); | ||
// Write default "scripts" if none found | ||
pkgData.scripts = pkgData.scripts || (await addScripts(pkgData, target, isYarn)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe instead of making scripts
a wholesale override, we could merge our scripts into the template's?
pkgData.scripts = {
...(pkgData.scripts || {}),
...(await addScripts(pkgData, target, isYarn))
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could merge our scripts into the template's?
I don't think there is a necessary for that since templates will have scripts defined in the package.json file (includes our scripts too)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just sucks if the cli wants to change script down the line 😋
dev: 'preact watch', | ||
test: 'eslint src && preact test' | ||
start: `if-env NODE_ENV=production && ${cmd} run -s serve || ${cmd} run -s watch`, | ||
watch: 'preact watch' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I waffled on this incessantly when doing the original scripts. FWIW CRA does neither, they actually use npm start
for the dev server (that's why I added the env bit there).
I don't have a really compelling reason to go one way or the other here. It might be annoying for people to upgrade and find the command they know has a new name, but then it's only in the templated projects - anything created with 1.x will work just fine.
@@ -141,13 +134,6 @@ export default (env) => { | |||
loader: 'sass-loader', | |||
options: { sourceMap: true } | |||
} | |||
}, | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What the best way for templates to add these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preact.config.js
is the only way the user can tweak the webpack config in CLI as of now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Template authors have to define their own dependencies, as a rule. As of now, the template can also include a preact.config.js, but in the near future, I'll add a meta.js
file (from root) that will have postinstall hooks and behaviors. Hat tip to Vue for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect
- print `info` message about the assumption
What
This adds a separation-of-concerns layer, relinquishing all of the what (aka, the contents) to third parties. In effect, this allows the community to share & reuse templates or recipes that the Preact CLI team is not experienced with and/or not willing to officially support.
Our community is very bright & inventive, so allowing them to create solutions to their own needs is a win for everybody! 🎉
As a result, Preact CLI will focus on two items:
Scaffolding the initial project files
Enhancing its commands for:
a) optimal PWA-centric builds
b) user-friendly development process
Why
How
Use an official template:
Use a user template (tagged version!):
TODOs
Prompt the user when insufficient data is passed to
preact create
Alias
preact init
topreact create
Read & Respond to "extraction hooks"
Injecting values based on custom prompts
Allow optional, custom prompts on a per-template basis
Template authors may require specific values or have a choice list for certain items
Still a WIP. I'd like to continue only once all
TODO
items are complete.Closes #99, #326.