@cparra/apexdocs 2.19.0-alpha.2 → 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 +6 -4
- package/lib/application/Apexdocs.js +4 -4
- package/lib/application/Apexdocs.js.map +1 -1
- package/lib/service/file-writer.d.ts +2 -6
- package/lib/service/file-writer.js +16 -9
- package/lib/service/file-writer.js.map +1 -1
- package/lib/settings.d.ts +18 -16
- package/lib/settings.js +3 -3
- 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 +20 -20
- package/src/settings.ts +24 -6
package/apexdocs.config.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { TargetFile } from './src/settings';
|
|
2
|
+
|
|
1
3
|
export default {
|
|
2
|
-
onBeforeFileWrite: (
|
|
3
|
-
console.log('onBefore writing',
|
|
4
|
-
return
|
|
4
|
+
onBeforeFileWrite: (file: TargetFile): TargetFile => {
|
|
5
|
+
console.log('onBefore writing', file);
|
|
6
|
+
return file;
|
|
5
7
|
},
|
|
6
|
-
onAfterProcess: (files:
|
|
8
|
+
onAfterProcess: (files: TargetFile[]) => {
|
|
7
9
|
console.log('onAfterProcess files', files);
|
|
8
10
|
},
|
|
9
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;QACpD,kCAAe,CAAC,WAAW,EAAE,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QAC5D,MAAM,SAAS,GAAG,+BAAqB,CAAC,GAAG,CAAC,mBAAQ,CAAC,WA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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,10 +1,6 @@
|
|
|
1
1
|
import { OutputFile } from '../model/outputFile';
|
|
2
|
+
import { TargetFile } from '../settings';
|
|
2
3
|
export declare class FileWriter {
|
|
3
|
-
static write(files: OutputFile[], onWriteCallback: (file:
|
|
4
|
+
static write(files: OutputFile[], onWriteCallback: (file: TargetFile) => void): void;
|
|
4
5
|
private static getTargetLocation;
|
|
5
6
|
}
|
|
6
|
-
type TargetLocation = {
|
|
7
|
-
dir: string;
|
|
8
|
-
fileName: string;
|
|
9
|
-
};
|
|
10
|
-
export {};
|
|
@@ -6,21 +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
|
-
|
|
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);
|
|
24
31
|
}
|
|
25
32
|
}
|
|
26
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,KAAmB,EAAE,eAA2C;QAC3E,MAAM,iBAAiB,GAAsB,CAAC,IAAgB,EAAE,EAAE,CAAC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
2
|
+
export type OnBeforeFileWrite = (file: TargetFile) => TargetFile;
|
|
3
|
+
export type TargetFile = {
|
|
4
|
+
name: string;
|
|
5
|
+
extension: string;
|
|
6
|
+
dir: OutputDir;
|
|
7
|
+
};
|
|
8
|
+
export type TargetLocation = {
|
|
9
|
+
dir: string;
|
|
10
|
+
fileName: string;
|
|
11
|
+
};
|
|
12
|
+
export type OutputDir = {
|
|
13
|
+
baseDir: string;
|
|
14
|
+
fileDir: string;
|
|
15
|
+
};
|
|
2
16
|
export interface SettingsConfig {
|
|
3
17
|
sourceDirectory: string;
|
|
4
18
|
recursive: boolean;
|
|
@@ -14,14 +28,8 @@ export interface SettingsConfig {
|
|
|
14
28
|
openApiFileName: string;
|
|
15
29
|
includeMetadata: boolean;
|
|
16
30
|
rootDir?: string;
|
|
17
|
-
onAfterProcess?: (files:
|
|
18
|
-
|
|
19
|
-
fileName: string;
|
|
20
|
-
}[]) => void;
|
|
21
|
-
onBeforeFileWrite?: (outputDir: string, fileName: string) => {
|
|
22
|
-
dir: string;
|
|
23
|
-
fileName: string;
|
|
24
|
-
};
|
|
31
|
+
onAfterProcess?: (files: TargetFile[]) => void;
|
|
32
|
+
onBeforeFileWrite?: (file: TargetFile) => TargetFile;
|
|
25
33
|
}
|
|
26
34
|
export declare class Settings {
|
|
27
35
|
config: SettingsConfig;
|
|
@@ -44,12 +52,6 @@ export declare class Settings {
|
|
|
44
52
|
openApiFileName(): string;
|
|
45
53
|
includeMetadata(): boolean;
|
|
46
54
|
getRootDir(): string | undefined;
|
|
47
|
-
onAfterProcess(files:
|
|
48
|
-
|
|
49
|
-
fileName: string;
|
|
50
|
-
}[]): void;
|
|
51
|
-
onBeforeFileWrite(outputDir: string, fileName: string): {
|
|
52
|
-
dir: string;
|
|
53
|
-
fileName: string;
|
|
54
|
-
};
|
|
55
|
+
onAfterProcess(files: TargetFile[]): void;
|
|
56
|
+
onBeforeFileWrite(file: TargetFile): TargetFile;
|
|
55
57
|
}
|
package/lib/settings.js
CHANGED
|
@@ -68,11 +68,11 @@ class Settings {
|
|
|
68
68
|
this.config.onAfterProcess(files);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
onBeforeFileWrite(
|
|
71
|
+
onBeforeFileWrite(file) {
|
|
72
72
|
if (this.config.onBeforeFileWrite) {
|
|
73
|
-
return this.config.onBeforeFileWrite(
|
|
73
|
+
return this.config.onBeforeFileWrite(file);
|
|
74
74
|
}
|
|
75
|
-
return
|
|
75
|
+
return file;
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
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,CAAC,SAAS,CAAC;IAC/B,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;IAC3B,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;IAC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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,34 +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 { Settings } from '../settings';
|
|
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: {
|
|
27
|
+
baseDir: Settings.getInstance().outputDir,
|
|
28
|
+
fileDir: file.dir,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return onBeforeFileWrite(targetFile);
|
|
26
33
|
}
|
|
27
34
|
}
|
|
28
|
-
|
|
29
|
-
type OnBeforeFileWrite = (outputDir: string, fileName: string) => TargetLocation;
|
|
30
|
-
|
|
31
|
-
type TargetLocation = {
|
|
32
|
-
dir: string;
|
|
33
|
-
fileName: string;
|
|
34
|
-
};
|
package/src/settings.ts
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
import { GeneratorChoices } from './transpiler/generator-choices';
|
|
2
2
|
|
|
3
|
+
export type OnBeforeFileWrite = (file: TargetFile) => TargetFile;
|
|
4
|
+
|
|
5
|
+
export type TargetFile = {
|
|
6
|
+
name: string;
|
|
7
|
+
extension: string;
|
|
8
|
+
dir: OutputDir;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type TargetLocation = {
|
|
12
|
+
dir: string;
|
|
13
|
+
fileName: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type OutputDir = {
|
|
17
|
+
baseDir: string;
|
|
18
|
+
fileDir: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
3
21
|
export interface SettingsConfig {
|
|
4
22
|
sourceDirectory: string;
|
|
5
23
|
recursive: boolean;
|
|
@@ -15,8 +33,8 @@ export interface SettingsConfig {
|
|
|
15
33
|
openApiFileName: string;
|
|
16
34
|
includeMetadata: boolean;
|
|
17
35
|
rootDir?: string;
|
|
18
|
-
onAfterProcess?: (files:
|
|
19
|
-
onBeforeFileWrite?: (
|
|
36
|
+
onAfterProcess?: (files: TargetFile[]) => void;
|
|
37
|
+
onBeforeFileWrite?: (file: TargetFile) => TargetFile;
|
|
20
38
|
}
|
|
21
39
|
|
|
22
40
|
export class Settings {
|
|
@@ -98,16 +116,16 @@ export class Settings {
|
|
|
98
116
|
return this.config.rootDir;
|
|
99
117
|
}
|
|
100
118
|
|
|
101
|
-
public onAfterProcess(files:
|
|
119
|
+
public onAfterProcess(files: TargetFile[]): void {
|
|
102
120
|
if (this.config.onAfterProcess) {
|
|
103
121
|
this.config.onAfterProcess(files);
|
|
104
122
|
}
|
|
105
123
|
}
|
|
106
124
|
|
|
107
|
-
public onBeforeFileWrite(
|
|
125
|
+
public onBeforeFileWrite(file: TargetFile): TargetFile {
|
|
108
126
|
if (this.config.onBeforeFileWrite) {
|
|
109
|
-
return this.config.onBeforeFileWrite(
|
|
127
|
+
return this.config.onBeforeFileWrite(file);
|
|
110
128
|
}
|
|
111
|
-
return
|
|
129
|
+
return file;
|
|
112
130
|
}
|
|
113
131
|
}
|