type-crafter 0.1.0 → 0.1.1
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/dist/index.js +32 -12
- package/dist/utils/file-system.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import path$1 from 'path';
|
|
|
5
5
|
import require$$3 from 'fs';
|
|
6
6
|
import require$$4 from 'process';
|
|
7
7
|
import fs$1 from 'fs/promises';
|
|
8
|
+
import { fileURLToPath } from 'url';
|
|
8
9
|
|
|
9
10
|
function getDefaultExportFromCjs (x) {
|
|
10
11
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
@@ -19264,13 +19265,19 @@ var Runtime = {
|
|
|
19264
19265
|
compileTemplates
|
|
19265
19266
|
};
|
|
19266
19267
|
|
|
19267
|
-
function
|
|
19268
|
+
function getSourceFileDirectory() {
|
|
19269
|
+
const fileName = fileURLToPath(import.meta.url);
|
|
19270
|
+
return path$1.dirname(fileName);
|
|
19271
|
+
}
|
|
19272
|
+
function resolveFilePath(filePath, useCurrentDirectory = true) {
|
|
19268
19273
|
const isAbsolutePath = path$1.isAbsolute(filePath);
|
|
19269
|
-
const normalizedPath = isAbsolutePath
|
|
19274
|
+
const normalizedPath = isAbsolutePath
|
|
19275
|
+
? filePath
|
|
19276
|
+
: path$1.join(useCurrentDirectory ? process.cwd() : getSourceFileDirectory(), filePath);
|
|
19270
19277
|
return path$1.resolve(normalizedPath);
|
|
19271
19278
|
}
|
|
19272
|
-
async function readFile(filePath) {
|
|
19273
|
-
const data = await fs$1.readFile(resolveFilePath(filePath), 'utf-8');
|
|
19279
|
+
async function readFile(filePath, useCurrentWorkingDirectory = true) {
|
|
19280
|
+
const data = await fs$1.readFile(resolveFilePath(filePath, useCurrentWorkingDirectory), 'utf-8');
|
|
19274
19281
|
return data;
|
|
19275
19282
|
}
|
|
19276
19283
|
async function createFolderWithBasePath(basePath, folderName) {
|
|
@@ -19284,7 +19291,12 @@ async function createFolder(folderPath) {
|
|
|
19284
19291
|
await fs$1.mkdir(folderPath, { recursive: true });
|
|
19285
19292
|
}
|
|
19286
19293
|
async function deleteFolder(folderPath) {
|
|
19287
|
-
|
|
19294
|
+
try {
|
|
19295
|
+
await fs$1.rm(folderPath, { recursive: true });
|
|
19296
|
+
}
|
|
19297
|
+
catch (e) {
|
|
19298
|
+
console.log("Couldn't delete folder: ", folderPath);
|
|
19299
|
+
}
|
|
19288
19300
|
}
|
|
19289
19301
|
async function getCompleteFolderPath(folderName) {
|
|
19290
19302
|
const isAbsolutePath = path$1.isAbsolute(folderName);
|
|
@@ -19455,13 +19467,21 @@ function getReferenceName(reference) {
|
|
|
19455
19467
|
const referenceParts = reference.split('/');
|
|
19456
19468
|
return referenceParts[referenceParts.length - 1];
|
|
19457
19469
|
}
|
|
19470
|
+
function resolveAndGetReferenceName(reference) {
|
|
19471
|
+
resolveReference(reference);
|
|
19472
|
+
return getReferenceName(reference);
|
|
19473
|
+
}
|
|
19458
19474
|
function getLanguageDataType(dataType, format, items) {
|
|
19459
19475
|
const typeMapper = Runtime.getConfig().language.typeMapper ?? null;
|
|
19460
19476
|
const mappedType = typeMapper !== null ? typeMapper[dataType] : null;
|
|
19461
19477
|
const itemsType =
|
|
19462
19478
|
// eslint-disable-next-line
|
|
19463
|
-
items !== null
|
|
19464
|
-
?
|
|
19479
|
+
items !== null
|
|
19480
|
+
? items.type !== null
|
|
19481
|
+
? getLanguageDataType(items.type, items.format, items.items)
|
|
19482
|
+
: items.$ref !== null
|
|
19483
|
+
? resolveAndGetReferenceName(items.$ref)
|
|
19484
|
+
: null
|
|
19465
19485
|
: null;
|
|
19466
19486
|
const fillerPatterns = [];
|
|
19467
19487
|
if (itemsType !== null) {
|
|
@@ -19706,10 +19726,10 @@ async function writeOutput(generationResult) {
|
|
|
19706
19726
|
|
|
19707
19727
|
async function config(inputFilePath, outputDirectory, typesWriterMode, groupedTypesWriterMode) {
|
|
19708
19728
|
// PRODUCTION will be replaced with PRODUCTION when package is built.
|
|
19709
|
-
const directoryPrefix = 'PRODUCTION'.includes('DEVELOPMENT') ? 'src/' : '
|
|
19710
|
-
const objectSyntax = await readFile(directoryPrefix + 'templates/typescript/object-syntax.hbs');
|
|
19711
|
-
const exporterModuleSyntax = await readFile(directoryPrefix + 'templates/typescript/exporter-module-syntax.hbs');
|
|
19712
|
-
const typesFileSyntax = await readFile(directoryPrefix + 'templates/typescript/types-file-syntax.hbs');
|
|
19729
|
+
const directoryPrefix = 'PRODUCTION'.includes('DEVELOPMENT') ? 'src/' : './';
|
|
19730
|
+
const objectSyntax = await readFile(directoryPrefix + 'templates/typescript/object-syntax.hbs', false);
|
|
19731
|
+
const exporterModuleSyntax = await readFile(directoryPrefix + 'templates/typescript/exporter-module-syntax.hbs', false);
|
|
19732
|
+
const typesFileSyntax = await readFile(directoryPrefix + 'templates/typescript/types-file-syntax.hbs', false);
|
|
19713
19733
|
const config = {
|
|
19714
19734
|
input: inputFilePath,
|
|
19715
19735
|
output: {
|
|
@@ -19786,7 +19806,7 @@ async function runner(language, inputFilePath, outputDirectory, _typesWriterMode
|
|
|
19786
19806
|
}
|
|
19787
19807
|
}
|
|
19788
19808
|
greeting();
|
|
19789
|
-
const program = new Command().version('0.1.
|
|
19809
|
+
const program = new Command().version('0.1.1');
|
|
19790
19810
|
program
|
|
19791
19811
|
.command('generate')
|
|
19792
19812
|
.description('Generate types for your language from a type spec file')
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export declare function resolveFilePath(filePath: string): string;
|
|
2
|
-
export declare function readFile(filePath: string): Promise<string>;
|
|
1
|
+
export declare function resolveFilePath(filePath: string, useCurrentDirectory?: boolean): string;
|
|
2
|
+
export declare function readFile(filePath: string, useCurrentWorkingDirectory?: boolean): Promise<string>;
|
|
3
3
|
export declare function createFolderWithBasePath(basePath: string, folderName: string): Promise<void>;
|
|
4
4
|
export declare function createFolder(folderPath: string): Promise<void>;
|
|
5
5
|
export declare function deleteFolder(folderPath: string): Promise<void>;
|