vovk-cli 0.0.1-draft.163 → 0.0.1-draft.164
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.
|
@@ -2,7 +2,6 @@ import path from 'node:path';
|
|
|
2
2
|
import { glob } from 'glob';
|
|
3
3
|
import resolveAbsoluteModulePath from '../utils/resolveAbsoluteModulePath.mjs';
|
|
4
4
|
import getFileSystemEntryType, { FileSystemEntryType } from '../utils/getFileSystemEntryType.mjs';
|
|
5
|
-
import { checkIfInstalled } from '../utils/checkIfInstalled.mjs';
|
|
6
5
|
export default async function getClientTemplateFiles({ config, cwd, log, configKey, cliGenerateOptions, }) {
|
|
7
6
|
const usedTemplateDefs = {};
|
|
8
7
|
const fromTemplates = configKey === 'fullClient'
|
|
@@ -23,30 +22,22 @@ export default async function getClientTemplateFiles({ config, cwd, log, configK
|
|
|
23
22
|
}
|
|
24
23
|
const templateFiles = [];
|
|
25
24
|
const entries = Object.entries(usedTemplateDefs);
|
|
26
|
-
for (const [templateName, templateDef] of entries) {
|
|
27
|
-
if (templateDef.templatePath &&
|
|
28
|
-
!templateDef.templatePath.startsWith('.') &&
|
|
29
|
-
!templateDef.templatePath.startsWith('/')) {
|
|
30
|
-
const pathParts = templateDef.templatePath.split('/');
|
|
31
|
-
const npmModuleName = pathParts[0].startsWith('@') ? `${pathParts[0]}/${pathParts[1]}` : pathParts[0];
|
|
32
|
-
const isInstalled = checkIfInstalled(npmModuleName);
|
|
33
|
-
if (!isInstalled) {
|
|
34
|
-
log.error(`Template "${templateName}" requires the package "${npmModuleName}" to be installed.`);
|
|
35
|
-
return {
|
|
36
|
-
fromTemplates: [],
|
|
37
|
-
templateFiles: [],
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
25
|
for (let i = 0; i < entries.length; i++) {
|
|
43
26
|
const [templateName, templateDef, forceOutCwdRelativeDir] = entries[i];
|
|
44
27
|
const templateAbsolutePath = templateDef.templatePath
|
|
45
28
|
? resolveAbsoluteModulePath(templateDef.templatePath, cwd)
|
|
46
29
|
: null;
|
|
47
30
|
const entryType = templateAbsolutePath ? await getFileSystemEntryType(templateAbsolutePath) : null;
|
|
48
|
-
if (templateAbsolutePath && !entryType)
|
|
49
|
-
|
|
31
|
+
if (templateAbsolutePath && !entryType) {
|
|
32
|
+
if (templateDef.templatePath &&
|
|
33
|
+
!templateDef.templatePath.startsWith('.') &&
|
|
34
|
+
!templateDef.templatePath.startsWith('/')) {
|
|
35
|
+
const pathParts = templateDef.templatePath.split('/');
|
|
36
|
+
const npmModuleName = pathParts[0].startsWith('@') ? `${pathParts[0]}/${pathParts[1]}` : pathParts[0];
|
|
37
|
+
throw new Error(`Unable to locate template path "${templateDef.templatePath}" resolved as "${templateAbsolutePath}". You may need to install the package "${npmModuleName}" first.`);
|
|
38
|
+
}
|
|
39
|
+
throw new Error(`Unable to locate template path "${templateDef.templatePath}" resolved as "${templateAbsolutePath}"`);
|
|
40
|
+
}
|
|
50
41
|
const defOutDir = configKey === 'fullClient' ? templateDef.fullClient?.outDir : templateDef.segmentedClient?.outDir;
|
|
51
42
|
let files = [];
|
|
52
43
|
if (templateAbsolutePath) {
|
|
@@ -62,8 +62,8 @@ export default async function getConfig({ cliGenerateOptions, cliBundleOptions,
|
|
|
62
62
|
prettifyClient: (env.VOVK_PRETTIFY_CLIENT ? !!env.VOVK_PRETTIFY_CLIENT : null) ?? conf.prettifyClient ?? false,
|
|
63
63
|
devHttps: (env.VOVK_DEV_HTTPS ? !!env.VOVK_DEV_HTTPS : null) ?? conf.devHttps ?? false,
|
|
64
64
|
moduleTemplates: {
|
|
65
|
-
service: 'vovk-cli/templates/service.ts.ejs',
|
|
66
|
-
controller: 'vovk-cli/templates/controller.ts.ejs',
|
|
65
|
+
service: 'vovk-cli/module-templates/service.ts.ejs',
|
|
66
|
+
controller: 'vovk-cli/module-templates/controller.ts.ejs',
|
|
67
67
|
...conf.moduleTemplates,
|
|
68
68
|
},
|
|
69
69
|
libs: conf.libs ?? {},
|
package/dist/new/newSegment.mjs
CHANGED
|
@@ -24,7 +24,7 @@ ${isStaticSegment
|
|
|
24
24
|
return generateStaticAPI(controllers);
|
|
25
25
|
}`
|
|
26
26
|
: ''}
|
|
27
|
-
export const { GET, POST, PATCH, PUT, HEAD, OPTIONS, DELETE } = initVovk({
|
|
27
|
+
export const { GET${isStaticSegment ? '' : ', POST, PATCH, PUT, HEAD, OPTIONS, DELETE'} } = initVovk({
|
|
28
28
|
${segmentName ? ` segmentName: '${segmentName}',\n` : ''} emitSchema: true,
|
|
29
29
|
controllers,
|
|
30
30
|
});
|
package/package.json
CHANGED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if a package is installed and available to be imported
|
|
3
|
-
* @param packageName The name of the package to check
|
|
4
|
-
* @returns A boolean indicating if the package is installed
|
|
5
|
-
*/
|
|
6
|
-
export declare function checkIfInstalled(packageName: string): Promise<boolean>;
|
|
7
|
-
/**
|
|
8
|
-
* Synchronous version of checkIfInstalled
|
|
9
|
-
* @param packageName The name of the package to check
|
|
10
|
-
* @returns A boolean indicating if the package is installed
|
|
11
|
-
*/
|
|
12
|
-
export declare function checkIfInstalledSync(packageName: string): boolean;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';
|
|
2
|
-
/**
|
|
3
|
-
* Checks if a package is installed and available to be imported
|
|
4
|
-
* @param packageName The name of the package to check
|
|
5
|
-
* @returns A boolean indicating if the package is installed
|
|
6
|
-
*/
|
|
7
|
-
export async function checkIfInstalled(packageName) {
|
|
8
|
-
try {
|
|
9
|
-
// Create a require function that works in ESM
|
|
10
|
-
const require = createRequire(import.meta.url);
|
|
11
|
-
require.resolve(packageName);
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
catch {
|
|
15
|
-
// If an error is thrown, the package is not installed or cannot be resolved
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Synchronous version of checkIfInstalled
|
|
21
|
-
* @param packageName The name of the package to check
|
|
22
|
-
* @returns A boolean indicating if the package is installed
|
|
23
|
-
*/
|
|
24
|
-
export function checkIfInstalledSync(packageName) {
|
|
25
|
-
try {
|
|
26
|
-
const require = createRequire(import.meta.url);
|
|
27
|
-
require.resolve(packageName);
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
}
|