@feathersjs/cli 5.0.0-pre.26 → 5.0.0-pre.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/lib/app/index.js +1 -1
- package/lib/app/index.js.map +1 -1
- package/lib/app/index.ts +1 -1
- package/lib/app/templates/app.tpl.js +2 -2
- package/lib/app/templates/app.tpl.ts +2 -2
- package/lib/app/templates/client.tpl.js +1 -1
- package/lib/app/templates/client.tpl.ts +1 -1
- package/lib/app/templates/configuration.tpl.js +23 -20
- package/lib/app/templates/configuration.tpl.js.map +1 -1
- package/lib/app/templates/configuration.tpl.ts +23 -20
- package/lib/app/templates/declarations.tpl.js +1 -1
- package/lib/app/templates/declarations.tpl.ts +1 -1
- package/lib/app/templates/package.json.tpl.js +2 -0
- package/lib/app/templates/package.json.tpl.js.map +1 -1
- package/lib/app/templates/package.json.tpl.ts +2 -0
- package/lib/app/templates/prettierrc.tpl.d.ts +2 -0
- package/lib/app/templates/prettierrc.tpl.js +11 -0
- package/lib/app/templates/prettierrc.tpl.js.map +1 -0
- package/lib/app/templates/prettierrc.tpl.ts +14 -0
- package/lib/authentication/index.d.ts +0 -2
- package/lib/authentication/templates/authentication.tpl.js +3 -3
- package/lib/authentication/templates/authentication.tpl.js.map +1 -1
- package/lib/authentication/templates/authentication.tpl.ts +5 -5
- package/lib/authentication/templates/declarations.tpl.js +1 -1
- package/lib/authentication/templates/declarations.tpl.js.map +1 -1
- package/lib/authentication/templates/declarations.tpl.ts +2 -2
- package/lib/authentication/templates/knex.tpl.js +6 -5
- package/lib/authentication/templates/knex.tpl.js.map +1 -1
- package/lib/authentication/templates/knex.tpl.ts +16 -17
- package/lib/authentication/templates/test.tpl.js +2 -2
- package/lib/authentication/templates/test.tpl.js.map +1 -1
- package/lib/authentication/templates/test.tpl.ts +2 -2
- package/lib/authentication/templates/user.resolver.tpl.js +6 -6
- package/lib/authentication/templates/user.resolver.tpl.js.map +1 -1
- package/lib/authentication/templates/user.resolver.tpl.ts +6 -6
- package/lib/authentication/templates/user.schema.tpl.js +7 -13
- package/lib/authentication/templates/user.schema.tpl.js.map +1 -1
- package/lib/authentication/templates/user.schema.tpl.ts +7 -13
- package/lib/commons.d.ts +19 -9
- package/lib/commons.js +56 -23
- package/lib/commons.js.map +1 -1
- package/lib/commons.ts +87 -26
- package/lib/connection/templates/knex.tpl.js +13 -16
- package/lib/connection/templates/knex.tpl.js.map +1 -1
- package/lib/connection/templates/knex.tpl.ts +18 -20
- package/lib/connection/templates/mongodb.tpl.js +5 -9
- package/lib/connection/templates/mongodb.tpl.js.map +1 -1
- package/lib/connection/templates/mongodb.tpl.ts +10 -12
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/index.ts +2 -1
- package/lib/service/index.d.ts +0 -16
- package/lib/service/index.js +3 -8
- package/lib/service/index.js.map +1 -1
- package/lib/service/index.ts +3 -16
- package/lib/service/templates/class.tpl.d.ts +2 -0
- package/lib/service/templates/class.tpl.js +63 -0
- package/lib/service/templates/class.tpl.js.map +1 -0
- package/lib/service/templates/class.tpl.ts +79 -0
- package/lib/service/templates/client.tpl.js +4 -6
- package/lib/service/templates/client.tpl.js.map +1 -1
- package/lib/service/templates/client.tpl.ts +10 -15
- package/lib/service/templates/resolver.tpl.js +4 -4
- package/lib/service/templates/resolver.tpl.js.map +1 -1
- package/lib/service/templates/resolver.tpl.ts +4 -4
- package/lib/service/templates/schema.tpl.js +2 -2
- package/lib/service/templates/schema.tpl.js.map +1 -1
- package/lib/service/templates/schema.tpl.ts +2 -2
- package/lib/service/templates/service.tpl.js +12 -58
- package/lib/service/templates/service.tpl.js.map +1 -1
- package/lib/service/templates/service.tpl.ts +17 -79
- package/lib/service/templates/test.tpl.js +4 -4
- package/lib/service/templates/test.tpl.js.map +1 -1
- package/lib/service/templates/test.tpl.ts +4 -4
- package/lib/service/type/custom.tpl.d.ts +1 -1
- package/lib/service/type/custom.tpl.js +24 -16
- package/lib/service/type/custom.tpl.js.map +1 -1
- package/lib/service/type/custom.tpl.ts +28 -19
- package/lib/service/type/knex.tpl.js +11 -5
- package/lib/service/type/knex.tpl.js.map +1 -1
- package/lib/service/type/knex.tpl.ts +14 -9
- package/lib/service/type/mongodb.tpl.js +11 -5
- package/lib/service/type/mongodb.tpl.js.map +1 -1
- package/lib/service/type/mongodb.tpl.ts +14 -9
- package/package.json +19 -19
|
@@ -8,7 +8,7 @@ const template = ({
|
|
|
8
8
|
relative,
|
|
9
9
|
authStrategies,
|
|
10
10
|
type,
|
|
11
|
-
|
|
11
|
+
fileName
|
|
12
12
|
}: AuthenticationGeneratorContext) =>
|
|
13
13
|
`import { resolve } from '@feathersjs/schema'
|
|
14
14
|
${authStrategies.includes('local') ? `import { passwordHash } from '@feathersjs/authentication-local'` : ''}
|
|
@@ -18,13 +18,13 @@ import type {
|
|
|
18
18
|
${upperName}Patch,
|
|
19
19
|
${upperName}Result,
|
|
20
20
|
${upperName}Query,
|
|
21
|
-
} from '
|
|
21
|
+
} from './${fileName}.schema'
|
|
22
22
|
import {
|
|
23
23
|
${camelName}DataSchema,
|
|
24
24
|
${camelName}PatchSchema,
|
|
25
25
|
${camelName}ResultSchema,
|
|
26
26
|
${camelName}QuerySchema
|
|
27
|
-
} from '
|
|
27
|
+
} from './${fileName}.schema'
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
// Resolver for the basic data model (e.g. creating new entries)
|
|
@@ -98,11 +98,11 @@ export const generate = (ctx: AuthenticationGeneratorContext) =>
|
|
|
98
98
|
generator(ctx).then(
|
|
99
99
|
renderSource(
|
|
100
100
|
template,
|
|
101
|
-
toFile(({ lib, folder,
|
|
101
|
+
toFile(({ lib, folder, fileName }: AuthenticationGeneratorContext) => [
|
|
102
102
|
lib,
|
|
103
|
-
'
|
|
103
|
+
'services',
|
|
104
104
|
...folder,
|
|
105
|
-
`${
|
|
105
|
+
`${fileName}.resolver`
|
|
106
106
|
]),
|
|
107
107
|
{ force: true }
|
|
108
108
|
)
|
|
@@ -15,15 +15,9 @@ export const ${camelName}DataSchema = schema({
|
|
|
15
15
|
properties: {
|
|
16
16
|
${authStrategies
|
|
17
17
|
.map((name) => name === 'local'
|
|
18
|
-
? `email: {
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
password: {
|
|
22
|
-
type: 'string'
|
|
23
|
-
}`
|
|
24
|
-
: ` ${name}Id: {
|
|
25
|
-
type: 'string'
|
|
26
|
-
}`)
|
|
18
|
+
? ` email: { type: 'string' },
|
|
19
|
+
password: { type: 'string' }`
|
|
20
|
+
: ` ${name}Id: { type: 'string' }`)
|
|
27
21
|
.join(',\n')}
|
|
28
22
|
}
|
|
29
23
|
} as const)
|
|
@@ -53,7 +47,7 @@ export const ${camelName}ResultSchema = schema({
|
|
|
53
47
|
properties: {
|
|
54
48
|
...${camelName}DataSchema.properties,
|
|
55
49
|
${type === 'mongodb' ? '_id' : 'id'}: {
|
|
56
|
-
type: 'string'
|
|
50
|
+
type: '${type === 'mongodb' ? 'string' : 'number'}'
|
|
57
51
|
}
|
|
58
52
|
}
|
|
59
53
|
} as const)
|
|
@@ -75,11 +69,11 @@ export const ${camelName}QuerySchema = schema({
|
|
|
75
69
|
|
|
76
70
|
export type ${upperName}Query = Infer<typeof ${camelName}QuerySchema>
|
|
77
71
|
`;
|
|
78
|
-
const generate = (ctx) => (0, pinion_1.generator)(ctx).then((0, commons_1.renderSource)(template, (0, pinion_1.toFile)(({ lib, folder,
|
|
72
|
+
const generate = (ctx) => (0, pinion_1.generator)(ctx).then((0, commons_1.renderSource)(template, (0, pinion_1.toFile)(({ lib, folder, fileName }) => [
|
|
79
73
|
lib,
|
|
80
|
-
'
|
|
74
|
+
'services',
|
|
81
75
|
...folder,
|
|
82
|
-
`${
|
|
76
|
+
`${fileName}.schema`
|
|
83
77
|
]), { force: true }));
|
|
84
78
|
exports.generate = generate;
|
|
85
79
|
//# sourceMappingURL=user.schema.tpl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.schema.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/user.schema.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,2CAA4C;AAG5C,MAAM,QAAQ,GAAG,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,IAAI,EAAkC,EAAE,EAAE,CAClG;;;;eAIa,SAAS;UACd,SAAS;;;gBAGH,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,EAAE;;MAEvE,cAAc;KACb,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACZ,IAAI,KAAK,OAAO;IACd,CAAC,CAAC
|
|
1
|
+
{"version":3,"file":"user.schema.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/user.schema.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,2CAA4C;AAG5C,MAAM,QAAQ,GAAG,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,IAAI,EAAkC,EAAE,EAAE,CAClG;;;;eAIa,SAAS;UACd,SAAS;;;gBAGH,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,EAAE;;MAEvE,cAAc;KACb,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACZ,IAAI,KAAK,OAAO;IACd,CAAC,CAAC;iCACqB;IACvB,CAAC,CAAC,OAAO,IAAI,wBAAwB,CACxC;KACA,IAAI,CAAC,KAAK,CAAC;;;;cAIJ,SAAS,uBAAuB,SAAS;;;;eAIxC,SAAS;UACd,SAAS;;;;;SAKV,SAAS;;;;cAIJ,SAAS,wBAAwB,SAAS;;;eAGzC,SAAS;UACd,SAAS;;;iBAGF,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;;SAEzC,SAAS;MACZ,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;eACxB,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ;;;;;cAKzC,SAAS,yBAAyB,SAAS;;;uBAGlC,SAAS,uBAAuB,SAAS;;;eAGjD,SAAS;UACd,SAAS;;;;qBAIE,SAAS;;;;cAIhB,SAAS,wBAAwB,SAAS;CACvD,CAAA;AAEM,MAAM,QAAQ,GAAG,CAAC,GAAmC,EAAE,EAAE,CAC9D,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC,IAAI,CACjB,IAAA,sBAAY,EACV,QAAQ,EACR,IAAA,eAAM,EAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAkC,EAAE,EAAE,CAAC;IACpE,GAAG;IACH,UAAU;IACV,GAAG,MAAM;IACT,GAAG,QAAQ,SAAS;CACrB,CAAC,EACF,EAAE,KAAK,EAAE,IAAI,EAAE,CAChB,CACF,CAAA;AAZU,QAAA,QAAQ,YAYlB"}
|
|
@@ -16,15 +16,9 @@ export const ${camelName}DataSchema = schema({
|
|
|
16
16
|
${authStrategies
|
|
17
17
|
.map((name) =>
|
|
18
18
|
name === 'local'
|
|
19
|
-
? `email: {
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
password: {
|
|
23
|
-
type: 'string'
|
|
24
|
-
}`
|
|
25
|
-
: ` ${name}Id: {
|
|
26
|
-
type: 'string'
|
|
27
|
-
}`
|
|
19
|
+
? ` email: { type: 'string' },
|
|
20
|
+
password: { type: 'string' }`
|
|
21
|
+
: ` ${name}Id: { type: 'string' }`
|
|
28
22
|
)
|
|
29
23
|
.join(',\n')}
|
|
30
24
|
}
|
|
@@ -55,7 +49,7 @@ export const ${camelName}ResultSchema = schema({
|
|
|
55
49
|
properties: {
|
|
56
50
|
...${camelName}DataSchema.properties,
|
|
57
51
|
${type === 'mongodb' ? '_id' : 'id'}: {
|
|
58
|
-
type: 'string'
|
|
52
|
+
type: '${type === 'mongodb' ? 'string' : 'number'}'
|
|
59
53
|
}
|
|
60
54
|
}
|
|
61
55
|
} as const)
|
|
@@ -82,11 +76,11 @@ export const generate = (ctx: AuthenticationGeneratorContext) =>
|
|
|
82
76
|
generator(ctx).then(
|
|
83
77
|
renderSource(
|
|
84
78
|
template,
|
|
85
|
-
toFile(({ lib, folder,
|
|
79
|
+
toFile(({ lib, folder, fileName }: AuthenticationGeneratorContext) => [
|
|
86
80
|
lib,
|
|
87
|
-
'
|
|
81
|
+
'services',
|
|
88
82
|
...folder,
|
|
89
|
-
`${
|
|
83
|
+
`${fileName}.schema`
|
|
90
84
|
]),
|
|
91
85
|
{ force: true }
|
|
92
86
|
)
|
package/lib/commons.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PackageJson } from 'type-fest';
|
|
2
|
-
import { Callable, PinionContext } from '@feathershq/pinion';
|
|
2
|
+
import { Callable, PinionContext, Location } from '@feathershq/pinion';
|
|
3
3
|
import * as ts from 'typescript';
|
|
4
|
+
import { Options as PrettierOptions } from 'prettier';
|
|
4
5
|
export declare type DependencyVersions = {
|
|
5
6
|
[key: string]: string;
|
|
6
7
|
};
|
|
@@ -97,24 +98,33 @@ export declare const initializeBaseContext: () => <C extends FeathersBaseContext
|
|
|
97
98
|
*/
|
|
98
99
|
export declare const getJavaScript: (typescript: string, options?: ts.TranspileOptions) => string;
|
|
99
100
|
/**
|
|
100
|
-
*
|
|
101
|
-
|
|
101
|
+
* The default configuration for prettifying files
|
|
102
|
+
*/
|
|
103
|
+
export declare const PRETTIERRC: PrettierOptions;
|
|
104
|
+
export declare const prettify: <C extends PinionContext & {
|
|
105
|
+
language: 'js' | 'ts';
|
|
106
|
+
}>(target: Callable<string, C>, options?: PrettierOptions) => (ctx: C) => Promise<C>;
|
|
107
|
+
/**
|
|
108
|
+
* Render a source file template for the language set in the context.
|
|
102
109
|
*
|
|
103
110
|
* @param templates The JavaScript and TypeScript template to render
|
|
104
|
-
* @param
|
|
111
|
+
* @param target The target filename without extension (will be added based on language)
|
|
105
112
|
* @returns The updated context
|
|
106
113
|
*/
|
|
107
114
|
export declare const renderSource: <C extends PinionContext & {
|
|
108
115
|
language: 'js' | 'ts';
|
|
109
|
-
}>(template: Callable<string, C>,
|
|
116
|
+
}>(template: Callable<string, C>, target: Callable<string, C>, options?: {
|
|
110
117
|
force: boolean;
|
|
111
118
|
}) => (ctx: C) => Promise<C>;
|
|
112
119
|
/**
|
|
113
|
-
*
|
|
120
|
+
* Inject a source template as the language set in the context.
|
|
114
121
|
*
|
|
115
|
-
* @param template The source template
|
|
122
|
+
* @param template The source template to render
|
|
123
|
+
* @param location The location to inject the code to. Must use the target language.
|
|
124
|
+
* @param target The target file name
|
|
125
|
+
* @param transpile Set to `false` if the code should not be transpiled to JavaScript
|
|
116
126
|
* @returns
|
|
117
127
|
*/
|
|
118
|
-
export declare const
|
|
128
|
+
export declare const injectSource: <C extends PinionContext & {
|
|
119
129
|
language: 'js' | 'ts';
|
|
120
|
-
}>(template: Callable<string, C
|
|
130
|
+
}>(template: Callable<string, C>, location: Location<C>, target: Callable<string, C>, transpile?: boolean) => (ctx: C) => Promise<C>;
|
package/lib/commons.js
CHANGED
|
@@ -26,7 +26,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
29
|
+
exports.injectSource = exports.renderSource = exports.prettify = exports.PRETTIERRC = exports.getJavaScript = exports.initializeBaseContext = exports.addVersions = exports.getDatabaseAdapter = void 0;
|
|
30
|
+
const promises_1 = require("fs/promises");
|
|
30
31
|
const pinion_1 = require("@feathershq/pinion");
|
|
31
32
|
const ts = __importStar(require("typescript"));
|
|
32
33
|
const prettier_1 = __importDefault(require("prettier"));
|
|
@@ -95,43 +96,75 @@ const getJavaScript = (typescript, options = {}) => {
|
|
|
95
96
|
...options.compilerOptions
|
|
96
97
|
}
|
|
97
98
|
});
|
|
98
|
-
|
|
99
|
-
return prettier_1.default.format(code, {
|
|
100
|
-
semi: false,
|
|
101
|
-
parser: 'babel',
|
|
102
|
-
singleQuote: true
|
|
103
|
-
});
|
|
99
|
+
return fixLocalImports(restoreNewLines(transpiled.outputText));
|
|
104
100
|
};
|
|
105
101
|
exports.getJavaScript = getJavaScript;
|
|
102
|
+
const getFileName = async (target, ctx) => `${await (0, pinion_1.getCallable)(target, ctx)}.${ctx.language}`;
|
|
106
103
|
/**
|
|
107
|
-
*
|
|
108
|
-
|
|
104
|
+
* The default configuration for prettifying files
|
|
105
|
+
*/
|
|
106
|
+
exports.PRETTIERRC = {
|
|
107
|
+
tabWidth: 2,
|
|
108
|
+
useTabs: false,
|
|
109
|
+
printWidth: 110,
|
|
110
|
+
semi: false,
|
|
111
|
+
trailingComma: 'none',
|
|
112
|
+
singleQuote: true
|
|
113
|
+
};
|
|
114
|
+
/*
|
|
115
|
+
* Format a source file using Prettier. Will use the local configuration, the settings set in
|
|
116
|
+
* `options` or a default configuration
|
|
109
117
|
*
|
|
110
|
-
* @param
|
|
111
|
-
* @param
|
|
118
|
+
* @param target The file to prettify
|
|
119
|
+
* @param options The Prettier options
|
|
112
120
|
* @returns The updated context
|
|
113
121
|
*/
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
122
|
+
const prettify = (target, options = exports.PRETTIERRC) => async (ctx) => {
|
|
123
|
+
const fileName = await getFileName(target, ctx);
|
|
124
|
+
const config = (await prettier_1.default.resolveConfig(ctx.cwd)) || options;
|
|
125
|
+
const content = (await (0, promises_1.readFile)(fileName)).toString();
|
|
126
|
+
try {
|
|
127
|
+
await (0, promises_1.writeFile)(fileName, await prettier_1.default.format(content, {
|
|
128
|
+
parser: ctx.language === 'ts' ? 'typescript' : 'babel',
|
|
129
|
+
...config
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
throw new Error(`Error prettifying ${fileName}: ${error.message}`);
|
|
117
134
|
}
|
|
135
|
+
return ctx;
|
|
136
|
+
};
|
|
137
|
+
exports.prettify = prettify;
|
|
138
|
+
/**
|
|
139
|
+
* Render a source file template for the language set in the context.
|
|
140
|
+
*
|
|
141
|
+
* @param templates The JavaScript and TypeScript template to render
|
|
142
|
+
* @param target The target filename without extension (will be added based on language)
|
|
143
|
+
* @returns The updated context
|
|
144
|
+
*/
|
|
145
|
+
const renderSource = (template, target, options) => async (ctx) => {
|
|
118
146
|
const { language } = ctx;
|
|
119
|
-
const fileName = await (
|
|
147
|
+
const fileName = await getFileName(target, ctx);
|
|
120
148
|
const content = language === 'js' ? (0, exports.getJavaScript)(await (0, pinion_1.getCallable)(template, ctx)) : template;
|
|
121
|
-
const renderer = (0, pinion_1.renderTemplate)(content,
|
|
122
|
-
return renderer(ctx);
|
|
149
|
+
const renderer = (0, pinion_1.renderTemplate)(content, fileName, options);
|
|
150
|
+
return renderer(ctx).then((0, exports.prettify)(target));
|
|
123
151
|
};
|
|
124
152
|
exports.renderSource = renderSource;
|
|
125
153
|
/**
|
|
126
|
-
*
|
|
154
|
+
* Inject a source template as the language set in the context.
|
|
127
155
|
*
|
|
128
|
-
* @param template The source template
|
|
156
|
+
* @param template The source template to render
|
|
157
|
+
* @param location The location to inject the code to. Must use the target language.
|
|
158
|
+
* @param target The target file name
|
|
159
|
+
* @param transpile Set to `false` if the code should not be transpiled to JavaScript
|
|
129
160
|
* @returns
|
|
130
161
|
*/
|
|
131
|
-
const
|
|
162
|
+
const injectSource = (template, location, target, transpile = true) => async (ctx) => {
|
|
132
163
|
const { language } = ctx;
|
|
133
|
-
const source = await (0, pinion_1.getCallable)(template, ctx);
|
|
134
|
-
|
|
164
|
+
const source = language === 'js' && transpile ? (0, exports.getJavaScript)(await (0, pinion_1.getCallable)(template, ctx)) : template;
|
|
165
|
+
const fileName = await getFileName(target, ctx);
|
|
166
|
+
const injector = (0, pinion_1.inject)(source, location, fileName);
|
|
167
|
+
return injector(ctx).then((0, exports.prettify)(target));
|
|
135
168
|
};
|
|
136
|
-
exports.
|
|
169
|
+
exports.injectSource = injectSource;
|
|
137
170
|
//# sourceMappingURL=commons.js.map
|
package/lib/commons.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commons.js","sourceRoot":"","sources":["../src/commons.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,+
|
|
1
|
+
{"version":3,"file":"commons.js","sourceRoot":"","sources":["../src/commons.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,0CAAiD;AACjD,+CAS2B;AAC3B,+CAAgC;AAChC,wDAA+D;AAC/D,gDAAuB;AASvB;;;;;GAKG;AACI,MAAM,kBAAkB,GAAG,CAAC,QAAsB,EAAE,EAAE,CAAC,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;AAA9F,QAAA,kBAAkB,sBAA4E;AA0D3G;;;;;;GAMG;AACI,MAAM,WAAW,GAAG,CAAC,YAAsB,EAAE,QAA4B,EAAE,EAAE,CAClF,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAA;AADpE,QAAA,WAAW,eACyD;AAEjF;;;;;GAKG;AACI,MAAM,qBAAqB,GAChC,GAAG,EAAE,CACL,CAAgC,GAAM,EAAE,EAAE,CACxC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC;KACjB,IAAI,CAAC,IAAA,iBAAQ,EAAC,IAAA,iBAAQ,EAAC,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC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E,QAAQ,EAAE,GAAG,GAAG,CAAA;IACxB,MAAM,MAAM,GACV,QAAQ,KAAK,IAAI,IAAI,SAAS,CAAC,CAAC,CAAC,IAAA,qBAAa,EAAC,MAAM,IAAA,oBAAW,EAAY,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAA;IACxG,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC/C,MAAM,QAAQ,GAAG,IAAA,eAAM,EAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAA;IAEnD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAA,gBAAQ,EAAC,MAAM,CAAC,CAAC,CAAA;AAC7C,CAAC,CAAA;AAfU,QAAA,YAAY,gBAetB"}
|
package/lib/commons.ts
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import { PackageJson } from 'type-fest'
|
|
2
|
-
import {
|
|
2
|
+
import { readFile, writeFile } from 'fs/promises'
|
|
3
|
+
import {
|
|
4
|
+
Callable,
|
|
5
|
+
PinionContext,
|
|
6
|
+
loadJSON,
|
|
7
|
+
fromFile,
|
|
8
|
+
getCallable,
|
|
9
|
+
renderTemplate,
|
|
10
|
+
inject,
|
|
11
|
+
Location
|
|
12
|
+
} from '@feathershq/pinion'
|
|
3
13
|
import * as ts from 'typescript'
|
|
4
|
-
import prettier from 'prettier'
|
|
14
|
+
import prettier, { Options as PrettierOptions } from 'prettier'
|
|
5
15
|
import path from 'path'
|
|
6
16
|
|
|
7
17
|
export type DependencyVersions = { [key: string]: string }
|
|
@@ -135,53 +145,104 @@ export const getJavaScript = (typescript: string, options: ts.TranspileOptions =
|
|
|
135
145
|
...options.compilerOptions
|
|
136
146
|
}
|
|
137
147
|
})
|
|
138
|
-
const code = fixLocalImports(restoreNewLines(transpiled.outputText))
|
|
139
148
|
|
|
140
|
-
return
|
|
141
|
-
semi: false,
|
|
142
|
-
parser: 'babel',
|
|
143
|
-
singleQuote: true
|
|
144
|
-
})
|
|
149
|
+
return fixLocalImports(restoreNewLines(transpiled.outputText))
|
|
145
150
|
}
|
|
146
151
|
|
|
152
|
+
const getFileName = async <C extends PinionContext & { language: 'js' | 'ts' }>(
|
|
153
|
+
target: Callable<string, C>,
|
|
154
|
+
ctx: C
|
|
155
|
+
) => `${await getCallable(target, ctx)}.${ctx.language}`
|
|
156
|
+
|
|
147
157
|
/**
|
|
148
|
-
*
|
|
149
|
-
|
|
158
|
+
* The default configuration for prettifying files
|
|
159
|
+
*/
|
|
160
|
+
export const PRETTIERRC: PrettierOptions = {
|
|
161
|
+
tabWidth: 2,
|
|
162
|
+
useTabs: false,
|
|
163
|
+
printWidth: 110,
|
|
164
|
+
semi: false,
|
|
165
|
+
trailingComma: 'none',
|
|
166
|
+
singleQuote: true
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/*
|
|
170
|
+
* Format a source file using Prettier. Will use the local configuration, the settings set in
|
|
171
|
+
* `options` or a default configuration
|
|
172
|
+
*
|
|
173
|
+
* @param target The file to prettify
|
|
174
|
+
* @param options The Prettier options
|
|
175
|
+
* @returns The updated context
|
|
176
|
+
*/
|
|
177
|
+
export const prettify =
|
|
178
|
+
<C extends PinionContext & { language: 'js' | 'ts' }>(
|
|
179
|
+
target: Callable<string, C>,
|
|
180
|
+
options: PrettierOptions = PRETTIERRC
|
|
181
|
+
) =>
|
|
182
|
+
async (ctx: C) => {
|
|
183
|
+
const fileName = await getFileName(target, ctx)
|
|
184
|
+
const config = (await prettier.resolveConfig(ctx.cwd)) || options
|
|
185
|
+
const content = (await readFile(fileName)).toString()
|
|
186
|
+
|
|
187
|
+
try {
|
|
188
|
+
await writeFile(
|
|
189
|
+
fileName,
|
|
190
|
+
await prettier.format(content, {
|
|
191
|
+
parser: ctx.language === 'ts' ? 'typescript' : 'babel',
|
|
192
|
+
...config
|
|
193
|
+
})
|
|
194
|
+
)
|
|
195
|
+
} catch (error: any) {
|
|
196
|
+
throw new Error(`Error prettifying ${fileName}: ${error.message}`)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return ctx
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Render a source file template for the language set in the context.
|
|
150
204
|
*
|
|
151
205
|
* @param templates The JavaScript and TypeScript template to render
|
|
152
|
-
* @param
|
|
206
|
+
* @param target The target filename without extension (will be added based on language)
|
|
153
207
|
* @returns The updated context
|
|
154
208
|
*/
|
|
155
209
|
export const renderSource =
|
|
156
210
|
<C extends PinionContext & { language: 'js' | 'ts' }>(
|
|
157
211
|
template: Callable<string, C>,
|
|
158
|
-
|
|
212
|
+
target: Callable<string, C>,
|
|
159
213
|
options?: { force: boolean }
|
|
160
214
|
) =>
|
|
161
215
|
async (ctx: C) => {
|
|
162
|
-
if (!template) {
|
|
163
|
-
return ctx
|
|
164
|
-
}
|
|
165
|
-
|
|
166
216
|
const { language } = ctx
|
|
167
|
-
const fileName = await
|
|
217
|
+
const fileName = await getFileName(target, ctx)
|
|
168
218
|
const content = language === 'js' ? getJavaScript(await getCallable<string, C>(template, ctx)) : template
|
|
169
|
-
const renderer = renderTemplate(content,
|
|
219
|
+
const renderer = renderTemplate(content, fileName, options)
|
|
170
220
|
|
|
171
|
-
return renderer(ctx)
|
|
221
|
+
return renderer(ctx).then(prettify(target))
|
|
172
222
|
}
|
|
173
223
|
|
|
174
224
|
/**
|
|
175
|
-
*
|
|
225
|
+
* Inject a source template as the language set in the context.
|
|
176
226
|
*
|
|
177
|
-
* @param template The source template
|
|
227
|
+
* @param template The source template to render
|
|
228
|
+
* @param location The location to inject the code to. Must use the target language.
|
|
229
|
+
* @param target The target file name
|
|
230
|
+
* @param transpile Set to `false` if the code should not be transpiled to JavaScript
|
|
178
231
|
* @returns
|
|
179
232
|
*/
|
|
180
|
-
export const
|
|
181
|
-
<C extends PinionContext & { language: 'js' | 'ts' }>(
|
|
182
|
-
|
|
233
|
+
export const injectSource =
|
|
234
|
+
<C extends PinionContext & { language: 'js' | 'ts' }>(
|
|
235
|
+
template: Callable<string, C>,
|
|
236
|
+
location: Location<C>,
|
|
237
|
+
target: Callable<string, C>,
|
|
238
|
+
transpile = true
|
|
239
|
+
) =>
|
|
240
|
+
async (ctx: C) => {
|
|
183
241
|
const { language } = ctx
|
|
184
|
-
const source =
|
|
242
|
+
const source =
|
|
243
|
+
language === 'js' && transpile ? getJavaScript(await getCallable<string, C>(template, ctx)) : template
|
|
244
|
+
const fileName = await getFileName(target, ctx)
|
|
245
|
+
const injector = inject(source, location, fileName)
|
|
185
246
|
|
|
186
|
-
return
|
|
247
|
+
return injector(ctx).then(prettify(target))
|
|
187
248
|
}
|
|
@@ -17,7 +17,7 @@ export const ${database} = (app: Application) => {
|
|
|
17
17
|
const config = app.get('${database}')
|
|
18
18
|
const db = knex(config!)
|
|
19
19
|
|
|
20
|
-
app.set('${database}Client', db)
|
|
20
|
+
app.set('${database}Client', db)
|
|
21
21
|
}
|
|
22
22
|
`;
|
|
23
23
|
const knexfile = ({ lib, language, database }) => `
|
|
@@ -28,16 +28,17 @@ const config = app.get('${database}')
|
|
|
28
28
|
|
|
29
29
|
${language === 'js' ? 'export default config' : 'module.exports = config'}
|
|
30
30
|
`;
|
|
31
|
-
const configurationTemplate = ({ database }) =>
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
const configurationTemplate = ({ database }) => `${database}: {
|
|
32
|
+
type: 'object',
|
|
33
|
+
properties: {
|
|
34
|
+
client: { type: 'string' },
|
|
35
|
+
connection: { type: 'string' }
|
|
36
|
+
}
|
|
37
|
+
},`;
|
|
38
38
|
const importTemplate = ({ database }) => `import { ${database} } from './${database}'`;
|
|
39
39
|
const configureTemplate = ({ database }) => `app.configure(${database})`;
|
|
40
|
-
const toAppFile = (0, pinion_1.toFile)(({ lib
|
|
40
|
+
const toAppFile = (0, pinion_1.toFile)(({ lib }) => [lib, 'app']);
|
|
41
|
+
const toConfig = (0, pinion_1.toFile)(({ lib }) => [lib, 'configuration']);
|
|
41
42
|
const generate = (ctx) => (0, pinion_1.generator)(ctx)
|
|
42
43
|
.then((0, commons_1.renderSource)(template, (0, pinion_1.toFile)(({ lib, database }) => [lib, database])))
|
|
43
44
|
.then((0, commons_1.renderSource)(knexfile, (0, pinion_1.toFile)('knexfile')))
|
|
@@ -48,12 +49,8 @@ const generate = (ctx) => (0, pinion_1.generator)(ctx)
|
|
|
48
49
|
test: 'cross-env NODE_ENV=test npm run migrate && npm run mocha'
|
|
49
50
|
}
|
|
50
51
|
}, (0, pinion_1.toFile)('package.json')))
|
|
51
|
-
.then((0,
|
|
52
|
-
|
|
53
|
-
'
|
|
54
|
-
`configuration.schema.${language}`
|
|
55
|
-
])))
|
|
56
|
-
.then((0, pinion_1.inject)((0, commons_1.getSource)(importTemplate), (0, pinion_1.before)('import { services } from'), toAppFile))
|
|
57
|
-
.then((0, pinion_1.inject)((0, commons_1.getSource)(configureTemplate), (0, pinion_1.before)('app.configure(services)'), toAppFile));
|
|
52
|
+
.then((0, commons_1.injectSource)(configurationTemplate, (0, pinion_1.before)('authentication: authenticationSettingsSchema'), toConfig, false))
|
|
53
|
+
.then((0, commons_1.injectSource)(importTemplate, (0, pinion_1.before)('import { services } from'), toAppFile))
|
|
54
|
+
.then((0, commons_1.injectSource)(configureTemplate, (0, pinion_1.before)('app.configure(services)'), toAppFile));
|
|
58
55
|
exports.generate = generate;
|
|
59
56
|
//# sourceMappingURL=knex.tpl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"knex.tpl.js","sourceRoot":"","sources":["../../../src/connection/templates/knex.tpl.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"knex.tpl.js","sourceRoot":"","sources":["../../../src/connection/templates/knex.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAyE;AAEzE,2CAA0D;AAE1D,MAAM,QAAQ,G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AM,EAAC,UAAU,CAAC,CAAC,CAAC;KAChD,IAAI,CACH,IAAA,kBAAS,EACP;IACE,OAAO,EAAE;QACP,OAAO,EAAE,qBAAqB;QAC9B,cAAc,EAAE,mBAAmB;QACnC,IAAI,EAAE,0DAA0D;KACjE;CACF,EACD,IAAA,eAAM,EAAC,cAAc,CAAC,CACvB,CACF;KACA,IAAI,CACH,IAAA,sBAAY,EACV,qBAAqB,EACrB,IAAA,eAAM,EAAC,8CAA8C,CAAC,EACtD,QAAQ,EACR,KAAK,CACN,CACF;KACA,IAAI,CAAC,IAAA,sBAAY,EAAC,cAAc,EAAE,IAAA,eAAM,EAAC,0BAA0B,CAAC,EAAE,SAAS,CAAC,CAAC;KACjF,IAAI,CAAC,IAAA,sBAAY,EAAC,iBAAiB,EAAE,IAAA,eAAM,EAAC,yBAAyB,CAAC,EAAE,SAAS,CAAC,CAAC,CAAA;AA9B3E,QAAA,QAAQ,YA8BmE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { generator, toFile,
|
|
1
|
+
import { generator, toFile, before, mergeJSON } from '@feathershq/pinion'
|
|
2
2
|
import { ConnectionGeneratorContext } from '../index'
|
|
3
|
-
import {
|
|
3
|
+
import { injectSource, renderSource } from '../../commons'
|
|
4
4
|
|
|
5
5
|
const template = ({ database }: ConnectionGeneratorContext) =>
|
|
6
6
|
`import knex from 'knex'
|
|
@@ -17,7 +17,7 @@ export const ${database} = (app: Application) => {
|
|
|
17
17
|
const config = app.get('${database}')
|
|
18
18
|
const db = knex(config!)
|
|
19
19
|
|
|
20
|
-
app.set('${database}Client', db)
|
|
20
|
+
app.set('${database}Client', db)
|
|
21
21
|
}
|
|
22
22
|
`
|
|
23
23
|
|
|
@@ -30,18 +30,19 @@ const config = app.get('${database}')
|
|
|
30
30
|
${language === 'js' ? 'export default config' : 'module.exports = config'}
|
|
31
31
|
`
|
|
32
32
|
|
|
33
|
-
const configurationTemplate = ({ database }: ConnectionGeneratorContext) =>
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
const configurationTemplate = ({ database }: ConnectionGeneratorContext) => `${database}: {
|
|
34
|
+
type: 'object',
|
|
35
|
+
properties: {
|
|
36
|
+
client: { type: 'string' },
|
|
37
|
+
connection: { type: 'string' }
|
|
38
|
+
}
|
|
39
|
+
},`
|
|
41
40
|
const importTemplate = ({ database }: ConnectionGeneratorContext) =>
|
|
42
41
|
`import { ${database} } from './${database}'`
|
|
43
42
|
const configureTemplate = ({ database }: ConnectionGeneratorContext) => `app.configure(${database})`
|
|
44
|
-
|
|
43
|
+
|
|
44
|
+
const toAppFile = toFile<ConnectionGeneratorContext>(({ lib }) => [lib, 'app'])
|
|
45
|
+
const toConfig = toFile<ConnectionGeneratorContext>(({ lib }) => [lib, 'configuration'])
|
|
45
46
|
|
|
46
47
|
export const generate = (ctx: ConnectionGeneratorContext) =>
|
|
47
48
|
generator(ctx)
|
|
@@ -65,15 +66,12 @@ export const generate = (ctx: ConnectionGeneratorContext) =>
|
|
|
65
66
|
)
|
|
66
67
|
)
|
|
67
68
|
.then(
|
|
68
|
-
|
|
69
|
+
injectSource(
|
|
69
70
|
configurationTemplate,
|
|
70
71
|
before('authentication: authenticationSettingsSchema'),
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
'schemas',
|
|
74
|
-
`configuration.schema.${language}`
|
|
75
|
-
])
|
|
72
|
+
toConfig,
|
|
73
|
+
false
|
|
76
74
|
)
|
|
77
75
|
)
|
|
78
|
-
.then(
|
|
79
|
-
.then(
|
|
76
|
+
.then(injectSource(importTemplate, before('import { services } from'), toAppFile))
|
|
77
|
+
.then(injectSource(configureTemplate, before('app.configure(services)'), toAppFile))
|
|
@@ -22,18 +22,14 @@ export const mongodb = (app: Application) => {
|
|
|
22
22
|
app.set('mongodbClient', mongoClient)
|
|
23
23
|
}
|
|
24
24
|
`;
|
|
25
|
-
const configurationTemplate = ({ database }) => `
|
|
25
|
+
const configurationTemplate = ({ database }) => ` ${database}: { type: 'string' },`;
|
|
26
26
|
const importTemplate = "import { mongodb } from './mongodb'";
|
|
27
27
|
const configureTemplate = 'app.configure(mongodb)';
|
|
28
|
-
const toAppFile = (0, pinion_1.toFile)(({ lib
|
|
28
|
+
const toAppFile = (0, pinion_1.toFile)(({ lib }) => [lib, 'app']);
|
|
29
29
|
const generate = (ctx) => (0, pinion_1.generator)(ctx)
|
|
30
30
|
.then((0, commons_1.renderSource)(template, (0, pinion_1.toFile)(({ lib }) => lib, 'mongodb')))
|
|
31
|
-
.then((0,
|
|
32
|
-
|
|
33
|
-
'
|
|
34
|
-
`configuration.schema.${language}`
|
|
35
|
-
])))
|
|
36
|
-
.then((0, pinion_1.inject)((0, commons_1.getSource)(importTemplate), (0, pinion_1.before)('import { services } from'), toAppFile))
|
|
37
|
-
.then((0, pinion_1.inject)((0, commons_1.getSource)(configureTemplate), (0, pinion_1.before)('app.configure(services)'), toAppFile));
|
|
31
|
+
.then((0, commons_1.injectSource)(configurationTemplate, (0, pinion_1.before)('authentication: authenticationSettingsSchema'), (0, pinion_1.toFile)(({ lib }) => [lib, 'configuration']), false))
|
|
32
|
+
.then((0, commons_1.injectSource)(importTemplate, (0, pinion_1.before)('import { services } from'), toAppFile))
|
|
33
|
+
.then((0, commons_1.injectSource)(configureTemplate, (0, pinion_1.before)('app.configure(services)'), toAppFile));
|
|
38
34
|
exports.generate = generate;
|
|
39
35
|
//# sourceMappingURL=mongodb.tpl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongodb.tpl.js","sourceRoot":"","sources":["../../../src/connection/templates/mongodb.tpl.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"mongodb.tpl.js","sourceRoot":"","sources":["../../../src/connection/templates/mongodb.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA8D;AAE9D,2CAA0D;AAE1D,MAAM,QAAQ,GAAG,CAAC,EAA8B,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