Skip to content

Commit

Permalink
fix: make installNpmPackage work without package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
uetchy committed Jun 29, 2022
1 parent f45d98c commit 69a87e3
Show file tree
Hide file tree
Showing 9 changed files with 296 additions and 219 deletions.
90 changes: 49 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,51 @@

<!-- START mdmod {use: 'toc'} -->

- [Quick Start](#quick-start)
- [1. Bootstrap your project](#1-bootstrap-your-project)
- [2. Add and edit template files](#2-add-and-edit-template-files)
- [3. Build the app (TypeScript only)](#3-build-the-app-typescript-only)
- [4. Publish package to npm](#4-publish-package-to-npm)
- [5. PROFIT](#5-profit)
- [Template](#template)
- [Advanced: Multiple templates](#advanced-multiple-templates)
- [Helper functions](#helper-functions)
- [`upper`](#upper)
- [`lower`](#lower)
- [`capital`](#capital)
- [`camel`](#camel)
- [`snake`](#snake)
- [`kebab`](#kebab)
- [`space`](#space)
- [`uuid`](#uuid)
- [Config](#config)
- [templateRoot (required)](#templateroot-required)
- [modifyName (default: `undefined`)](#modifyname-default-undefined)
- [extra (default: `undefined`)](#extra-default-undefined)
- [defaultDescription (default: `description`)](#defaultdescription-default-description)
- [defaultAuthor (default: `user.name` in `~/.gitconfig` otherwise `Your name`)](#defaultauthor-default-username-in-gitconfig-otherwise-your-name)
- [defaultEmail (default: `user.email` in `~/.gitconfig` otherwise `Your email`)](#defaultemail-default-useremail-in-gitconfig-otherwise-your-email)
- [defaultTemplate (default: `default`)](#defaulttemplate-default-default)
- [defaultLicense (default: `MIT`)](#defaultlicense-default-mit)
- [defaultPackageManager (default: `undefined`)](#defaultpackagemanager-default-undefined)
- [promptForDescription (default: `true`)](#promptfordescription-default-true)
- [promptForAuthor (default: `true`)](#promptforauthor-default-true)
- [promptForEmail (default: `true`)](#promptforemail-default-true)
- [promptForTemplate (default: `false`)](#promptfortemplate-default-false)
- [promptForLicense (default: `true`)](#promptforlicense-default-true)
- [promptForPackageManager (default: `false`)](#promptforpackagemanager-default-false)
- [skipGitInit (default: `false`)](#skipgitinit-default-false)
- [skipNpmInstall (default: `false`)](#skipnpminstall-default-false)
- [after (default: `undefined`)](#after-default-undefined)
- [caveat (default: `undefined`)](#caveat-default-undefined)
- [`AfterHookOptions`](#afterhookoptions)
- [Showcase](#showcase)
- [Contribution](#contribution)
- [Contributors ✨](#contributors-)

- [✨ Create Create App](#-create-create-app)
- [Why?](#why)
- [Table of contents](#table-of-contents)
- [Quick Start](#quick-start)
- [1. Bootstrap your project](#1-bootstrap-your-project)
- [2. Add and edit template files](#2-add-and-edit-template-files)
- [3. Build the app (TypeScript only)](#3-build-the-app-typescript-only)
- [4. Publish package to npm](#4-publish-package-to-npm)
- [5. PROFIT](#5-profit)
- [Template](#template)
- [Advanced: Multiple templates](#advanced-multiple-templates)
- [Helper functions](#helper-functions)
- [`upper`](#upper)
- [`lower`](#lower)
- [`capital`](#capital)
- [`camel`](#camel)
- [`snake`](#snake)
- [`kebab`](#kebab)
- [`space`](#space)
- [`uuid`](#uuid)
- [Config](#config)
- [templateRoot (required)](#templateroot-required)
- [modifyName (default: `undefined`)](#modifyname-default-undefined)
- [extra (default: `undefined`)](#extra-default-undefined)
- [defaultDescription (default: `description`)](#defaultdescription-default-description)
- [defaultAuthor (default: `user.name` in `~/.gitconfig` otherwise `Your name`)](#defaultauthor-default-username-in-gitconfig-otherwise-your-name)
- [defaultEmail (default: `user.email` in `~/.gitconfig` otherwise `Your email`)](#defaultemail-default-useremail-in-gitconfig-otherwise-your-email)
- [defaultTemplate (default: `default`)](#defaulttemplate-default-default)
- [defaultLicense (default: `MIT`)](#defaultlicense-default-mit)
- [defaultPackageManager (default: `undefined`)](#defaultpackagemanager-default-undefined)
- [promptForDescription (default: `true`)](#promptfordescription-default-true)
- [promptForAuthor (default: `true`)](#promptforauthor-default-true)
- [promptForEmail (default: `true`)](#promptforemail-default-true)
- [promptForTemplate (default: `false`)](#promptfortemplate-default-false)
- [promptForLicense (default: `true`)](#promptforlicense-default-true)
- [promptForPackageManager (default: `false`)](#promptforpackagemanager-default-false)
- [skipGitInit (default: `false`)](#skipgitinit-default-false)
- [skipNpmInstall (default: `false`)](#skipnpminstall-default-false)
- [after (default: `undefined`)](#after-default-undefined)
- [caveat (default: `undefined`)](#caveat-default-undefined)
- [`AfterHookOptions`](#afterhookoptions)
- [Showcase](#showcase)
- [Contribution](#contribution)
- [Contributors ✨](#contributors-)

<!-- END mdmod -->

Expand Down Expand Up @@ -120,6 +124,8 @@ Built-in variables are:
- `{{contact}}` author name formatted with `{{name}} <{{email}}>`. If email is missing, simply `{{name}}`
- `{{license}}` package license (e.g. `MIT`)
- `{{year}}` current year (e.g. `2021`)
- `{{template}} selected template name (e.g. `typescript`)
- `{{packageManager}} package manager (e.g. `yarn`)

### Advanced: Multiple templates

Expand Down Expand Up @@ -346,6 +352,8 @@ create('create-greet', {
```typescript
{
// variables
name: string; // e.g. "create-greet"
template: string; // e.g. "default"
packageDir: string; // e.g. "/path/to/ohayo"
templateDir: string; // e.g. "/path/to/create-greet/templates/default"
year: number; // e.g. 2020
Expand Down
9 changes: 5 additions & 4 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { AfterHookOptions, create } from '.';

const templateRoot = resolve(__dirname, '..', 'templates');

const caveat = ({ name, template }: AfterHookOptions) => {
const caveat = ({ answers: { name, template } }: AfterHookOptions) => {
let text = `
cd ${chalk.bold.green(name)}
`;
Expand Down Expand Up @@ -40,14 +40,15 @@ ${chalk.yellow(

create('create-create-app', {
templateRoot,
modifyName: (name) => (name.startsWith('create-') ? name : `create-${name}`),

promptForTemplate: true,
skipNpmInstall: true,

modifyName: (name) => (name.startsWith('create-') ? name : `create-${name}`),

after: async ({ installNpmPackage }: AfterHookOptions) => {
console.log('Installing the latest version of create-create-app');
console.log('\nInstalling the latest version of create-create-app');
await installNpmPackage('create-create-app');
},

caveat,
});
Loading

0 comments on commit 69a87e3

Please sign in to comment.