From 9afaf14f10a0009fb79ee47bb2a2a21aff1b2e7c Mon Sep 17 00:00:00 2001 From: fratzinger Date: Sat, 18 Dec 2021 16:55:21 +0100 Subject: [PATCH 1/4] init nextgen --- .../app/base/{index.js => index.ts} | 33 +- .../base/js/{app.test.js.t => app.test.js.ts} | 23 +- .../base/js/{channels.js.t => channels.js.ts} | 35 +- .../{express.app.js.t => express.app.js.ts} | 24 +- .../cli/_templates/app/base/js/index.js.t | 12 - .../cli/_templates/app/base/js/index.js.ts | 24 + .../base/js/{koa.app.js.t => koa.app.js.ts} | 23 +- .../app/base/js/{logger.js.t => logger.js.ts} | 17 +- .../cli/_templates/app/base/js/package.json.t | 19 - .../_templates/app/base/js/package.json.ts | 27 + .../app/base/js/services/index.js.t | 6 - .../app/base/js/services/index.js.ts | 16 + .../base/ts/{app.test.ts.t => app.test.ts.ts} | 23 +- .../base/ts/{channels.ts.t => channels.ts.ts} | 37 +- .../{declarations.ts.t => declarations.ts.ts} | 19 +- .../{express.app.ts.t => express.app.ts.ts} | 23 +- .../cli/_templates/app/base/ts/index.ts.t | 12 - .../cli/_templates/app/base/ts/index.ts.ts | 24 + .../base/ts/{koa.app.ts.t => koa.app.ts.ts} | 23 +- .../app/base/ts/{logger.ts.t => logger.ts.ts} | 17 +- .../cli/_templates/app/base/ts/package.json.t | 19 - .../_templates/app/base/ts/package.json.ts | 24 + .../app/base/ts/services/index.ts.t | 7 - .../app/base/ts/services/index.ts.ts | 18 + .../_templates/app/base/ts/tsconfig.json.t | 19 - .../_templates/app/base/ts/tsconfig.json.ts | 30 + .../app/new/{.gitignore.t => .gitignore.ts} | 19 +- .../_templates/app/new/config/default.json.t | 12 - .../_templates/app/new/config/default.json.ts | 23 + .../cli/_templates/app/new/config/test.json.t | 6 - .../_templates/app/new/config/test.json.ts | 17 + .../app/new/{index.html.t => index.html.ts} | 23 +- .../_templates/app/new/{index.js => index.ts} | 21 +- .../cli/_templates/app/new/package.json.t | 33 - .../cli/_templates/app/new/package.json.ts | 42 + .../app/new/{readme.md.t => readme.md.ts} | 36 +- .../custom/service/{index.js => index.ts} | 6 +- .../_templates/custom/service/js/class.js.t | 41 - .../_templates/custom/service/js/class.js.ts | 51 + .../service/ts/{class.ts.t => class.ts.ts} | 25 +- .../_templates/custom/service/ts/import.ts.t | 7 - .../_templates/custom/service/ts/import.ts.ts | 18 + .../hook/new/{index.js => index.ts} | 10 +- packages/cli/_templates/hook/new/js/hook.js.t | 8 - .../cli/_templates/hook/new/js/hook.js.ts | 19 + packages/cli/_templates/hook/new/ts/hook.ts.t | 11 - .../cli/_templates/hook/new/ts/hook.ts.ts | 22 + .../service/base/{index.js => index.ts} | 18 +- .../_templates/service/base/js/configure.t | 7 - .../_templates/service/base/js/configure.ts | 18 + .../cli/_templates/service/base/js/import.t | 7 - .../cli/_templates/service/base/js/import.ts | 18 + .../_templates/service/base/js/schema.js.t | 55 - .../_templates/service/base/js/schema.js.ts | 66 + .../_templates/service/base/js/service.js.t | 50 - .../_templates/service/base/js/service.js.ts | 58 + .../cli/_templates/service/base/js/test.js.t | 13 - .../cli/_templates/service/base/js/test.js.ts | 21 + .../_templates/service/base/ts/configure.t | 7 - .../_templates/service/base/ts/configure.ts | 18 + .../cli/_templates/service/base/ts/import.t | 7 - .../cli/_templates/service/base/ts/import.ts | 18 + .../_templates/service/base/ts/service.ts.t | 45 - .../_templates/service/base/ts/service.ts.ts | 54 + .../cli/_templates/service/base/ts/test.ts.t | 13 - .../cli/_templates/service/base/ts/test.ts.ts | 22 + .../service/new/{index.js => index.ts} | 6 +- packages/cli/package-lock.json | 8201 +++++++++++++++++ packages/cli/package.json | 13 +- packages/cli/src/engine.ts | 85 + packages/cli/src/execute.ts | 31 + packages/cli/src/getParams.ts | 38 + packages/cli/src/hookmodule.ts | 26 + packages/cli/src/index.ts | 17 +- packages/cli/src/logger.ts | 38 + packages/cli/src/newline.ts | 16 + packages/cli/src/ops/add.ts | 63 + packages/cli/src/ops/index.ts | 19 + packages/cli/src/ops/inject.ts | 43 + packages/cli/src/ops/injector.ts | 96 + packages/cli/src/ops/result.ts | 18 + packages/cli/src/ops/shell.ts | 29 + packages/cli/src/prompt.ts | 53 + packages/cli/src/render.ts | 57 + packages/cli/src/types.ts | 140 + packages/cli/src/utils.ts | 66 +- 86 files changed, 10012 insertions(+), 562 deletions(-) rename packages/cli/_templates/app/base/{index.js => index.ts} (59%) rename packages/cli/_templates/app/base/js/{app.test.js.t => app.test.js.ts} (62%) rename packages/cli/_templates/app/base/js/{channels.js.t => channels.js.ts} (65%) rename packages/cli/_templates/app/base/js/{express.app.js.t => express.app.js.ts} (60%) delete mode 100644 packages/cli/_templates/app/base/js/index.js.t create mode 100644 packages/cli/_templates/app/base/js/index.js.ts rename packages/cli/_templates/app/base/js/{koa.app.js.t => koa.app.js.ts} (57%) rename packages/cli/_templates/app/base/js/{logger.js.t => logger.js.ts} (53%) delete mode 100644 packages/cli/_templates/app/base/js/package.json.t create mode 100644 packages/cli/_templates/app/base/js/package.json.ts delete mode 100644 packages/cli/_templates/app/base/js/services/index.js.t create mode 100644 packages/cli/_templates/app/base/js/services/index.js.ts rename packages/cli/_templates/app/base/ts/{app.test.ts.t => app.test.ts.ts} (63%) rename packages/cli/_templates/app/base/ts/{channels.ts.t => channels.ts.ts} (65%) rename packages/cli/_templates/app/base/ts/{declarations.ts.t => declarations.ts.ts} (54%) rename packages/cli/_templates/app/base/ts/{express.app.ts.t => express.app.ts.ts} (64%) delete mode 100644 packages/cli/_templates/app/base/ts/index.ts.t create mode 100644 packages/cli/_templates/app/base/ts/index.ts.ts rename packages/cli/_templates/app/base/ts/{koa.app.ts.t => koa.app.ts.ts} (58%) rename packages/cli/_templates/app/base/ts/{logger.ts.t => logger.ts.ts} (55%) delete mode 100644 packages/cli/_templates/app/base/ts/package.json.t create mode 100644 packages/cli/_templates/app/base/ts/package.json.ts delete mode 100644 packages/cli/_templates/app/base/ts/services/index.ts.t create mode 100644 packages/cli/_templates/app/base/ts/services/index.ts.ts delete mode 100644 packages/cli/_templates/app/base/ts/tsconfig.json.t create mode 100644 packages/cli/_templates/app/base/ts/tsconfig.json.ts rename packages/cli/_templates/app/new/{.gitignore.t => .gitignore.ts} (85%) delete mode 100644 packages/cli/_templates/app/new/config/default.json.t create mode 100644 packages/cli/_templates/app/new/config/default.json.ts delete mode 100644 packages/cli/_templates/app/new/config/test.json.t create mode 100644 packages/cli/_templates/app/new/config/test.json.ts rename packages/cli/_templates/app/new/{index.html.t => index.html.ts} (96%) rename packages/cli/_templates/app/new/{index.js => index.ts} (79%) delete mode 100644 packages/cli/_templates/app/new/package.json.t create mode 100644 packages/cli/_templates/app/new/package.json.ts rename packages/cli/_templates/app/new/{readme.md.t => readme.md.ts} (63%) rename packages/cli/_templates/custom/service/{index.js => index.ts} (61%) delete mode 100644 packages/cli/_templates/custom/service/js/class.js.t create mode 100644 packages/cli/_templates/custom/service/js/class.js.ts rename packages/cli/_templates/custom/service/ts/{class.ts.t => class.ts.ts} (59%) delete mode 100644 packages/cli/_templates/custom/service/ts/import.ts.t create mode 100644 packages/cli/_templates/custom/service/ts/import.ts.ts rename packages/cli/_templates/hook/new/{index.js => index.ts} (52%) delete mode 100644 packages/cli/_templates/hook/new/js/hook.js.t create mode 100644 packages/cli/_templates/hook/new/js/hook.js.ts delete mode 100644 packages/cli/_templates/hook/new/ts/hook.ts.t create mode 100644 packages/cli/_templates/hook/new/ts/hook.ts.ts rename packages/cli/_templates/service/base/{index.js => index.ts} (67%) delete mode 100644 packages/cli/_templates/service/base/js/configure.t create mode 100644 packages/cli/_templates/service/base/js/configure.ts delete mode 100644 packages/cli/_templates/service/base/js/import.t create mode 100644 packages/cli/_templates/service/base/js/import.ts delete mode 100644 packages/cli/_templates/service/base/js/schema.js.t create mode 100644 packages/cli/_templates/service/base/js/schema.js.ts delete mode 100644 packages/cli/_templates/service/base/js/service.js.t create mode 100644 packages/cli/_templates/service/base/js/service.js.ts delete mode 100644 packages/cli/_templates/service/base/js/test.js.t create mode 100644 packages/cli/_templates/service/base/js/test.js.ts delete mode 100644 packages/cli/_templates/service/base/ts/configure.t create mode 100644 packages/cli/_templates/service/base/ts/configure.ts delete mode 100644 packages/cli/_templates/service/base/ts/import.t create mode 100644 packages/cli/_templates/service/base/ts/import.ts delete mode 100644 packages/cli/_templates/service/base/ts/service.ts.t create mode 100644 packages/cli/_templates/service/base/ts/service.ts.ts delete mode 100644 packages/cli/_templates/service/base/ts/test.ts.t create mode 100644 packages/cli/_templates/service/base/ts/test.ts.ts rename packages/cli/_templates/service/new/{index.js => index.ts} (59%) create mode 100644 packages/cli/package-lock.json create mode 100644 packages/cli/src/engine.ts create mode 100644 packages/cli/src/execute.ts create mode 100644 packages/cli/src/getParams.ts create mode 100644 packages/cli/src/hookmodule.ts create mode 100644 packages/cli/src/logger.ts create mode 100644 packages/cli/src/newline.ts create mode 100644 packages/cli/src/ops/add.ts create mode 100644 packages/cli/src/ops/index.ts create mode 100644 packages/cli/src/ops/inject.ts create mode 100644 packages/cli/src/ops/injector.ts create mode 100644 packages/cli/src/ops/result.ts create mode 100644 packages/cli/src/ops/shell.ts create mode 100644 packages/cli/src/prompt.ts create mode 100644 packages/cli/src/render.ts create mode 100644 packages/cli/src/types.ts diff --git a/packages/cli/_templates/app/base/index.js b/packages/cli/_templates/app/base/index.ts similarity index 59% rename from packages/cli/_templates/app/base/index.js rename to packages/cli/_templates/app/base/index.ts index f22362a34a..323ef87233 100644 --- a/packages/cli/_templates/app/base/index.js +++ b/packages/cli/_templates/app/base/index.ts @@ -1,7 +1,15 @@ -module.exports = { - async prompt ({ config }) { +import { PromptOptions, RunnerConfig } from "../../../src"; + +export type VariablesAppBase = { + hasSocketio: boolean + dependencies: string[] + devDependencies: string[] +} + +export default { + async prompt ({ config }: PromptOptions) { const { feathers } = config.helpers; - const hasSocketio = feathers.transports && feathers.transports.includes('websockets'); + const hasSocketio = feathers?.transports?.includes('websockets'); const dependencies = [ '@feathersjs/feathers', '@feathersjs/errors', @@ -21,18 +29,18 @@ module.exports = { dependencies.push('@feathersjs/socketio'); } - if (feathers.database !== 'custom') { + if (["mongodb", "sequelize"].includes(feathers?.database)) { dependencies.push(`feathers-${feathers.database}`); } - if (feathers.framework === 'koa') { + if (feathers?.framework === 'koa') { dependencies.push( '@feathersjs/koa', 'koa-static' ); } - if (feathers.framework === 'express') { + if (feathers?.framework === 'express') { dependencies.push( '@feathersjs/express', 'compression', @@ -40,10 +48,17 @@ module.exports = { ); } - if (feathers.language === 'ts') { + if (feathers?.language === 'ts') { devDependencies.push( '@types/mocha', - feathers.framework === 'koa' ? '@types/koa-static' : '@types/compression', + ) + if (feathers.framework === "koa") { + devDependencies.push('@types/koa-static') + } + if (feathers.framework === "express") { + devDependencies.push('@types/compression') + } + devDependencies.push( '@types/node', 'nodemon', 'ts-node', @@ -59,7 +74,7 @@ module.exports = { }; }, - async rendered (result, config) { + async rendered (result: any, config: RunnerConfig) { const { args: { dependencies, devDependencies } } = result; await config.helpers.install(config, dependencies); diff --git a/packages/cli/_templates/app/base/js/app.test.js.t b/packages/cli/_templates/app/base/js/app.test.js.ts similarity index 62% rename from packages/cli/_templates/app/base/js/app.test.js.t rename to packages/cli/_templates/app/base/js/app.test.js.ts index 8bb774e6b6..2925b13d5f 100644 --- a/packages/cli/_templates/app/base/js/app.test.js.t +++ b/packages/cli/_templates/app/base/js/app.test.js.ts @@ -1,12 +1,16 @@ ---- -to: "<%= h.test %>/app.test.js" ---- +import { join } from 'path' +import { GeneratorContext, RenderResult } from '../../../../src'; +import { VariablesApp } from '../../new'; + +export function render (context: GeneratorContext): RenderResult { + const to = join(context.h.test, 'app.test.js') + const body = ` import assert from 'assert'; import axios from 'axios'; -import { app } from '../<%= h.lib %>/app.js'; +import { app } from '../${context.h.lib}/app.js'; const port = app.get('port'); -const appUrl = `http://${app.get('host')}:${port}`; +const appUrl = \`http://\${app.get('host')}:\${port}\`; describe('Feathers application tests', () => { let server; @@ -27,7 +31,7 @@ describe('Feathers application tests', () => { it('shows a 404 JSON error', async () => { try { - await axios.get(`${appUrl}/path/to/nowhere`, { + await axios.get(\`\${appUrl}/path/to/nowhere\`, { responseType: 'json' }); assert.fail('should never get here'); @@ -40,3 +44,10 @@ describe('Feathers application tests', () => { } }); }); +` + + return { + body, + to + } +} \ No newline at end of file diff --git a/packages/cli/_templates/app/base/js/channels.js.t b/packages/cli/_templates/app/base/js/channels.js.ts similarity index 65% rename from packages/cli/_templates/app/base/js/channels.js.t rename to packages/cli/_templates/app/base/js/channels.js.ts index ec0701d71b..54b86e87ad 100644 --- a/packages/cli/_templates/app/base/js/channels.js.t +++ b/packages/cli/_templates/app/base/js/channels.js.ts @@ -1,6 +1,10 @@ ---- -to: "<%= h.lib %>/channels.js" ---- +import { join } from 'path' +import { GeneratorContext, RenderResult } from '../../../../src'; +import { VariablesApp } from '../../new'; + +export function render (context: GeneratorContext): RenderResult { + const to = join(context.h.lib, 'channels.js') + const body = ` import { logger } from './logger.js'; export default app => { @@ -9,7 +13,7 @@ export default app => { return; } - logger.warn('Publishing all events to all authenticated users. See `channels.js` and https://docs.feathersjs.com/api/channels.html for more information.'); + logger.warn('Publishing all events to all authenticated users. See \`channels.js\` and https://docs.feathersjs.com/api/channels.html for more information.'); app.on('connection', connection => { // On a new real-time connection, add it to the anonymous channel @@ -35,32 +39,39 @@ export default app => { // if(user.isAdmin) { app.channel('admins').join(connection); } // If the user has joined e.g. chat rooms - // if(Array.isArray(user.rooms)) user.rooms.forEach(room => app.channel(`rooms/${room.id}`).join(connection)); + // if(Array.isArray(user.rooms)) user.rooms.forEach(room => app.channel(\`rooms/\${room.id}\`).join(connection)); // Easily organize users by email and userid for things like messaging - // app.channel(`emails/${user.email}`).join(connection); - // app.channel(`userIds/${user.id}`).join(connection); + // app.channel(\`emails/\${user.email}\`).join(connection); + // app.channel(\`userIds/\${user.id}\`).join(connection); } }); // eslint-disable-next-line no-unused-vars app.publish((data, hook) => { - // Here you can add event publishers to channels set up in `channels.js` - // To publish only for a specific event use `app.publish(eventname, () => {})` + // Here you can add event publishers to channels set up in \`channels.js\` + // To publish only for a specific event use \`app.publish(eventname, () => {})\` // e.g. to publish all service events to all authenticated users use return app.channel('authenticated'); }); // Here you can also add service specific event publishers - // e.g. the publish the `users` service `created` event to the `admins` channel + // e.g. the publish the 'users' service 'created' event to the 'admins' channel // app.service('users').publish('created', () => app.channel('admins')); // With the userid and email organization from above you can easily select involved users // app.service('messages').publish(() => { // return [ - // app.channel(`userIds/${data.createdBy}`), - // app.channel(`emails/${data.recipientEmail}`) + // app.channel(\`userIds/\${data.createdBy}\`), + // app.channel(\`emails/\${data.recipientEmail}\`) // ]; // }); }; +` + + return { + body, + to + } +} \ No newline at end of file diff --git a/packages/cli/_templates/app/base/js/express.app.js.t b/packages/cli/_templates/app/base/js/express.app.js.ts similarity index 60% rename from packages/cli/_templates/app/base/js/express.app.js.t rename to packages/cli/_templates/app/base/js/express.app.js.ts index 6777be3668..7f11996917 100644 --- a/packages/cli/_templates/app/base/js/express.app.js.t +++ b/packages/cli/_templates/app/base/js/express.app.js.ts @@ -1,13 +1,20 @@ ---- -to: "<%= h.feathers.framework === 'express' ? `${h.lib}/app.js` : null %>" ---- +import { join } from 'path' +import { VariablesAppBase } from '..'; +import { GeneratorContext, RenderResult } from '../../../../src'; +import { VariablesApp } from '../../new'; + +export function render (context: GeneratorContext): RenderResult { + const to = (context.h.feathers.framework === "express") + ? join(context.h.lib, 'app.js') + : null; + const body = ` import compress from 'compression'; import helmet from 'helmet'; import { feathers } from '@feathersjs/feathers'; import express from '@feathersjs/express'; import configuration from '@feathersjs/configuration'; -<% if (hasSocketio) { %>import socketio from '@feathersjs/socketio';<% } %> +${ (context.hasSocketio) ? 'import socketio from \'@feathersjs/socketio\'' : '' } import { logger } from './logger.js'; import services from './services/index.js'; @@ -26,7 +33,7 @@ app.use('/', express.static(app.get('public'))); // Configure services and real-time functionality app.configure(express.rest()); -<% if (hasSocketio) { %>app.configure(socketio());<% } %> +${ (context.hasSocketio) ? 'app.configure(socketio());' : '' } app.configure(services); app.configure(channels); @@ -35,3 +42,10 @@ app.use(express.notFound()); app.use(express.errorHandler({ logger })); export { app }; +` + + return { + body, + to + } +} \ No newline at end of file diff --git a/packages/cli/_templates/app/base/js/index.js.t b/packages/cli/_templates/app/base/js/index.js.t deleted file mode 100644 index b6e9e56e83..0000000000 --- a/packages/cli/_templates/app/base/js/index.js.t +++ /dev/null @@ -1,12 +0,0 @@ ---- -to: "<%= h.lib %>/index.js" ---- -import { app } from './app.js'; -import { logger } from './logger.js'; - -const port = app.get('port'); -const host = app.get('host'); - -app.listen(port).then(() => { - logger.info(`Feathers app listening on http://${host}:${port}`); -}); diff --git a/packages/cli/_templates/app/base/js/index.js.ts b/packages/cli/_templates/app/base/js/index.js.ts new file mode 100644 index 0000000000..720454211a --- /dev/null +++ b/packages/cli/_templates/app/base/js/index.js.ts @@ -0,0 +1,24 @@ +import { join } from 'path' +import { VariablesAppBase } from '..'; +import { GeneratorContext, RenderResult } from '../../../../src'; +import { VariablesApp } from '../../new'; + +export function render (context: GeneratorContext): RenderResult { + const to = join(context.h.lib, 'index.ts'); + const body = ` +import { app } from './app.js'; +import { logger } from './logger.js'; + +const port = app.get('port'); +const host = app.get('host'); + +app.listen(port).then(() => { + logger.info(\`Feathers app listening on http://\${host}:\${port}\`); +}); +` + + return { + body, + to + } +} \ No newline at end of file diff --git a/packages/cli/_templates/app/base/js/koa.app.js.t b/packages/cli/_templates/app/base/js/koa.app.js.ts similarity index 57% rename from packages/cli/_templates/app/base/js/koa.app.js.t rename to packages/cli/_templates/app/base/js/koa.app.js.ts index 01d31c73ec..eb266d34d8 100644 --- a/packages/cli/_templates/app/base/js/koa.app.js.t +++ b/packages/cli/_templates/app/base/js/koa.app.js.ts @@ -1,11 +1,17 @@ ---- -to: "<%= h.feathers.framework === 'koa' ? `${h.lib}/app.js` : null %>" ---- +import { join } from 'path' +import { VariablesAppBase } from '..'; +import { GeneratorContext, RenderResult } from '../../../../src'; + +export function render (context: GeneratorContext): RenderResult { + const to = (context.h.feathers.framework === "koa") + ? join(context.h.lib, 'app.js') + : null; + const body = ` import serveStatic from 'koa-static'; import { feathers } from '@feathersjs/feathers'; import configuration from '@feathersjs/configuration'; import { koa, rest, bodyParser, errorHandler, authentication } from '@feathersjs/koa'; -<% if (hasSocketio) { %>import socketio from '@feathersjs/socketio';<% } %> +${ (context.hasSocketio) ? 'import socketio from \'@feathersjs/socketio\'' : '' } import services from './services/index.js'; import channels from './channels.js'; @@ -23,8 +29,15 @@ app.use(bodyParser()); app.use(rest()); // Configure services and real-time functionality -<% if (hasSocketio) { %>app.configure(socketio());<% } %> +${ (context.hasSocketio) ? 'app.configure(socketio());' : '' } app.configure(services); app.configure(channels); export { app }; +` + + return { + body, + to + } +} \ No newline at end of file diff --git a/packages/cli/_templates/app/base/js/logger.js.t b/packages/cli/_templates/app/base/js/logger.js.ts similarity index 53% rename from packages/cli/_templates/app/base/js/logger.js.t rename to packages/cli/_templates/app/base/js/logger.js.ts index 6f04536ff3..8a46de4781 100644 --- a/packages/cli/_templates/app/base/js/logger.js.t +++ b/packages/cli/_templates/app/base/js/logger.js.ts @@ -1,7 +1,11 @@ ---- -to: "<%= h.lib %>/logger.js" ---- +import { join } from 'path' +import { VariablesAppBase } from '..'; +import { GeneratorContext, RenderResult } from '../../../../src'; +import { VariablesApp } from '../../new'; +export function render (context: GeneratorContext): RenderResult { + const to = join(context.h.lib, 'logger.js'); + const body = ` import winston from 'winston'; const { createLogger, format, transports } = winston; @@ -18,3 +22,10 @@ export const logger = createLogger({ new transports.Console() ], }); +` + + return { + body, + to + } +} diff --git a/packages/cli/_templates/app/base/js/package.json.t b/packages/cli/_templates/app/base/js/package.json.t deleted file mode 100644 index ed561d4913..0000000000 --- a/packages/cli/_templates/app/base/js/package.json.t +++ /dev/null @@ -1,19 +0,0 @@ ---- -to: "package.json" -force: true ---- -<% - -// This extends the content of the existing package.json -const pkg = { - ...h.pkg, - type: 'module', - scripts: { - ...h.scripts, - start: `node ${h.lib}/`, - dev: `nodemon ${h.lib}/`, - test: 'mocha test/ --recursive --exit' - } -}; - -%><%- JSON.stringify(pkg, null, ' ') %> diff --git a/packages/cli/_templates/app/base/js/package.json.ts b/packages/cli/_templates/app/base/js/package.json.ts new file mode 100644 index 0000000000..1a04014ee6 --- /dev/null +++ b/packages/cli/_templates/app/base/js/package.json.ts @@ -0,0 +1,27 @@ +import { join } from 'path' +import { VariablesAppBase } from '..'; +import { GeneratorContext, RenderResult } from '../../../../src'; +import { VariablesApp } from '../../new'; + +export function render (context: GeneratorContext): RenderResult { + const to = join('package.json'); + + const pkg = { + ...context.h.pkg, + type: 'module', + scripts: { + ...context.h.pkg.scripts, + start: `node ${context.h.lib}/`, + dev: `nodemon ${context.h.lib}/`, + test: 'mocha test/ --recursive --exit' + } + }; + + const body = JSON.stringify(pkg) + + return { + body, + to, + force: true + } +} diff --git a/packages/cli/_templates/app/base/js/services/index.js.t b/packages/cli/_templates/app/base/js/services/index.js.t deleted file mode 100644 index 1279ab36af..0000000000 --- a/packages/cli/_templates/app/base/js/services/index.js.t +++ /dev/null @@ -1,6 +0,0 @@ ---- -to: "<%= h.lib %>/services/index.js" ---- - -export default app => { -} diff --git a/packages/cli/_templates/app/base/js/services/index.js.ts b/packages/cli/_templates/app/base/js/services/index.js.ts new file mode 100644 index 0000000000..f91251db24 --- /dev/null +++ b/packages/cli/_templates/app/base/js/services/index.js.ts @@ -0,0 +1,16 @@ +import { join } from 'path' +import { VariablesAppBase } from '../..'; +import { GeneratorContext, RenderResult } from '../../../../../src'; + +export function render (context: GeneratorContext): RenderResult { + const to = join(context.h.lib, 'services', 'index.js') + const body = ` +export default app => { +} +` + + return { + body, + to + } +} \ No newline at end of file diff --git a/packages/cli/_templates/app/base/ts/app.test.ts.t b/packages/cli/_templates/app/base/ts/app.test.ts.ts similarity index 63% rename from packages/cli/_templates/app/base/ts/app.test.ts.t rename to packages/cli/_templates/app/base/ts/app.test.ts.ts index 0e552710a2..3d4434d29f 100644 --- a/packages/cli/_templates/app/base/ts/app.test.ts.t +++ b/packages/cli/_templates/app/base/ts/app.test.ts.ts @@ -1,13 +1,17 @@ ---- -to: "<%= h.test %>/app.test.ts" ---- +import { join } from 'path' +import { VariablesAppBase } from '..'; +import { GeneratorContext, RenderResult } from '../../../../src'; + +export function render (context: GeneratorContext): RenderResult { + const to = join(context.h.test, 'app.test.ts') + const body = ` import assert from 'assert'; import axios from 'axios'; import { Server } from 'http'; -import { app } from '../<%= h.lib %>/app'; +import { app } from '../${context.h.lib}/app'; const port = app.get('port'); -const appUrl = `http://${app.get('host')}:${port}`; +const appUrl = \`http://\${app.get('host')}:\${port}\`; describe('Feathers application tests', () => { let server: Server; @@ -28,7 +32,7 @@ describe('Feathers application tests', () => { it('shows a 404 JSON error', async () => { try { - await axios.get(`${appUrl}/path/to/nowhere`, { + await axios.get(\`\${appUrl}/path/to/nowhere\`, { responseType: 'json' }); assert.fail('should never get here'); @@ -40,3 +44,10 @@ describe('Feathers application tests', () => { } }); }); +` + + return { + body, + to + } +} \ No newline at end of file diff --git a/packages/cli/_templates/app/base/ts/channels.ts.t b/packages/cli/_templates/app/base/ts/channels.ts.ts similarity index 65% rename from packages/cli/_templates/app/base/ts/channels.ts.t rename to packages/cli/_templates/app/base/ts/channels.ts.ts index b715f8a783..91e584eb17 100644 --- a/packages/cli/_templates/app/base/ts/channels.ts.t +++ b/packages/cli/_templates/app/base/ts/channels.ts.ts @@ -1,6 +1,10 @@ ---- -to: "<%= h.lib %>/channels.ts" ---- +import { join } from 'path' +import { VariablesAppBase } from '..'; +import { GeneratorContext, RenderResult } from '../../../../src'; + +export function render (context: GeneratorContext): RenderResult { + const to = join(context.h.lib, 'channels.ts') + const body = ` import '@feathersjs/transport-commons'; import { Application, HookContext } from './declarations'; import { logger } from './logger'; @@ -11,7 +15,7 @@ export default function(app: Application) { return; } - logger.warn('Publishing all events to all authenticated users. See `channels.js` and https://docs.feathersjs.com/api/channels.html for more information.'); + logger.warn('Publishing all events to all authenticated users. See \`channels.js\` and https://docs.feathersjs.com/api/channels.html for more information.'); app.on('connection', (connection: any) => { // On a new real-time connection, add it to the anonymous channel @@ -37,34 +41,41 @@ export default function(app: Application) { // if(user.isAdmin) { app.channel('admins').join(connection); } // If the user has joined e.g. chat rooms - // if(Array.isArray(user.rooms)) user.rooms.forEach(room => app.channel(`rooms/${room.id}`).join(connection)); + // if(Array.isArray(user.rooms)) user.rooms.forEach(room => app.channel(\`rooms/\${room.id}\`).join(connection)); // Easily organize users by email and userid for things like messaging - // app.channel(`emails/${user.email}`).join(connection); - // app.channel(`userIds/${user.id}`).join(connection); + // app.channel(\`emails/\${user.email}\`).join(connection); + // app.channel(\`userIds/\${user.id}\`).join(connection); } }); // eslint-disable-next-line no-unused-vars app.publish((data: any, hook: HookContext) => { - // Here you can add event publishers to channels set up in `channels.js` - // To publish only for a specific event use `app.publish(eventname, () => {})` + // Here you can add event publishers to channels set up in \`channels.js\` + // To publish only for a specific event use \`app.publish(eventname, () => {})\` - console.log('Publishing all events to all authenticated users. See `channels.js` and https://docs.feathersjs.com/api/channels.html for more information.'); // eslint-disable-line + console.log('Publishing all events to all authenticated users. See \`channels.js\` and https://docs.feathersjs.com/api/channels.html for more information.'); // eslint-disable-line // e.g. to publish all service events to all authenticated users use return app.channel('authenticated'); }); // Here you can also add service specific event publishers - // e.g. the publish the `users` service `created` event to the `admins` channel + // e.g. the publish the 'users' service 'created' event to the 'admins' channel // app.service('users').publish('created', () => app.channel('admins')); // With the userid and email organization from above you can easily select involved users // app.service('messages').publish(() => { // return [ - // app.channel(`userIds/${data.createdBy}`), - // app.channel(`emails/${data.recipientEmail}`) + // app.channel(\`userIds/\${data.createdBy}\`), + // app.channel(\`emails/\${data.recipientEmail}\`) // ]; // }); }; +` + + return { + body, + to + } +} \ No newline at end of file diff --git a/packages/cli/_templates/app/base/ts/declarations.ts.t b/packages/cli/_templates/app/base/ts/declarations.ts.ts similarity index 54% rename from packages/cli/_templates/app/base/ts/declarations.ts.t rename to packages/cli/_templates/app/base/ts/declarations.ts.ts index 014102dc61..f452369c88 100644 --- a/packages/cli/_templates/app/base/ts/declarations.ts.t +++ b/packages/cli/_templates/app/base/ts/declarations.ts.ts @@ -1,8 +1,12 @@ ---- -to: "<%= h.lib %>/declarations.ts" ---- +import { join } from 'path' +import { VariablesAppBase } from '..'; +import { GeneratorContext, RenderResult } from '../../../../src'; + +export function render (context: GeneratorContext): RenderResult { + const to = join(context.h.lib, 'declarations.ts') + const body = ` import { HookContext as FeathersHookContext } from '@feathersjs/feathers'; -import { Application as FeathersApplication } from '@feathersjs/<%= h.feathers.framework %>'; +import { Application as FeathersApplication } from '@feathersjs/${context.h.feathers.framework}'; // A mapping of service names to types. Will be extended in service files. export interface ServiceTypes {} @@ -11,3 +15,10 @@ export interface ServiceTypes {} export type Application = FeathersApplication; export type HookContext = FeathersHookContext; +` + + return { + body, + to + } +} \ No newline at end of file diff --git a/packages/cli/_templates/app/base/ts/express.app.ts.t b/packages/cli/_templates/app/base/ts/express.app.ts.ts similarity index 64% rename from packages/cli/_templates/app/base/ts/express.app.ts.t rename to packages/cli/_templates/app/base/ts/express.app.ts.ts index 9c9385b926..141ae01764 100644 --- a/packages/cli/_templates/app/base/ts/express.app.ts.t +++ b/packages/cli/_templates/app/base/ts/express.app.ts.ts @@ -1,13 +1,19 @@ ---- -to: "<%= h.feathers.framework === 'express' ? `${h.lib}/app.ts` : null %>" ---- +import { join } from 'path' +import { VariablesAppBase } from '..'; +import { GeneratorContext, RenderResult } from '../../../../src'; + +export function render (context: GeneratorContext): RenderResult { + const to = (context.h.feathers.framework === "express") + ? join(context.h.lib, 'app.ts') + : null; + const body = ` import compress from 'compression'; import helmet from 'helmet'; import { feathers } from '@feathersjs/feathers'; import * as express from '@feathersjs/express'; import configuration from '@feathersjs/configuration'; -<% if (hasSocketio) { %>import socketio from '@feathersjs/socketio';<% } %> +${ (context.hasSocketio) ? 'import socketio from \'@feathersjs/socketio\'' : '' } import { logger } from './logger'; import services from './services'; @@ -27,7 +33,7 @@ app.use('/', express.static(app.get('public'))); // Configure services and real-time functionality app.configure(express.rest()); -<% if (hasSocketio) { %>app.configure(socketio());<% } %> +${ (context.hasSocketio) ? 'app.configure(socketio());' : '' } app.configure(services); app.configure(channels); @@ -36,3 +42,10 @@ app.use(express.notFound()); app.use(express.errorHandler({ logger })); export { app }; +` + + return { + body, + to + } +} \ No newline at end of file diff --git a/packages/cli/_templates/app/base/ts/index.ts.t b/packages/cli/_templates/app/base/ts/index.ts.t deleted file mode 100644 index 2d531c11df..0000000000 --- a/packages/cli/_templates/app/base/ts/index.ts.t +++ /dev/null @@ -1,12 +0,0 @@ ---- -to: "<%= h.lib %>/index.ts" ---- -import { app } from './app'; -import { logger } from './logger'; - -const port = app.get('port'); -const host = app.get('host'); - -app.listen(port).then(() => { - logger.info(`Feathers app listening on http://${host}:${port}`); -}); diff --git a/packages/cli/_templates/app/base/ts/index.ts.ts b/packages/cli/_templates/app/base/ts/index.ts.ts new file mode 100644 index 0000000000..2a5f11bc6d --- /dev/null +++ b/packages/cli/_templates/app/base/ts/index.ts.ts @@ -0,0 +1,24 @@ +import { join } from 'path' +import { VariablesAppBase } from '..'; +import { GeneratorContext, RenderResult } from '../../../../src'; +import { VariablesApp } from '../../new'; + +export function render (context: GeneratorContext): RenderResult { + const to = join(context.h.lib, 'index.ts') + const body = ` +import { app } from './app'; +import { logger } from './logger'; + +const port = app.get('port'); +const host = app.get('host'); + +app.listen(port).then(() => { + logger.info(\`Feathers app listening on http://\${host}:\${port}\`); +}); +` + + return { + body, + to + } +} \ No newline at end of file diff --git a/packages/cli/_templates/app/base/ts/koa.app.ts.t b/packages/cli/_templates/app/base/ts/koa.app.ts.ts similarity index 58% rename from packages/cli/_templates/app/base/ts/koa.app.ts.t rename to packages/cli/_templates/app/base/ts/koa.app.ts.ts index 75cf7e2ebe..ed0a3093d1 100644 --- a/packages/cli/_templates/app/base/ts/koa.app.ts.t +++ b/packages/cli/_templates/app/base/ts/koa.app.ts.ts @@ -1,11 +1,17 @@ ---- -to: "<%= h.feathers.framework === 'koa' ? `${h.lib}/app.ts` : null %>" ---- +import { join } from 'path' +import { VariablesAppBase } from '..'; +import { GeneratorContext, RenderResult } from '../../../../src'; + +export function render (context: GeneratorContext): RenderResult { + const to = (context.h.feathers.framework === "koa") + ? join(context.h.lib, 'app.ts') + : null; + const body = ` import serveStatic from 'koa-static'; import { feathers } from '@feathersjs/feathers'; import configuration from '@feathersjs/configuration'; import { koa, rest, bodyParser, errorHandler, authentication } from '@feathersjs/koa'; -<% if (hasSocketio) { %>import socketio from '@feathersjs/socketio';<% } %> +${ (context.hasSocketio) ? 'import socketio from \'@feathersjs/socketio\'' : '' } import services from './services'; import channels from './channels'; @@ -24,8 +30,15 @@ app.use(bodyParser()); app.use(rest()); // Configure services and real-time functionality -<% if (hasSocketio) { %>app.configure(socketio());<% } %> +${ (context.hasSocketio) ? 'app.configure(socketio());' : '' } app.configure(services); app.configure(channels); export { app }; +` + + return { + body, + to + } +} \ No newline at end of file diff --git a/packages/cli/_templates/app/base/ts/logger.ts.t b/packages/cli/_templates/app/base/ts/logger.ts.ts similarity index 55% rename from packages/cli/_templates/app/base/ts/logger.ts.t rename to packages/cli/_templates/app/base/ts/logger.ts.ts index 8b1aec0901..e9faec8730 100644 --- a/packages/cli/_templates/app/base/ts/logger.ts.t +++ b/packages/cli/_templates/app/base/ts/logger.ts.ts @@ -1,6 +1,10 @@ ---- -to: "<%= h.lib %>/logger.ts" ---- +import { join } from 'path' +import { VariablesAppBase } from '..'; +import { GeneratorContext, RenderResult } from '../../../../src'; + +export function render (context: GeneratorContext): RenderResult { + const to = join(context.h.lib, 'logger.ts') + const body = ` import { createLogger, format, transports } from 'winston'; // Configure the Winston logger. For the complete documentation see https://github.com/winstonjs/winston @@ -15,3 +19,10 @@ export const logger = createLogger({ new transports.Console() ], }); +` + + return { + body, + to + } +} \ No newline at end of file diff --git a/packages/cli/_templates/app/base/ts/package.json.t b/packages/cli/_templates/app/base/ts/package.json.t deleted file mode 100644 index 4a6cea0492..0000000000 --- a/packages/cli/_templates/app/base/ts/package.json.t +++ /dev/null @@ -1,19 +0,0 @@ ---- -to: "package.json" -force: true ---- -<% - -// This extends the content of the existing package.json -const pkg = { - ...h.pkg, - scripts: { - ...h.pkg.scripts, - dev: 'nodemon -x ts-node ${h.lib}/index.ts', - compile: 'shx rm -rf lib/ && tsc', - start: 'npm run compile && node lib/', - test: 'mocha test/ --require ts-node/register --recursive --extension .ts --exit' - } -}; - -%><%- JSON.stringify(pkg, null, ' ') %> diff --git a/packages/cli/_templates/app/base/ts/package.json.ts b/packages/cli/_templates/app/base/ts/package.json.ts new file mode 100644 index 0000000000..aa28504961 --- /dev/null +++ b/packages/cli/_templates/app/base/ts/package.json.ts @@ -0,0 +1,24 @@ +import { join } from 'path' +import { VariablesAppBase } from '..'; +import { GeneratorContext, RenderResult } from '../../../../src'; + +export function render (context: GeneratorContext): RenderResult { + const to = join('package.json') + const pkg = { + ...context.h.pkg, + scripts: { + ...context.h.pkg.scripts, + dev: 'nodemon -x ts-node ${h.lib}/index.ts', + compile: 'shx rm -rf lib/ && tsc', + start: 'npm run compile && node lib/', + test: 'mocha test/ --require ts-node/register --recursive --extension .ts --exit' + } + }; + const body = JSON.stringify(pkg) + + return { + body, + to, + force: true + } +} \ No newline at end of file diff --git a/packages/cli/_templates/app/base/ts/services/index.ts.t b/packages/cli/_templates/app/base/ts/services/index.ts.t deleted file mode 100644 index 4c4ae267f9..0000000000 --- a/packages/cli/_templates/app/base/ts/services/index.ts.t +++ /dev/null @@ -1,7 +0,0 @@ ---- -to: "<%= h.lib %>/services/index.ts" ---- -import { Application } from '../declarations'; - -export default (app: Application) => { -} diff --git a/packages/cli/_templates/app/base/ts/services/index.ts.ts b/packages/cli/_templates/app/base/ts/services/index.ts.ts new file mode 100644 index 0000000000..220343dcb5 --- /dev/null +++ b/packages/cli/_templates/app/base/ts/services/index.ts.ts @@ -0,0 +1,18 @@ +import { join } from 'path' +import { VariablesAppBase } from '../..' +import { GeneratorContext, RenderResult } from '../../../../../src' + +export function render (context: GeneratorContext): RenderResult { + const to = join(context.h.lib, 'services', 'index.ts') + const body = ` +import { Application } from '../declarations'; + +export default (app: Application) => { +} +` + + return { + body, + to + } +} \ No newline at end of file diff --git a/packages/cli/_templates/app/base/ts/tsconfig.json.t b/packages/cli/_templates/app/base/ts/tsconfig.json.t deleted file mode 100644 index df7d7d74c3..0000000000 --- a/packages/cli/_templates/app/base/ts/tsconfig.json.t +++ /dev/null @@ -1,19 +0,0 @@ ---- -to: "tsconfig.json" ---- -{ - "ts-node": { - "files": true - }, - "compilerOptions": { - "target": "es2020", - "module": "commonjs", - "outDir": "./lib", - "rootDir": "./<%= h.lib %>", - "strict": true, - "esModuleInterop": true - }, - "exclude": [ - "test" - ] -} diff --git a/packages/cli/_templates/app/base/ts/tsconfig.json.ts b/packages/cli/_templates/app/base/ts/tsconfig.json.ts new file mode 100644 index 0000000000..81e1e549ae --- /dev/null +++ b/packages/cli/_templates/app/base/ts/tsconfig.json.ts @@ -0,0 +1,30 @@ +import { join } from 'path' +import { GeneratorContext, RenderResult } from '../../../../src'; +import { VariablesApp } from '../../new'; + +export function render (context: GeneratorContext): RenderResult { + const to = join('tsconfig.json') + const body = ` +{ + "ts-node": { + "files": true + }, + "compilerOptions": { + "target": "es2020", + "module": "commonjs", + "outDir": "./lib", + "rootDir": "${context.h.lib}", + "strict": true, + "esModuleInterop": true + }, + "exclude": [ + "test" + ] +} +` + + return { + body, + to + } +} \ No newline at end of file diff --git a/packages/cli/_templates/app/new/.gitignore.t b/packages/cli/_templates/app/new/.gitignore.ts similarity index 85% rename from packages/cli/_templates/app/new/.gitignore.t rename to packages/cli/_templates/app/new/.gitignore.ts index 75bb12a830..9aac7b4e71 100644 --- a/packages/cli/_templates/app/new/.gitignore.t +++ b/packages/cli/_templates/app/new/.gitignore.ts @@ -1,6 +1,10 @@ ---- -to: ".gitignore" ---- +import { join } from 'path' +import { VariablesApp } from '.' +import { GeneratorContext, RenderResult } from '../../../src' + +export function render (_context: GeneratorContext): RenderResult { + const to = join('.gitignore') + const body = ` # Logs logs *.log @@ -118,4 +122,11 @@ dist .yarn/unplugged .yarn/build-state.yml .yarn/install-state.gz -.pnp.* \ No newline at end of file +.pnp.* + ` + + return { + body, + to + } +} \ No newline at end of file diff --git a/packages/cli/_templates/app/new/config/default.json.t b/packages/cli/_templates/app/new/config/default.json.t deleted file mode 100644 index 454fa9bc89..0000000000 --- a/packages/cli/_templates/app/new/config/default.json.t +++ /dev/null @@ -1,12 +0,0 @@ ---- -to: "config/default.json" ---- -{ - "host": "localhost", - "port": 3030, - "public": "./public/", - "paginate": { - "default": 10, - "max": 50 - } -} diff --git a/packages/cli/_templates/app/new/config/default.json.ts b/packages/cli/_templates/app/new/config/default.json.ts new file mode 100644 index 0000000000..22a242768a --- /dev/null +++ b/packages/cli/_templates/app/new/config/default.json.ts @@ -0,0 +1,23 @@ +import { join } from 'path' +import { VariablesApp } from '..' +import { GeneratorContext, RenderResult } from '../../../../src' + +export function render (context: GeneratorContext): RenderResult { + const to = join(context.lib, 'config', 'default.json') + const body = ` +{ + "host": "localhost", + "port": 3030, + "public": "./public/", + "paginate": { + "default": 10, + "max": 50 + } +} +` + + return { + body, + to + } +} \ No newline at end of file diff --git a/packages/cli/_templates/app/new/config/test.json.t b/packages/cli/_templates/app/new/config/test.json.t deleted file mode 100644 index 92057c1f62..0000000000 --- a/packages/cli/_templates/app/new/config/test.json.t +++ /dev/null @@ -1,6 +0,0 @@ ---- -to: "config/test.json" ---- -{ - "port": 8998 -} diff --git a/packages/cli/_templates/app/new/config/test.json.ts b/packages/cli/_templates/app/new/config/test.json.ts new file mode 100644 index 0000000000..0ac6eec9e9 --- /dev/null +++ b/packages/cli/_templates/app/new/config/test.json.ts @@ -0,0 +1,17 @@ +import { join } from 'path' +import { VariablesApp } from '..' +import { GeneratorContext, RenderResult } from '../../../../src' + +export function render (context: GeneratorContext): RenderResult { + const to = join(context.lib, 'config', 'test.json') + const body = ` +{ + "port": 8998 +} +` + +return { + body, + to +} +} \ No newline at end of file diff --git a/packages/cli/_templates/app/new/index.html.t b/packages/cli/_templates/app/new/index.html.ts similarity index 96% rename from packages/cli/_templates/app/new/index.html.t rename to packages/cli/_templates/app/new/index.html.ts index 3fdcc0e3c7..eea6c09052 100644 --- a/packages/cli/_templates/app/new/index.html.t +++ b/packages/cli/_templates/app/new/index.html.ts @@ -1,11 +1,15 @@ ---- -to: "public/index.html" ---- +import { join } from 'path' +import { VariablesApp } from '.' +import { GeneratorContext, RenderResult } from '../../../src' + +export function render (context: GeneratorContext): RenderResult { + const to = join('public', 'index.html') + const body = ` - <%= name %> - + ${context.name} +