{"id":17446031,"url":"https://github.com/jamen/create","last_synced_at":"2025-07-06T14:37:06.796Z","repository":{"id":96784204,"uuid":"183805723","full_name":"jamen/create","owner":"jamen","description":"Functions for creating new projects.","archived":false,"fork":false,"pushed_at":"2019-04-27T18:02:04.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-08T02:24:14.210Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/jamen.png","metadata":{"files":{"readme":"readme.md","changelog":null,"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":"2019-04-27T18:01:55.000Z","updated_at":"2021-12-19T15:27:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"06190138-fc7d-4077-802d-a0e1aca259a5","html_url":"https://github.com/jamen/create","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamen%2Fcreate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamen%2Fcreate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamen%2Fcreate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamen%2Fcreate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamen","download_url":"https://codeload.github.com/jamen/create/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246803134,"owners_count":20836500,"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":[],"created_at":"2024-10-17T18:21:03.606Z","updated_at":"2025-04-02T11:22:40.065Z","avatar_url":"https://github.com/jamen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @jamen/create\n\nFunctions for scaffolding projects.\n\nThe goal is to replace tools like [Yeoman](https://github.com/yeoman/yo) and [Generate](https://github.com/generate/generate) with npm's `npm init \u003cgenerator\u003e` scripts:\n\n```\nnpm init @jamen/js\n# Or\nnpx @jamen/create-js\n```\n\nBecause these are just CLI scripts, this package gives functions for prompting, writing files, and installing dependencies.\n\n## Install\n\n```\nnpm i @jamen/create\n```\n\n## Usage\n\nThis package has many functions, but not a function that puts them all together. Instead, you create your own \"template function\" that follows this pattern:\n\n```js\nasync function create () {\n    // Get CLI options\n    const options = await cli({\n        flags: {\n            alias: { n: 'name' }\n        },\n        questions: flags =\u003e [\n            {\n                message: 'This is an example',\n                name: 'example',\n                type: 'text'\n            }\n        ]\n    })\n\n    // Write files\n    await write({\n        input: resolve(__dirname, 'files'),\n        output: options.output,\n        files: [\n            {\n                input: 'package.json',\n                output: 'package.json',\n                write: writeJson\n            }\n        ]\n    })\n\n    // Install dependencies\n    await npmInstall({\n        output: options.output,\n        dependencies: [ 'foobar' ],\n        devDependencies: [ 'bazqux' ]\n    })\n}\n```\n\n### `cli(options)`\n\nThis function collects all the options your template needs from the command-line.\n\nThe options are `{ flags, questions }`. The `flags` are options given to [`mri`](https://www.npmjs.com/package/mri) for parsing the arguments, and questions is a list given to [`prompts`](https://www.npmjs.com/package/prompts)\n\nSometimes questions will depend on flags, so the `questions` can be a function that accepts the flags and returns a list, instead of just a list. `[ ... ]` versus `flags =\u003e [ ... ]`.\n\nIt returns a Promise of an object with all options your template will use.\n\n```js\nconst options = await cli({\n    flags: {\n        alias: { n: 'name' }\n    },\n    questions: flags =\u003e [\n        {\n            message: 'This is an example',\n            name: 'example',\n            type: 'text'\n        }\n    ]\n})\n```\n\n### `write(options)`\n\nThis function writes a list of files, given an input and output directory, and different functions used to write the files in special ways.\n\nThe options are `{ input, output, files }`. The `input` is where the source files are coming from, and the `output` are where the files are going to. `files` contains all the relative paths to and from each, along with an optional special write function (e.g. `writeTemplate` or `writeJson`).\n\nIt returns a Promise that resolves once all the file operations have finished.\n\n```js\nawait write({\n    input: resolve(__dirname, 'files'),\n    output: options.output,\n    files: [\n        {\n            input: 'readme.md',\n            output: 'readme.md'\n        }\n        {\n            input: 'package.json',\n            output: 'package.json',\n            write: writeJson\n        }\n    ]\n})\n```\n\n### `writeNormal(input, output)\n\nA simple write function, copying `input` to `output`. Its used by default in `write`.\n\nIf the file being written already exists, the function becomes `writeConfirm` instead, prompting if it should be overwritten first. This also applies to the other specialized `write` functions, so it wont be mentioned further.\n\n```js\n{\n    input: 'readme.md',\n    output: 'readme.md',\n    write: writeNormal\n}\n```\n\n### `writeTemplate(options)(input, output)`\n\nWrites a template from the input to the output, rendering it along the way.\n\nThe template has access to all the `options` you give it.\n\n```js\n{\n    input: 'readme.md',\n    output: 'readme.md'.\n    write: writeTemplate(options)\n}\n```\n\n### `writeUniqueLines(input, output)`\n\nWrite unique lines from input to output. This preserves the output file. Useful with a `.gitignore` for example.\n\n```js\n{\n    input: '.gitignore',\n    output: '.gitignore',\n    write: writeUniqueLines\n}\n```\n\n### `writeJson()`\n\nWrites a JSON input into the JSON output, merging them together. This preserves the output file. Useful with a `package.json` for example.\n\n```js\n{\n    input: 'package.json',\n    output: 'package.json',\n    write: writeJson\n}\n```\n\n### `writeJsonTemplate(options)(input, output)`\n\nBasically `writeTemplate` + `writeJson`.\n\n```js\n{\n    input: 'package.json',\n    output: 'package.json',\n    write: writeJsonTemplate(options)\n}\n```\n\n### `writeConfirm(input, output)`\n\nConfirms if the file should be written. This is used throughout some other write functions, so if the file already exists, it can gracefull overwrite or skip the operation.\n\n```js\n{\n    input: 'readme.md',\n    output: 'readme.md',\n    write: writeConfirm\n}\n```\n\n### `npmInstall(options)`\n\nInstall dependencies with npm.\n\nThe options are `{ output, dependencies, devDependencies }`. The dependencies are installed into the `output` directory.\n\nIt returns a promise that is resolved once install is finished.\n\n```js\nawait npmInstall({\n    output: options.output,\n    dependencies: [ 'foobar' ],\n    devDependencies: [ 'bazqux' ]\n})\n```\n\n### `npmName(name)`\n\nTurn strings into npm package names. For example, prompt input or file paths.\n\n```js\nnpmName('Foo Bar') === 'foo-bar'\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamen%2Fcreate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamen%2Fcreate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamen%2Fcreate/lists"}