Skip to content

Commit

Permalink
feat: many new features
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobrosenberg committed Jul 30, 2023
1 parent 2d042b9 commit c6ea25c
Show file tree
Hide file tree
Showing 19 changed files with 4,361 additions and 202 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules
dev
.history
.history
.templates
.repos
test/basic
66 changes: 66 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Contributors

## Adding your own template repo
To contribute new templates to the project, you need to create a configuration for it that matches our TemplateRepoConfig type. The configuration is added to `config.js`.

You can contribute two types of template repositories: `single` and `directory`. `single` contains one main template. `directory`, on the other hand, houses multiple templates, each in its own subdirectory.

Here are examples of TemplateRepoConfig objects for each type:

### Single template repo
```javascript
{
"url": "github:user/repo",
"path": "optional/path/inside/repo",
"name": "My Custom Template",
"description": "This is a custom template contributed to the project.",
"templateType": "single",
"author": "Your Name",
}
```

### Directory templates repo
```javascript
{
"url": "github:user/repo",
"path": "optional/path/inside/repo",
"templateType": "directory",
"author": "Your Name",
"requireManifest": false // folders without a manifest will be skipped
}
```

## Template Manifest
Manifests are optional and located at `<template>/manifest.js`. They enhance the template with extra information and features.

Here's a Template manifest example
```javascript
{
name: 'my starter template',
description: 'description of my template',
test: {
// adding tests will enable the `test` feature option
// if users enable tests, this will automatically install vitest to the project
tests: [{ page: '/', contains: 'Welcome to my starter template' }],
},
// features are selectable by the user after selecting the template
features: [
{
label: 'My Super Feature',
value: 'my-super-feature',
hint: 'This adds a super feature to the projet',
initial: true, // should the user opt in or opt out
},
],
// runs after `npm install`, whether install is skipped or not
// options contains the options selected by the user
postInstall: async (options)=>{
// it's often easier to remove a feature than add a feature
if (!options.features.includes('my-super-feature')) {
const { rm } = await import('fs/promises');
await rm(`${options.projectDir}/src/components/superFeature.js`);
}
}
// same as postInstall, but runs before `npm install`
// preInstall: (options)=>{}
}
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@ We have designed the cli to be able to be run in headless mode, as such the foll
```
npm init routify [directory-name]
-h, --help get the help menu
-v, --version use this to set the version of routify, e.g. 3
-f, --force this option bypasses directory checks, be careful as might overwrite files!
-v, --version <version> use this to set the version of routify, e.g. 3
-t, --starter-template <starterTemplate> use this to set the starter template, e.g. starter-basic
-f, --force this option bypasses directory checks, be careful as might overwrite files!
-r, --force-refresh this option forces a refresh of the repos
-f, --features <features> optionally add features to your project, eg. "test", "prettier"
-s, --skip this option skips all prompts
-p, --package-manager <package-manager> this option sets the package manager to use, e.g. "npm", "pnpm" or "yarn"
-i, --install install dependencies after creating project
-d, --debug run in debug mode
-h, --help display help for command
```

### Contributors
See [CONTRIBUTORS.md](CONTRIBUTORS.md)
43 changes: 43 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const features = {
prettier: {
label: 'prettier',
value: 'prettier',
hint: 'Add prettier config',
initial: true,
},
};

/** @type {TemplateConfig} */
export default {
versions: {
2: {
defaultTemplate: 'v2 starter template',
templatesRepos: [
{
url: 'roxiness/routify-starter',
name: 'v2 starter template',
description: 'Routify v2 starter template',
templateType: 'single',
author: 'Roxi (official)',
includeByDefault: true,
},
],
features: [features.prettier],
},
3: {
defaultTemplate: 'basic-starter',
templatesRepos: [
{
url: 'roxiness/routify#next',
// url: 'local:../routify',
path: 'examples',
templateType: 'directory',
author: 'Roxi (official)',
includeByDefault: true,
requireManifest: true,
},
],
features: [features.prettier],
},
},
};
Loading

0 comments on commit c6ea25c

Please sign in to comment.