@cparra/apexdocs 2.19.0-alpha.3 → 2.19.0-alpha.4
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/apexdocs.config.ts +5 -11
- package/lib/application/Apexdocs.js +4 -4
- package/lib/application/Apexdocs.js.map +1 -1
- package/lib/service/file-writer.d.ts +2 -2
- package/lib/service/file-writer.js +16 -11
- package/lib/service/file-writer.js.map +1 -1
- package/lib/settings.d.ts +10 -17
- package/lib/settings.js +3 -5
- package/lib/settings.js.map +1 -1
- package/package.json +1 -1
- package/src/application/Apexdocs.ts +6 -6
- package/src/service/file-writer.ts +17 -15
- package/src/settings.ts +13 -9
package/apexdocs.config.ts
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
type OutputDir = {
|
|
4
|
-
baseDir: string;
|
|
5
|
-
fileDir: string;
|
|
6
|
-
};
|
|
1
|
+
import { TargetFile } from './src/settings';
|
|
7
2
|
|
|
8
3
|
export default {
|
|
9
|
-
onBeforeFileWrite: (
|
|
10
|
-
console.log('onBefore writing',
|
|
11
|
-
|
|
12
|
-
return { dir: defaultDir, fileName };
|
|
4
|
+
onBeforeFileWrite: (file: TargetFile): TargetFile => {
|
|
5
|
+
console.log('onBefore writing', file);
|
|
6
|
+
return file;
|
|
13
7
|
},
|
|
14
|
-
onAfterProcess: (files:
|
|
8
|
+
onAfterProcess: (files: TargetFile[]) => {
|
|
15
9
|
console.log('onAfterProcess files', files);
|
|
16
10
|
},
|
|
17
11
|
};
|
|
@@ -30,12 +30,12 @@ class Apexdocs {
|
|
|
30
30
|
const processor = factory_1.TypeTranspilerFactory.get(settings_1.Settings.getInstance().targetGenerator);
|
|
31
31
|
transpiler_1.default.generate(filteredTypes, processor);
|
|
32
32
|
const generatedFiles = processor.fileBuilder().files();
|
|
33
|
-
const
|
|
33
|
+
const files = [];
|
|
34
34
|
file_writer_1.FileWriter.write(generatedFiles, (file) => {
|
|
35
|
-
logger_1.Logger.logSingle(`${file.
|
|
36
|
-
|
|
35
|
+
logger_1.Logger.logSingle(`${file.name} processed.`, false, 'green', false);
|
|
36
|
+
files.push(file);
|
|
37
37
|
});
|
|
38
|
-
settings_1.Settings.getInstance().onAfterProcess(
|
|
38
|
+
settings_1.Settings.getInstance().onAfterProcess(files);
|
|
39
39
|
// Error logging
|
|
40
40
|
error_logger_1.default.logErrors(filteredTypes);
|
|
41
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Apexdocs.js","sourceRoot":"","sources":["../../src/application/Apexdocs.ts"],"names":[],"mappings":";;;AAAA,kEAA6D;AAC7D,wDAA2D;AAC3D,6DAA0E;AAC1E,2CAAwC;AACxC,kEAA6D;AAC7D,8CAAkD;AAClD,
|
|
1
|
+
{"version":3,"file":"Apexdocs.js","sourceRoot":"","sources":["../../src/application/Apexdocs.ts"],"names":[],"mappings":";;;AAAA,kEAA6D;AAC7D,wDAA2D;AAC3D,6DAA0E;AAC1E,2CAAwC;AACxC,kEAA6D;AAC7D,8CAAkD;AAClD,0CAAmD;AACnD,yDAAkD;AAClD,wDAAoD;AACpD,uDAA+C;AAG/C,gEAA4D;AAC5D,mDAA8D;AAE9D;;GAEG;AACH,MAAa,QAAQ;IACnB;;OAEG;IACH,MAAM,CAAC,QAAQ;QACb,eAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QAC9B,MAAM,UAAU,GAAG,iCAAc,CAAC,YAAY,CAAC,IAAI,+BAAiB,EAAE,CAAC,CAAC;QACxE,MAAM,QAAQ,GAAG,IAAA,iCAAc,EAAC,IAAI,sBAAa,CAAC,UAAU,CAAC,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAC;QAC3F,kCAAe,CAAC,WAAW,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC1D,MAAM,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;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AAC;gBAC9D,cAAc;gBACd,YAAY;gBACZ,SAAS;gBACT,WAAW;gBACX,UAAU;gBACV,SAAS;aACV,CAAC,CAAC;YACH,kBAAkB,GAAG,YACnB,QAAQ,CAAC,KAAK,CAAC,MAAM,GAAG,aAAa,CAAC,MACxC,4DAA4D,CAAC;SAC9D;QACD,eAAM,CAAC,KAAK,EAAE,CAAC;QAEf,eAAM,CAAC,SAAS,CAAC,kBAAkB,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QAC5D,eAAM,CAAC,SAAS,CAAC,8BAA8B,aAAa,CAAC,MAAM,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QACtG,OAAO,aAAa,CAAC;IACvB,CAAC;;AAvDH,4BAgEC;AAPQ,8BAAqB,GAAG,CAAC,UAAsB,EAAoB,EAAE;;IAC1E,MAAM,MAAM,GAAG,IAAA,yBAAO,EAAC,UAAU,CAAC,cAAc,CAAC,CAAC;IAClD,IAAI,MAAM,CAAC,KAAK,EAAE;QAChB,eAAM,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC,QAAQ,oBAAoB,MAAA,MAAM,CAAC,KAAK,0CAAE,OAAO,EAAE,CAAC,CAAC;KACjF;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OutputFile } from '../model/outputFile';
|
|
2
|
-
import {
|
|
2
|
+
import { TargetFile } from '../settings';
|
|
3
3
|
export declare class FileWriter {
|
|
4
|
-
static write(files: OutputFile[], onWriteCallback: (file:
|
|
4
|
+
static write(files: OutputFile[], onWriteCallback: (file: TargetFile) => void): void;
|
|
5
5
|
private static getTargetLocation;
|
|
6
6
|
}
|
|
@@ -6,23 +6,28 @@ const path = require("path");
|
|
|
6
6
|
const settings_1 = require("../settings");
|
|
7
7
|
class FileWriter {
|
|
8
8
|
static write(files, onWriteCallback) {
|
|
9
|
-
const onBeforeFileWrite = (
|
|
9
|
+
const onBeforeFileWrite = (file) => settings_1.Settings.getInstance().onBeforeFileWrite(file);
|
|
10
10
|
files.forEach((file) => {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const resolvedFile = this.getTargetLocation(file, onBeforeFileWrite);
|
|
12
|
+
const fullDir = path.join(resolvedFile.dir.baseDir, resolvedFile.dir.fileDir);
|
|
13
|
+
if (!fs.existsSync(fullDir)) {
|
|
14
|
+
fs.mkdirSync(fullDir, { recursive: true });
|
|
14
15
|
}
|
|
15
|
-
const filePath = path.join(
|
|
16
|
+
const filePath = path.join(fullDir, `${resolvedFile.name}${resolvedFile.extension}`);
|
|
16
17
|
fs.writeFileSync(filePath, file.body, 'utf8');
|
|
17
|
-
onWriteCallback(
|
|
18
|
+
onWriteCallback(resolvedFile);
|
|
18
19
|
});
|
|
19
20
|
}
|
|
20
21
|
static getTargetLocation(file, onBeforeFileWrite) {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
const targetFile = {
|
|
23
|
+
name: file.fileName,
|
|
24
|
+
extension: file.fileExtension(),
|
|
25
|
+
dir: {
|
|
26
|
+
baseDir: settings_1.Settings.getInstance().outputDir,
|
|
27
|
+
fileDir: file.dir,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
return onBeforeFileWrite(targetFile);
|
|
26
31
|
}
|
|
27
32
|
}
|
|
28
33
|
exports.FileWriter = FileWriter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-writer.js","sourceRoot":"","sources":["../../src/service/file-writer.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AACzB,6BAA6B;AAE7B,
|
|
1
|
+
{"version":3,"file":"file-writer.js","sourceRoot":"","sources":["../../src/service/file-writer.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AACzB,6BAA6B;AAE7B,0CAAsE;AAEtE,MAAa,UAAU;IACrB,MAAM,CAAC,KAAK,CAAC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ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { GeneratorChoices } from './transpiler/generator-choices';
|
|
2
|
-
export type OnBeforeFileWrite = (
|
|
2
|
+
export type OnBeforeFileWrite = (file: TargetFile) => TargetFile;
|
|
3
|
+
export type TargetFile = {
|
|
4
|
+
name: string;
|
|
5
|
+
extension: string;
|
|
6
|
+
dir: OutputDir;
|
|
7
|
+
};
|
|
3
8
|
export type TargetLocation = {
|
|
4
9
|
dir: string;
|
|
5
10
|
fileName: string;
|
|
@@ -23,14 +28,8 @@ export interface SettingsConfig {
|
|
|
23
28
|
openApiFileName: string;
|
|
24
29
|
includeMetadata: boolean;
|
|
25
30
|
rootDir?: string;
|
|
26
|
-
onAfterProcess?: (files:
|
|
27
|
-
|
|
28
|
-
fileName: string;
|
|
29
|
-
}[]) => void;
|
|
30
|
-
onBeforeFileWrite?: (outputDir: OutputDir, fileName: string) => {
|
|
31
|
-
dir: string;
|
|
32
|
-
fileName: string;
|
|
33
|
-
};
|
|
31
|
+
onAfterProcess?: (files: TargetFile[]) => void;
|
|
32
|
+
onBeforeFileWrite?: (file: TargetFile) => TargetFile;
|
|
34
33
|
}
|
|
35
34
|
export declare class Settings {
|
|
36
35
|
config: SettingsConfig;
|
|
@@ -53,12 +52,6 @@ export declare class Settings {
|
|
|
53
52
|
openApiFileName(): string;
|
|
54
53
|
includeMetadata(): boolean;
|
|
55
54
|
getRootDir(): string | undefined;
|
|
56
|
-
onAfterProcess(files:
|
|
57
|
-
|
|
58
|
-
fileName: string;
|
|
59
|
-
}[]): void;
|
|
60
|
-
onBeforeFileWrite(outputDir: OutputDir, fileName: string): {
|
|
61
|
-
dir: string;
|
|
62
|
-
fileName: string;
|
|
63
|
-
};
|
|
55
|
+
onAfterProcess(files: TargetFile[]): void;
|
|
56
|
+
onBeforeFileWrite(file: TargetFile): TargetFile;
|
|
64
57
|
}
|
package/lib/settings.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Settings = void 0;
|
|
4
|
-
const path = require("path");
|
|
5
4
|
class Settings {
|
|
6
5
|
constructor(config) {
|
|
7
6
|
this.config = config;
|
|
@@ -69,12 +68,11 @@ class Settings {
|
|
|
69
68
|
this.config.onAfterProcess(files);
|
|
70
69
|
}
|
|
71
70
|
}
|
|
72
|
-
onBeforeFileWrite(
|
|
71
|
+
onBeforeFileWrite(file) {
|
|
73
72
|
if (this.config.onBeforeFileWrite) {
|
|
74
|
-
return this.config.onBeforeFileWrite(
|
|
73
|
+
return this.config.onBeforeFileWrite(file);
|
|
75
74
|
}
|
|
76
|
-
|
|
77
|
-
return { dir: defaultDir, fileName };
|
|
75
|
+
return file;
|
|
78
76
|
}
|
|
79
77
|
}
|
|
80
78
|
exports.Settings = Settings;
|
package/lib/settings.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":";;;AAuCA,MAAa,QAAQ;IAGnB,YAA2B,MAAsB;QAAtB,WAAM,GAAN,MAAM,CAAgB;IAAG,CAAC;IAE9C,MAAM,CAAC,KAAK,CAAC,MAAsB;QACxC,QAAQ,CAAC,QAAQ,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IAEM,MAAM,CAAC,WAAW;QACvB,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE;YACtB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;SACtD;QACD,OAAO,QAAQ,CAAC,QAAQ,CAAC;IAC3B,CAAC;IAED,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;IACrC,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,MAAM,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C,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;SACnC;IACH,CAAC;IAEM,iBAAiB,CAAC,IAAgB;QACvC,IAAI,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE;YACjC,OAAO,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;SAC5C;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA3FD,4BA2FC"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@ import { ReflectionResult, reflect, Type } from '@cparra/apex-reflection';
|
|
|
4
4
|
import { Logger } from '../util/logger';
|
|
5
5
|
import { createManifest } from '../service/manifest-factory';
|
|
6
6
|
import { RawBodyParser } from '../service/parser';
|
|
7
|
-
import { Settings } from '../settings';
|
|
7
|
+
import { Settings, TargetFile } from '../settings';
|
|
8
8
|
import Transpiler from '../transpiler/transpiler';
|
|
9
9
|
import { FileWriter } from '../service/file-writer';
|
|
10
10
|
import ErrorLogger from '../util/error-logger';
|
|
@@ -31,13 +31,13 @@ export class Apexdocs {
|
|
|
31
31
|
Transpiler.generate(filteredTypes, processor);
|
|
32
32
|
const generatedFiles = processor.fileBuilder().files();
|
|
33
33
|
|
|
34
|
-
const
|
|
35
|
-
FileWriter.write(generatedFiles, (file:
|
|
36
|
-
Logger.logSingle(`${file.
|
|
37
|
-
|
|
34
|
+
const files: TargetFile[] = [];
|
|
35
|
+
FileWriter.write(generatedFiles, (file: TargetFile) => {
|
|
36
|
+
Logger.logSingle(`${file.name} processed.`, false, 'green', false);
|
|
37
|
+
files.push(file);
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
-
Settings.getInstance().onAfterProcess(
|
|
40
|
+
Settings.getInstance().onAfterProcess(files);
|
|
41
41
|
|
|
42
42
|
// Error logging
|
|
43
43
|
ErrorLogger.logErrors(filteredTypes);
|
|
@@ -1,32 +1,34 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
import { OutputFile } from '../model/outputFile';
|
|
4
|
-
import { OnBeforeFileWrite,
|
|
4
|
+
import { OnBeforeFileWrite, Settings, TargetFile } from '../settings';
|
|
5
5
|
|
|
6
6
|
export class FileWriter {
|
|
7
|
-
static write(files: OutputFile[], onWriteCallback: (file:
|
|
8
|
-
const onBeforeFileWrite = (
|
|
9
|
-
Settings.getInstance().onBeforeFileWrite(outputDir, fileName);
|
|
7
|
+
static write(files: OutputFile[], onWriteCallback: (file: TargetFile) => void) {
|
|
8
|
+
const onBeforeFileWrite: OnBeforeFileWrite = (file: TargetFile) => Settings.getInstance().onBeforeFileWrite(file);
|
|
10
9
|
files.forEach((file) => {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const resolvedFile = this.getTargetLocation(file, onBeforeFileWrite);
|
|
11
|
+
const fullDir = path.join(resolvedFile.dir.baseDir, resolvedFile.dir.fileDir);
|
|
12
|
+
if (!fs.existsSync(fullDir)) {
|
|
13
|
+
fs.mkdirSync(fullDir, { recursive: true });
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
const filePath = path.join(
|
|
16
|
+
const filePath = path.join(fullDir, `${resolvedFile.name}${resolvedFile.extension}`);
|
|
17
17
|
fs.writeFileSync(filePath, file.body, 'utf8');
|
|
18
|
-
onWriteCallback(
|
|
18
|
+
onWriteCallback(resolvedFile);
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
private static getTargetLocation(file: OutputFile, onBeforeFileWrite: OnBeforeFileWrite):
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
private static getTargetLocation(file: OutputFile, onBeforeFileWrite: OnBeforeFileWrite): TargetFile {
|
|
23
|
+
const targetFile: TargetFile = {
|
|
24
|
+
name: file.fileName,
|
|
25
|
+
extension: file.fileExtension(),
|
|
26
|
+
dir: {
|
|
26
27
|
baseDir: Settings.getInstance().outputDir,
|
|
27
28
|
fileDir: file.dir,
|
|
28
29
|
},
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return onBeforeFileWrite(targetFile);
|
|
31
33
|
}
|
|
32
34
|
}
|
package/src/settings.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { GeneratorChoices } from './transpiler/generator-choices';
|
|
2
|
-
import * as path from 'path';
|
|
3
2
|
|
|
4
|
-
export type OnBeforeFileWrite = (
|
|
3
|
+
export type OnBeforeFileWrite = (file: TargetFile) => TargetFile;
|
|
4
|
+
|
|
5
|
+
export type TargetFile = {
|
|
6
|
+
name: string;
|
|
7
|
+
extension: string;
|
|
8
|
+
dir: OutputDir;
|
|
9
|
+
};
|
|
5
10
|
|
|
6
11
|
export type TargetLocation = {
|
|
7
12
|
dir: string;
|
|
@@ -28,8 +33,8 @@ export interface SettingsConfig {
|
|
|
28
33
|
openApiFileName: string;
|
|
29
34
|
includeMetadata: boolean;
|
|
30
35
|
rootDir?: string;
|
|
31
|
-
onAfterProcess?: (files:
|
|
32
|
-
onBeforeFileWrite?: (
|
|
36
|
+
onAfterProcess?: (files: TargetFile[]) => void;
|
|
37
|
+
onBeforeFileWrite?: (file: TargetFile) => TargetFile;
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
export class Settings {
|
|
@@ -111,17 +116,16 @@ export class Settings {
|
|
|
111
116
|
return this.config.rootDir;
|
|
112
117
|
}
|
|
113
118
|
|
|
114
|
-
public onAfterProcess(files:
|
|
119
|
+
public onAfterProcess(files: TargetFile[]): void {
|
|
115
120
|
if (this.config.onAfterProcess) {
|
|
116
121
|
this.config.onAfterProcess(files);
|
|
117
122
|
}
|
|
118
123
|
}
|
|
119
124
|
|
|
120
|
-
public onBeforeFileWrite(
|
|
125
|
+
public onBeforeFileWrite(file: TargetFile): TargetFile {
|
|
121
126
|
if (this.config.onBeforeFileWrite) {
|
|
122
|
-
return this.config.onBeforeFileWrite(
|
|
127
|
+
return this.config.onBeforeFileWrite(file);
|
|
123
128
|
}
|
|
124
|
-
|
|
125
|
-
return { dir: defaultDir, fileName };
|
|
129
|
+
return file;
|
|
126
130
|
}
|
|
127
131
|
}
|