Skip to content

Commit

Permalink
fix(generators): Move generators and CLI to featherscloud/pinion (#3386)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Jan 22, 2024
1 parent 59fb40b commit eb87c99
Show file tree
Hide file tree
Showing 58 changed files with 9,226 additions and 11,013 deletions.
4 changes: 2 additions & 2 deletions generators/package.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Callable, PinionContext } from '@feathershq/pinion'
import { generator, install, prompt, runGenerators, toFile } from '@feathershq/pinion'
import type { Callable, PinionContext } from '@featherscloud/pinion'
import { generator, install, prompt, runGenerators, toFile } from '@featherscloud/pinion'

export interface ModuleContext extends PinionContext {
name: string
Expand Down
2 changes: 1 addition & 1 deletion generators/package/index.tpl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { generator, renderTemplate, toFile } from '@feathershq/pinion'
import { generator, renderTemplate, toFile } from '@featherscloud/pinion'
import { ModuleContext } from '../package'

interface Context extends ModuleContext {}
Expand Down
2 changes: 1 addition & 1 deletion generators/package/license.tpl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { generator, renderTemplate, toFile } from '@feathershq/pinion'
import { generator, renderTemplate, toFile } from '@featherscloud/pinion'
import { ModuleContext } from '../package'

interface Context extends ModuleContext {}
Expand Down
2 changes: 1 addition & 1 deletion generators/package/package.json.tpl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { generator, toFile, writeJSON } from '@feathershq/pinion'
import { generator, toFile, writeJSON } from '@featherscloud/pinion'
import { ModuleContext } from '../package'

interface Context extends ModuleContext {}
Expand Down
2 changes: 1 addition & 1 deletion generators/package/readme.md.tpl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { generator, renderTemplate, toFile } from '@feathershq/pinion'
import { generator, renderTemplate, toFile } from '@featherscloud/pinion'
import { ModuleContext } from '../package'

const template = ({ description, moduleName }: ModuleContext) => `# ${moduleName}
Expand Down
2 changes: 1 addition & 1 deletion generators/package/test.tpl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { generator, renderTemplate, toFile } from '@feathershq/pinion'
import { generator, renderTemplate, toFile } from '@featherscloud/pinion'
import { ModuleContext } from '../package'

interface Context extends ModuleContext {}
Expand Down
2 changes: 1 addition & 1 deletion generators/package/tsconfig.json.tpl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { generator, toFile, writeJSON } from '@feathershq/pinion'
import { generator, toFile, writeJSON } from '@featherscloud/pinion'
import { ModuleContext } from '../package'

export const generate = (context: ModuleContext) =>
Expand Down
19,531 changes: 8,843 additions & 10,688 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
"lint": "npm run prettier && npm run eslint",
"compile": "lerna run compile",
"build:docs": "npm run build --workspace docs",
"update-dependencies": "ncu -u && npm exec --workspaces -- ncu -u --dep prod,dev,optional,peer -x node-fetch,chalk,\"@sinclair/typebox\"",
"update-dependencies": "ncu -u && npm exec --workspaces -- ncu -u --dep prod,dev,optional,peer -x node-fetch,\"@sinclair/typebox\"",
"clean": "find . -name node_modules -exec rm -rf '{}' + && find . -name package-lock.json -exec rm -rf '{}' +",
"test:deno": "deno test --config deno/tsconfig.json deno/test.ts",
"test": "npm run lint && npm run compile && c8 lerna run test --ignore @feathersjs/tests",
"generate:package": "pinion run generators/package.ts"
},
"devDependencies": {
"@feathershq/pinion": "^0.4.0-pre.3",
"@featherscloud/pinion": "^0.5.0",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"c8": "^9.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/bin/feathers
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
'use strict'

const { program } = require('../lib')
import { program } from '../lib/index.js'

program.parse()
7 changes: 4 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"description": "The command line interface for creating Feathers applications",
"version": "5.0.14",
"homepage": "https://feathersjs.com",
"main": "lib/",
"main": "lib/index.js",
"type": "module",
"bin": {
"feathers": "./bin/feathers"
},
Expand Down Expand Up @@ -45,15 +46,15 @@
"scripts": {
"prepublish": "npm run compile",
"compile": "shx rm -rf lib/ && tsc",
"mocha": "mocha --timeout 60000 --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts",
"mocha": "mocha --timeout 60000 --config ../../.mocharc.json --require tsx --recursive test/**.test.ts test/**/*.test.ts",
"test": "npm run compile && npm run mocha"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@feathersjs/generators": "^5.0.14",
"chalk": "^4.0.1",
"chalk": "^5.3.0",
"commander": "^11.1.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import chalk from 'chalk'
import { Command } from 'commander'
import { dirname } from 'path'
import { generator, runGenerator, getContext, FeathersBaseContext, version } from '@feathersjs/generators'
import { runGenerator, getContext, FeathersBaseContext, version } from '@feathersjs/generators'

export * from 'commander'
export { chalk }
Expand All @@ -12,7 +12,7 @@ export const commandRunner = (name: string) => async (options: any) => {
...options
})

await generator(ctx)
await Promise.resolve(ctx)
.then(runGenerator(folder, name, 'index'))
.catch((error) => {
const { logger } = ctx.pinion
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
],
"compilerOptions": {
"outDir": "lib",
"resolveJsonModule": true
"module": "ESNext",
"moduleResolution": "Node"
}
}
11 changes: 6 additions & 5 deletions packages/generators/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
"engines": {
"node": ">= 16"
},
"main": "lib/",
"main": "lib/index.js",
"types": "lib/",
"type": "module",
"files": [
"CHANGELOG.md",
"LICENSE",
Expand All @@ -43,7 +44,7 @@
"scripts": {
"prepublish": "npm run compile",
"compile": "shx rm -rf lib/ && tsc && shx cp -r src/. lib/",
"test": "npm run compile && mocha --config ../../.mocharc.json --recursive test/**.test.ts test/**/*.test.ts"
"test": "npm run compile && mocha --config ../../.mocharc.json --require tsx --recursive test/**.test.ts test/**/*.test.ts"
},
"directories": {
"lib": "lib"
Expand All @@ -52,8 +53,8 @@
"access": "public"
},
"dependencies": {
"@feathershq/pinion": "^0.3.5",
"chalk": "^4.0.1",
"@featherscloud/pinion": "^0.5.0",
"chalk": "^5.3.0",
"lodash": "^4.17.21",
"prettier": "^3.2.4",
"typescript": "^5.3.3"
Expand Down Expand Up @@ -88,7 +89,7 @@
"pg": "^8.11.3",
"shx": "^0.3.4",
"sqlite3": "^5.1.7",
"ts-node": "^10.9.2",
"tsx": "^4.7.0",
"type-fest": "^4.9.0",
"typescript": "^5.3.3"
},
Expand Down
25 changes: 17 additions & 8 deletions packages/generators/src/app/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { sep } from 'path'
import { sep, dirname } from 'path'
import chalk from 'chalk'
import { generator, prompt, runGenerators, fromFile, install, copyFiles, toFile } from '@feathershq/pinion'
import { FeathersBaseContext, FeathersAppInfo, initializeBaseContext, addVersions } from '../commons'
import { generate as connectionGenerator, prompts as connectionPrompts } from '../connection'
import { prompt, runGenerators, fromFile, copyFiles, toFile } from '@featherscloud/pinion'
import {
FeathersBaseContext,
FeathersAppInfo,
initializeBaseContext,
addVersions,
install
} from '../commons.js'
import { generate as connectionGenerator, prompts as connectionPrompts } from '../connection/index.js'

// Set __dirname in es module
const __dirname = dirname(new URL(import.meta.url).pathname)

export interface AppGeneratorData extends FeathersAppInfo {
/**
Expand Down Expand Up @@ -36,15 +45,15 @@ export type AppGeneratorContext = FeathersBaseContext &
export type AppGeneratorArguments = FeathersBaseContext & Partial<AppGeneratorData>

export const generate = (ctx: AppGeneratorArguments) =>
generator(ctx)
Promise.resolve(ctx)
.then(initializeBaseContext())
.then((ctx) => ({
...ctx,
dependencies: [],
devDependencies: []
}))
.then(
prompt<AppGeneratorArguments, AppGeneratorContext>((ctx) => [
prompt((ctx) => [
{
name: 'language',
type: 'list',
Expand Down Expand Up @@ -142,7 +151,7 @@ export const generate = (ctx: AppGeneratorArguments) =>
}
})
.then(
install<AppGeneratorContext>(
install(
({ transports, framework, dependencyVersions, dependencies, schema }) => {
const hasSocketio = transports.includes('websockets')

Expand Down Expand Up @@ -181,7 +190,7 @@ export const generate = (ctx: AppGeneratorArguments) =>
)
)
.then(
install<AppGeneratorContext>(
install(
({ language, devDependencies, dependencyVersions }) => {
devDependencies.push(
'nodemon',
Expand Down
8 changes: 4 additions & 4 deletions packages/generators/src/app/templates/app.test.tpl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { generator, toFile } from '@feathershq/pinion'
import { renderSource } from '../../commons'
import { AppGeneratorContext } from '../index'
import { toFile } from '@featherscloud/pinion'
import { renderSource } from '../../commons.js'
import { AppGeneratorContext } from '../index.js'

const template = ({
lib
Expand Down Expand Up @@ -47,4 +47,4 @@ describe('Feathers application tests', () => {
`

export const generate = (ctx: AppGeneratorContext) =>
generator(ctx).then(renderSource(template, toFile('test', 'app.test')))
Promise.resolve(ctx).then(renderSource(template, toFile('test', 'app.test')))
8 changes: 4 additions & 4 deletions packages/generators/src/app/templates/app.tpl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { generator, toFile } from '@feathershq/pinion'
import { renderSource } from '../../commons'
import { AppGeneratorContext } from '../index'
import { toFile } from '@featherscloud/pinion'
import { renderSource } from '../../commons.js'
import { AppGeneratorContext } from '../index.js'

const tsKoaApp = ({
transports,
Expand Down Expand Up @@ -133,7 +133,7 @@ const template = (ctx: AppGeneratorContext) =>
ctx.framework === 'express' ? tsExpressApp(ctx) : tsKoaApp(ctx)

export const generate = (ctx: AppGeneratorContext) =>
generator(ctx).then(
Promise.resolve(ctx).then(
renderSource(
template,
toFile<AppGeneratorContext>(({ lib }) => lib, 'app')
Expand Down
8 changes: 4 additions & 4 deletions packages/generators/src/app/templates/channels.tpl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { generator, toFile, when } from '@feathershq/pinion'
import { renderSource } from '../../commons'
import { AppGeneratorContext } from '../index'
import { toFile, when } from '@featherscloud/pinion'
import { renderSource } from '../../commons.js'
import { AppGeneratorContext } from '../index.js'

const template = ({
language
Expand Down Expand Up @@ -43,7 +43,7 @@ export const channels = (app: Application) => {
`

export const generate = (ctx: AppGeneratorContext) =>
generator(ctx).then(
Promise.resolve(ctx).then(
when<AppGeneratorContext>(
({ transports }) => transports.includes('websockets'),
renderSource(
Expand Down
8 changes: 4 additions & 4 deletions packages/generators/src/app/templates/client.test.tpl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { generator, toFile, when } from '@feathershq/pinion'
import { renderSource } from '../../commons'
import { AppGeneratorContext } from '../index'
import { toFile, when } from '@featherscloud/pinion'
import { renderSource } from '../../commons.js'
import { AppGeneratorContext } from '../index.js'

const template = ({ lib }: AppGeneratorContext) => /* ts */ `import assert from 'assert'
import axios from 'axios'
Expand All @@ -23,6 +23,6 @@ describe('client tests', () => {
`

export const generate = (ctx: AppGeneratorContext) =>
generator(ctx).then(
Promise.resolve(ctx).then(
when<AppGeneratorContext>((ctx) => ctx.client, renderSource(template, toFile('test', 'client.test')))
)
8 changes: 4 additions & 4 deletions packages/generators/src/app/templates/client.tpl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { generator, toFile, when } from '@feathershq/pinion'
import { renderSource } from '../../commons'
import { AppGeneratorContext } from '../index'
import { toFile, when } from '@featherscloud/pinion'
import { renderSource } from '../../commons.js'
import { AppGeneratorContext } from '../index.js'

const template = ({
name,
Expand Down Expand Up @@ -42,7 +42,7 @@ export const createClient = <Configuration = any> (
`

export const generate = async (ctx: AppGeneratorContext) =>
generator(ctx).then(
Promise.resolve(ctx).then(
when<AppGeneratorContext>(
(ctx) => ctx.client,
renderSource(
Expand Down
8 changes: 4 additions & 4 deletions packages/generators/src/app/templates/configuration.tpl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { generator, toFile, when, writeJSON } from '@feathershq/pinion'
import { renderSource } from '../../commons'
import { AppGeneratorContext } from '../index'
import { toFile, when, writeJSON } from '@featherscloud/pinion'
import { renderSource } from '../../commons.js'
import { AppGeneratorContext } from '../index.js'

const defaultConfig = ({}: AppGeneratorContext) => ({
host: 'localhost',
Expand Down Expand Up @@ -73,7 +73,7 @@ export const configurationValidator = getValidator(configurationSchema, dataVali
`

export const generate = (ctx: AppGeneratorContext) =>
generator(ctx)
Promise.resolve(ctx)
.then(writeJSON(defaultConfig, toFile('config', 'default.json')))
.then(writeJSON(testConfig, toFile('config', 'test.json')))
.then(writeJSON(customEnvironment, toFile('config', 'custom-environment-variables.json')))
Expand Down
6 changes: 3 additions & 3 deletions packages/generators/src/app/templates/declarations.tpl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { generator, toFile, when, renderTemplate } from '@feathershq/pinion'
import { AppGeneratorContext } from '../index'
import { toFile, when, renderTemplate } from '@featherscloud/pinion'
import { AppGeneratorContext } from '../index.js'

const template = ({
framework,
Expand Down Expand Up @@ -31,7 +31,7 @@ export type HookContext<S = any> = FeathersHookContext<Application, S>
`

export const generate = (ctx: AppGeneratorContext) =>
generator(ctx).then(
Promise.resolve(ctx).then(
when<AppGeneratorContext>(
({ language }) => language === 'ts',
renderTemplate(
Expand Down
6 changes: 3 additions & 3 deletions packages/generators/src/app/templates/index.html.tpl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { generator, renderTemplate, toFile } from '@feathershq/pinion'
import { AppGeneratorContext } from '../index'
import { renderTemplate, toFile } from '@featherscloud/pinion'
import { AppGeneratorContext } from '../index.js'

const template = ({ name, description }: AppGeneratorContext) => /* html */ `<!DOCTYPE html>
<html lang="en">
Expand Down Expand Up @@ -41,4 +41,4 @@ const template = ({ name, description }: AppGeneratorContext) => /* html */ `<!D
`

export const generate = (ctx: AppGeneratorContext) =>
generator(ctx).then(renderTemplate(template, toFile('public', 'index.html')))
Promise.resolve(ctx).then(renderTemplate(template, toFile('public', 'index.html')))
8 changes: 4 additions & 4 deletions packages/generators/src/app/templates/index.tpl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { generator, toFile } from '@feathershq/pinion'
import { renderSource } from '../../commons'
import { AppGeneratorContext } from '../index'
import { toFile } from '@featherscloud/pinion'
import { renderSource } from '../../commons.js'
import { AppGeneratorContext } from '../index.js'

const template = ({}: AppGeneratorContext) => /* ts */ `import { app } from './app'
import { logger } from './logger'
Expand All @@ -18,7 +18,7 @@ app.listen(port).then(() => {
`

export const generate = (ctx: AppGeneratorContext) =>
generator(ctx).then(
Promise.resolve(ctx).then(
renderSource(
template,
toFile<AppGeneratorContext>(({ lib }) => lib, 'index')
Expand Down

0 comments on commit eb87c99

Please sign in to comment.