{"id":19020357,"url":"https://github.com/ambar/gogen","last_synced_at":"2025-04-23T05:58:08.457Z","repository":{"id":33722162,"uuid":"161009603","full_name":"ambar/gogen","owner":"ambar","description":"Use stream API to scaffold projects or files 😉","archived":false,"fork":false,"pushed_at":"2023-03-04T04:12:48.000Z","size":1495,"stargazers_count":7,"open_issues_count":5,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-23T05:58:01.135Z","etag":null,"topics":["generator","gogen","initializer","sao","scaffolding","yeoman"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ambar.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-09T05:59:56.000Z","updated_at":"2022-11-10T08:22:35.000Z","dependencies_parsed_at":"2024-06-20T00:07:00.482Z","dependency_job_id":"0c72bdc6-a666-4b9a-9994-af2c70b8140c","html_url":"https://github.com/ambar/gogen","commit_stats":{"total_commits":104,"total_committers":3,"mean_commits":"34.666666666666664","dds":0.08653846153846156,"last_synced_commit":"f1e26d97f41336f01f6bc5959203911acbbf5635"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ambar%2Fgogen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ambar%2Fgogen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ambar%2Fgogen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ambar%2Fgogen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ambar","download_url":"https://codeload.github.com/ambar/gogen/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250379787,"owners_count":21420841,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["generator","gogen","initializer","sao","scaffolding","yeoman"],"created_at":"2024-11-08T20:16:57.452Z","updated_at":"2025-04-23T05:58:08.439Z","avatar_url":"https://github.com/ambar.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gogen\n\nUse stream API to scaffold projects or files.\n\n[![Coverage Status](https://coveralls.io/repos/github/ambar/gogen/badge.svg?branch=main)](https://coveralls.io/github/ambar/gogen?branch=main)\n[![npm version](https://badgen.net/npm/v/gogen)](https://www.npmjs.com/package/gogen)\n![](https://badgen.net/npm/types/gogen)\n[![install size](https://badgen.net/packagephobia/install/gogen)](https://packagephobia.now.sh/result?p=gogen)\n[![minzipped size](https://badgen.net/bundlephobia/minzip/gogen?scale=1\u0026cache=36000)](https://bundlephobia.com/result?p=gogen)\n\n## Features\n\n- Simple, easy to use\n- Lightweight, single file bundled (\u003c40K gzip size), no need to install globally, just run `npx`\n- Automatically rename `gitignore` to `.gitignore`, due to [npm/issues/1862](https://github.com/npm/npm/issues/1862)\n- Automatically set `name` field in `package.json`\n- Automatically parse command line arguments with [mri](https://www.npmjs.com/package/mri)\n- Add command line prompts with [prompts](https://github.com/terkelg/prompts#-usage)\n- Render `*.t.foo` (or `*.foo.t`) to `*.foo` with lodash template\n- Provide fast, in-memory testing API\n\n## Usage\n\n### Run existing generator\n\nRun from any npm package (registry/GitHub/git/folder...), same as [npm install](https://docs.npmjs.com/cli/install#synopsis) or [yarn add](https://yarnpkg.com/lang/en/docs/cli/add/):\n\n```bash\n# install generator to directory\nnpx gogen \u003cgenerator\u003e \u003cdirectory\u003e\n# eg.\nnpx gogen [\u003c@scope\u003e/]\u003cname\u003e \u003cdirectory\u003e # npm registry\nnpx gogen \u003cuser\u003e/\u003crepo\u003e \u003cdirectory\u003e  # GitHub\nnpx gogen \u003chost\u003e:\u003cname\u003e/\u003crepo\u003e \u003cdirectory\u003e  # git\nnpx gogen \u003cfolder\u003e \u003cdirectory\u003e # folder\n```\n\n### Examples\n\n- Scaffold project\n  - [examples/basic](./examples/basic/.gogenrc.js)\n  - [examples/with-ejs](./examples/with-ejs/.gogenrc.js)\n  - [examples/with-prompts](./examples/with-prompts/.gogenrc.js)\n  - [gogen-pkg](./gogen-pkg/.gogenrc.js)\n- npm initializer or starter kits\n  - [create-gogen](./create-gogen)\n  - [new-mina](https://github.com/ambar/new-mina/blob/main/packages/new-mina/.gogenrc.js) CRA-like initializer in 12 lines.\n\n### Create generator\n\nThe default directory structure, used in [examples](./examples):\n\n```bash\n.\n├── .gogenrc.js # optional, defaults to `lib/.gogenrc.default.js`\n├── package.json\n└── template\n    ├── index.js\n    └── package.json\n```\n\nEdit the `.gogenrc.js` file:\n\n```js\n/**\n * @type {import('gogen').Generator}\n */\nmodule.exports = async ({src, dest, pipeline, install, gitInit}) =\u003e {\n  await pipeline(src('template/**'), dest())\n  await install()\n  await gitInit()\n}\n```\n\nRun the generator:\n\n```bash\nnpx gogen \u003cyour-generator\u003e \u003cyour-project\u003e\n```\n\n### Create npm initializer\n\nAdd a bin file, eg. [examples/create-gogen/cli.js](./examples/create-gogen/cli.js).\n\n```js\nconst {run} = require('gogen')\nrun(\n  [__dirname, ...process.argv.slice(2)],\n  'Usage: npm init gogen \u003cmy-generator\u003e'\n)\n```\n\nRun the initializer:\n\n```bash\nnpm init \u003cyour-initializer\u003e \u003cyour-project\u003e\n# or: yarn create \u003cyour-initializer\u003e \u003cyour-project\u003e\n```\n\n### Configuration file\n\n`.gogenrc.js`:\n\n- `run(api: Object, context: Object) =\u003e void`\n  - `api` core stream and helper APIs\n    - `src(glob: string | string[], options: fg.Options) =\u003e Stream` read files, support [fast-glob](https://github.com/mrmlnc/fast-glob#options-3) options\n    - `dest(path?: string) =\u003e Stream` write files\n    - `pipeline(...streams: Stream[]) =\u003e Promise` pipe a series of streams\n    - `template(data: Object, {ext: RegExp, test: RegExp, render: Function}) =\u003e Stream` render `*.t` or `*.t.foo` files with [lodash template](https://lodash.com/docs/4.17.11#template)\n    - `packages(content: Object | Function) =\u003e Stream` change `package.json`\n    - `modify(match: RegExp | Function, transform: file =\u003e file) =\u003e Stream` change files\n      - `modify.text(match: RegExp | Function, transform: (file, text: string) =\u003e text) =\u003e Stream` change text files\n      - `modify.json(match: RegExp | Function, transform: (file, json: Object) =\u003e json) =\u003e Stream` change json files\n      - `modify.rename(match: RegExp | Function, transform: (file, paths: Object) =\u003e paths) =\u003e Stream` rename files\n    - `install(deps: string[], {dev: boolean, silent: boolean}) =\u003e Promise` install dependencies\n    - `gitInit(message: string) =\u003e Promise` init git repository\n    - `prompts(Array | Object) =\u003e Promise` see [prompts](https://github.com/terkelg/prompts#-usage)\n  - `context` generator context\n    - `path: string` new project's path (it's also a setter)\n    - `name: string` new project's name (it's also a setter)\n    - `argv: Object` command line arguments, parsed by [mri](https://www.npmjs.com/package/mri)\n\n## Testing\n\nUse the `mock` API:\n\n- `mock(generator: string, directory: string, options: Object)`:\n  - `generator` path to generator\n  - `directory` path to output\n  - `options`\n    - `answers: Object` inject prompt values\n\n```js\nconst {mock} = require('gogen')\n\nit('generate correctly', async () =\u003e {\n  const {files, readFile} = await mock('.', 'dist', {\n    answers: {description: 'superb'},\n  })\n  expect(files).toMatchSnapshot()\n  expect(readFile('package.json')).toMatch(/superb/)\n})\n```\n\n## Comparison with alternatives\n\n| Library                                 | Package Phobia                                                                                                 |\n| --------------------------------------- | -------------------------------------------------------------------------------------------------------------- |\n| [gogen](https://github.com/ambar/gogen) | [![install size](https://badgen.net/packagephobia/install/gogen)](https://packagephobia.now.sh/result?p=gogen) |\n| [sao](https://github.com/saojs/sao)     | [![install size](https://badgen.net/packagephobia/install/sao)](https://packagephobia.now.sh/result?p=sao)     |\n| [yeoman](https://github.com/yeoman/yo)  | [![install size](https://badgen.net/packagephobia/install/yo)](https://packagephobia.now.sh/result?p=yo)       |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fambar%2Fgogen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fambar%2Fgogen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fambar%2Fgogen/lists"}