-
-
Notifications
You must be signed in to change notification settings - Fork 753
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add a Pinion generator to initialise a new package
- Loading branch information
Showing
14 changed files
with
395 additions
and
88 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { Callable, PinionContext } from '@feathershq/pinion' | ||
import { generator, install, prompt, runGenerators, toFile } from '@feathershq/pinion' | ||
|
||
export interface ModuleContext extends PinionContext { | ||
name: string | ||
uppername: string | ||
description: string | ||
moduleName: string | ||
packagePath: Callable<string, ModuleContext> | ||
} | ||
|
||
export const generate = (context: ModuleContext) => | ||
generator(context) | ||
.then( | ||
prompt<ModuleContext>([ | ||
{ | ||
type: 'input', | ||
name: 'name', | ||
message: 'What is the name of the module?' | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'description', | ||
message: 'Write a short description' | ||
} | ||
]) | ||
) | ||
.then((ctx) => { | ||
return { | ||
...ctx, | ||
moduleName: `@feathersjs/${ctx.name}`, | ||
uppername: ctx.name.charAt(0).toUpperCase() + ctx.name.slice(1), | ||
packagePath: toFile('packages', ctx.name) | ||
} | ||
}) | ||
.then(runGenerators(__dirname, 'package')) | ||
.then( | ||
install<ModuleContext>( | ||
['@types/node', 'shx', 'ts-node', 'typescript', 'mocha'], | ||
true, | ||
(context) => `npm --workspace packages/${context.name}` | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { generator, renderTemplate, toFile } from '@feathershq/pinion' | ||
import { ModuleContext } from '../package' | ||
|
||
interface Context extends ModuleContext {} | ||
|
||
const template = ({ name }: Context) => ` | ||
export function ${name}() { | ||
return 'Hello from ${name}' | ||
} | ||
` | ||
|
||
export const generate = (context: Context) => | ||
generator(context).then(renderTemplate(template, toFile(context.packagePath, 'src', 'index.ts'))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { generator, renderTemplate, toFile } from '@feathershq/pinion' | ||
import { ModuleContext } from '../package' | ||
|
||
interface Context extends ModuleContext {} | ||
|
||
export const generate = (context: Context) => | ||
generator(context).then( | ||
renderTemplate( | ||
`The MIT License (MIT) | ||
Copyright (c) ${new Date().getFullYear()} Feathers Contributors | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
`, | ||
toFile<Context>(context.packagePath, 'LICENSE') | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { generator, toFile, writeJSON } from '@feathershq/pinion' | ||
import { ModuleContext } from '../package' | ||
|
||
interface Context extends ModuleContext {} | ||
|
||
export const generate = (context: Context) => | ||
generator(context).then( | ||
writeJSON<Context>( | ||
({ moduleName, description, name }) => ({ | ||
name: moduleName, | ||
description, | ||
version: '0.0.0', | ||
homepage: 'https://feathersjs.com', | ||
keywords: ['feathers'], | ||
license: 'MIT', | ||
repository: { | ||
type: 'git', | ||
url: 'git://github.com/feathersjs/feathers.git', | ||
directory: `packages/${name}` | ||
}, | ||
author: { | ||
name: 'Feathers contributor', | ||
email: '[email protected]', | ||
url: 'https://feathersjs.com' | ||
}, | ||
contributors: [], | ||
bugs: { | ||
url: 'https://github.com/feathersjs/feathers/issues' | ||
}, | ||
engines: { | ||
node: '>= 20' | ||
}, | ||
files: ['CHANGELOG.md', 'LICENSE', 'README.md', 'src/**', 'lib/**', 'esm/**'], | ||
// module: './esm/index.js', | ||
main: './lib/index.js', | ||
types: './src/index.ts', | ||
exports: { | ||
'.': { | ||
// import: './esm/index.js', | ||
require: './lib/index.js', | ||
types: './src/index.ts' | ||
} | ||
}, | ||
scripts: { | ||
prepublish: 'npm run compile', | ||
pack: 'npm pack --pack-destination ../generators/test/build', | ||
compile: 'shx rm -rf lib/ && tsc && npm run pack', | ||
test: 'mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts' | ||
}, | ||
publishConfig: { | ||
access: 'public' | ||
}, | ||
dependencies: {}, | ||
devDependencies: {} | ||
}), | ||
toFile('packages', context.name, 'package.json') | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { generator, renderTemplate, toFile } from '@feathershq/pinion' | ||
import { ModuleContext } from '../package' | ||
|
||
const template = ({ description, moduleName }: ModuleContext) => `# ${moduleName} | ||
[![CI](https://github.com/feathersjs/feathers/workflows/CI/badge.svg)](https://github.com/feathersjs/feathers/actions?query=workflow%3ACI) | ||
[![Download Status](https://img.shields.io/npm/dm/${moduleName}.svg?style=flat-square)](https://www.npmjs.com/package/${moduleName}) | ||
[![Discord](https://badgen.net/badge/icon/discord?icon=discord&label)](https://discord.gg/qa8kez8QBx) | ||
> ${description} | ||
## Installation | ||
\`\`\` | ||
npm install ${moduleName} --save | ||
\`\`\` | ||
## Documentation | ||
Refer to the [Feathers API documentation](https://feathersjs.com/api) for more details. | ||
## License | ||
Copyright (c) ${new Date().getFullYear()} [Feathers contributors](https://github.com/feathersjs/feathers/graphs/contributors) | ||
Licensed under the [MIT license](LICENSE). | ||
` | ||
|
||
export const generate = (context: ModuleContext) => | ||
generator(context).then(renderTemplate(template, toFile(context.packagePath, 'README.md'))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { generator, renderTemplate, toFile } from '@feathershq/pinion' | ||
import { ModuleContext } from '../package' | ||
|
||
interface Context extends ModuleContext {} | ||
|
||
const template = ({ moduleName, name }: Context) => /** ts */ `import { strict as assert } from 'assert' | ||
import { ${name} } from '../src/index' | ||
describe('${moduleName}', () => { | ||
it('initializes', () => { | ||
assert.equal(${name}(), 'Hello from ${name}') | ||
}) | ||
}) | ||
` | ||
|
||
export const generate = (context: Context) => | ||
generator(context).then( | ||
renderTemplate(template, toFile<Context>(context.packagePath, 'test', 'index.test.ts')) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { generator, toFile, writeJSON } from '@feathershq/pinion' | ||
import { ModuleContext } from '../package' | ||
|
||
export const generate = (context: ModuleContext) => | ||
generator(context).then( | ||
writeJSON( | ||
{ | ||
extends: '../../tsconfig', | ||
include: ['src/**/*.ts'], | ||
compilerOptions: { | ||
outDir: 'lib' | ||
} | ||
}, | ||
toFile(context.packagePath, 'tsconfig.json') | ||
) | ||
) |
Oops, something went wrong.