@strapi/typescript-utils 5.50.1 → 5.50.2
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/compile.d.ts +5 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +12 -0
- package/dist/compile.js.map +1 -0
- package/dist/compile.mjs +10 -0
- package/dist/compile.mjs.map +1 -0
- package/dist/compilers/basic.d.ts +11 -0
- package/dist/compilers/basic.d.ts.map +1 -0
- package/dist/compilers/basic.js +58 -0
- package/dist/compilers/basic.js.map +1 -0
- package/dist/compilers/basic.mjs +36 -0
- package/dist/compilers/basic.mjs.map +1 -0
- package/dist/compilers/index.d.ts +3 -0
- package/dist/compilers/index.d.ts.map +1 -0
- package/dist/compilers/index.js +8 -0
- package/dist/compilers/index.js.map +1 -0
- package/dist/compilers/index.mjs +3 -0
- package/dist/compilers/index.mjs.map +1 -0
- package/dist/generators/common/imports.d.ts +5 -0
- package/dist/generators/common/imports.d.ts.map +1 -0
- package/dist/generators/common/imports.js +42 -0
- package/dist/generators/common/imports.js.map +1 -0
- package/dist/generators/common/imports.mjs +19 -0
- package/dist/generators/common/imports.mjs.map +1 -0
- package/dist/generators/common/index.d.ts +4 -0
- package/dist/generators/common/index.d.ts.map +1 -0
- package/dist/generators/common/models/attributes.d.ts +17 -0
- package/dist/generators/common/models/attributes.d.ts.map +1 -0
- package/dist/generators/common/models/attributes.js +152 -0
- package/dist/generators/common/models/attributes.js.map +1 -0
- package/dist/generators/common/models/attributes.mjs +124 -0
- package/dist/generators/common/models/attributes.mjs.map +1 -0
- package/dist/generators/common/models/index.d.ts +7 -0
- package/dist/generators/common/models/index.d.ts.map +1 -0
- package/dist/generators/common/models/mappers.d.ts +9 -0
- package/dist/generators/common/models/mappers.d.ts.map +1 -0
- package/dist/generators/common/models/mappers.js +227 -0
- package/dist/generators/common/models/mappers.js.map +1 -0
- package/dist/generators/common/models/mappers.mjs +202 -0
- package/dist/generators/common/models/mappers.mjs.map +1 -0
- package/dist/generators/common/models/schema.d.ts +7 -0
- package/dist/generators/common/models/schema.d.ts.map +1 -0
- package/dist/generators/common/models/schema.js +79 -0
- package/dist/generators/common/models/schema.js.map +1 -0
- package/dist/generators/common/models/schema.mjs +57 -0
- package/dist/generators/common/models/schema.mjs.map +1 -0
- package/dist/generators/common/models/utils.d.ts +54 -0
- package/dist/generators/common/models/utils.d.ts.map +1 -0
- package/dist/generators/common/models/utils.js +109 -0
- package/dist/generators/common/models/utils.js.map +1 -0
- package/dist/generators/common/models/utils.mjs +81 -0
- package/dist/generators/common/models/utils.mjs.map +1 -0
- package/dist/generators/components/index.d.ts +9 -0
- package/dist/generators/components/index.d.ts.map +1 -0
- package/dist/generators/components/index.js +76 -0
- package/dist/generators/components/index.js.map +1 -0
- package/dist/generators/components/index.mjs +54 -0
- package/dist/generators/components/index.mjs.map +1 -0
- package/dist/generators/constants.d.ts +3 -0
- package/dist/generators/constants.d.ts.map +1 -0
- package/dist/generators/constants.js +8 -0
- package/dist/generators/constants.js.map +1 -0
- package/dist/generators/constants.mjs +5 -0
- package/dist/generators/constants.mjs.map +1 -0
- package/dist/generators/content-types/index.d.ts +9 -0
- package/dist/generators/content-types/index.d.ts.map +1 -0
- package/dist/generators/content-types/index.js +76 -0
- package/dist/generators/content-types/index.js.map +1 -0
- package/dist/generators/content-types/index.mjs +54 -0
- package/dist/generators/content-types/index.mjs.map +1 -0
- package/dist/generators/index.d.ts +23 -0
- package/dist/generators/index.d.ts.map +1 -0
- package/dist/generators/index.js +81 -0
- package/dist/generators/index.js.map +1 -0
- package/dist/generators/index.mjs +74 -0
- package/dist/generators/index.mjs.map +1 -0
- package/dist/generators/utils.d.ts +52 -0
- package/dist/generators/utils.d.ts.map +1 -0
- package/dist/generators/utils.js +164 -0
- package/dist/generators/utils.js.map +1 -0
- package/dist/generators/utils.mjs +131 -0
- package/dist/generators/utils.mjs.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +14 -0
- package/dist/index.mjs.map +1 -0
- package/dist/utils/format-host.d.ts +3 -0
- package/dist/utils/format-host.d.ts.map +1 -0
- package/dist/utils/format-host.js +33 -0
- package/dist/utils/format-host.js.map +1 -0
- package/dist/utils/format-host.mjs +11 -0
- package/dist/utils/format-host.mjs.map +1 -0
- package/dist/utils/get-config-path.d.ts +10 -0
- package/dist/utils/get-config-path.d.ts.map +1 -0
- package/dist/utils/get-config-path.js +43 -0
- package/dist/utils/get-config-path.js.map +1 -0
- package/dist/utils/get-config-path.mjs +18 -0
- package/dist/utils/get-config-path.mjs.map +1 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/is-using-typescript-sync.d.ts +5 -0
- package/dist/utils/is-using-typescript-sync.d.ts.map +1 -0
- package/dist/utils/is-using-typescript-sync.js +20 -0
- package/dist/utils/is-using-typescript-sync.js.map +1 -0
- package/dist/utils/is-using-typescript-sync.mjs +14 -0
- package/dist/utils/is-using-typescript-sync.mjs.map +1 -0
- package/dist/utils/is-using-typescript.d.ts +5 -0
- package/dist/utils/is-using-typescript.d.ts.map +1 -0
- package/dist/utils/is-using-typescript.js +20 -0
- package/dist/utils/is-using-typescript.js.map +1 -0
- package/dist/utils/is-using-typescript.mjs +14 -0
- package/dist/utils/is-using-typescript.mjs.map +1 -0
- package/dist/utils/report-diagnostics.d.ts +6 -0
- package/dist/utils/report-diagnostics.d.ts.map +1 -0
- package/dist/utils/report-diagnostics.js +37 -0
- package/dist/utils/report-diagnostics.js.map +1 -0
- package/dist/utils/report-diagnostics.mjs +15 -0
- package/dist/utils/report-diagnostics.mjs.map +1 -0
- package/dist/utils/resolve-config-options.d.ts +12 -0
- package/dist/utils/resolve-config-options.d.ts.map +1 -0
- package/dist/utils/resolve-config-options.js +39 -0
- package/dist/utils/resolve-config-options.js.map +1 -0
- package/dist/utils/resolve-config-options.mjs +17 -0
- package/dist/utils/resolve-config-options.mjs.map +1 -0
- package/dist/utils/resolve-outdir-sync.d.ts +5 -0
- package/dist/utils/resolve-outdir-sync.d.ts.map +1 -0
- package/dist/utils/resolve-outdir-sync.js +19 -0
- package/dist/utils/resolve-outdir-sync.js.map +1 -0
- package/dist/utils/resolve-outdir-sync.mjs +13 -0
- package/dist/utils/resolve-outdir-sync.mjs.map +1 -0
- package/dist/utils/resolve-outdir.d.ts +5 -0
- package/dist/utils/resolve-outdir.d.ts.map +1 -0
- package/dist/utils/resolve-outdir.js +19 -0
- package/dist/utils/resolve-outdir.js.map +1 -0
- package/dist/utils/resolve-outdir.mjs +13 -0
- package/dist/utils/resolve-outdir.mjs.map +1 -0
- package/package.json +25 -10
- package/.eslintrc.cjs +0 -16
- package/index.d.ts +0 -5
- package/jest.config.js +0 -6
- package/lib/__tests__/generators/schemas/attributes.test.js +0 -903
- package/lib/__tests__/generators/schemas/imports.test.js +0 -56
- package/lib/__tests__/generators/schemas/utils.test.js +0 -314
- package/lib/__tests__/generators/utils.test.js +0 -43
- package/lib/compile.js +0 -10
- package/lib/compilers/basic.js +0 -50
- package/lib/compilers/index.js +0 -7
- package/lib/generators/common/imports.js +0 -34
- package/lib/generators/common/index.js +0 -9
- package/lib/generators/common/models/attributes.js +0 -198
- package/lib/generators/common/models/index.js +0 -15
- package/lib/generators/common/models/mappers.js +0 -144
- package/lib/generators/common/models/schema.js +0 -93
- package/lib/generators/common/models/utils.js +0 -178
- package/lib/generators/components/index.js +0 -74
- package/lib/generators/constants.js +0 -6
- package/lib/generators/content-types/index.js +0 -74
- package/lib/generators/index.js +0 -122
- package/lib/generators/utils.js +0 -217
- package/lib/index.js +0 -13
- package/lib/utils/format-host.js +0 -15
- package/lib/utils/get-config-path.js +0 -29
- package/lib/utils/index.js +0 -21
- package/lib/utils/is-using-typescript-sync.js +0 -19
- package/lib/utils/is-using-typescript.js +0 -17
- package/lib/utils/report-diagnostics.js +0 -19
- package/lib/utils/resolve-config-options.js +0 -23
- package/lib/utils/resolve-outdir-sync.js +0 -18
- package/lib/utils/resolve-outdir.js +0 -18
- package/lint-staged.config.mjs +0 -1
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { factory } = require('typescript');
|
|
4
|
-
const { values, pipe, map, sortBy } = require('lodash/fp');
|
|
5
|
-
|
|
6
|
-
const { models } = require('../common');
|
|
7
|
-
const { emitDefinitions, format, generateSharedExtensionDefinition } = require('../utils');
|
|
8
|
-
|
|
9
|
-
const NO_CONTENT_TYPE_PLACEHOLDER_COMMENT = `/*
|
|
10
|
-
* The app doesn't have any content-types yet.
|
|
11
|
-
*/
|
|
12
|
-
`;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Generate type definitions for Strapi Content-Types
|
|
16
|
-
*
|
|
17
|
-
* @param {object} [options]
|
|
18
|
-
* @param {object} options.strapi
|
|
19
|
-
* @param {object} options.logger
|
|
20
|
-
* @param {string} options.pwd
|
|
21
|
-
*/
|
|
22
|
-
const generateContentTypesDefinitions = async (options = {}) => {
|
|
23
|
-
const { strapi } = options;
|
|
24
|
-
|
|
25
|
-
const { contentTypes } = strapi;
|
|
26
|
-
|
|
27
|
-
const contentTypesDefinitions = pipe(
|
|
28
|
-
values,
|
|
29
|
-
sortBy('uid'),
|
|
30
|
-
map((contentType) => ({
|
|
31
|
-
uid: contentType.uid,
|
|
32
|
-
definition: models.schema.generateSchemaDefinition(contentType),
|
|
33
|
-
}))
|
|
34
|
-
)(contentTypes);
|
|
35
|
-
|
|
36
|
-
options.logger.debug(`Found ${contentTypesDefinitions.length} content-types.`);
|
|
37
|
-
|
|
38
|
-
if (contentTypesDefinitions.length === 0) {
|
|
39
|
-
return { output: NO_CONTENT_TYPE_PLACEHOLDER_COMMENT, stats: {} };
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const formattedSchemasDefinitions = contentTypesDefinitions.reduce((acc, def) => {
|
|
43
|
-
acc.push(
|
|
44
|
-
// Definition
|
|
45
|
-
def.definition,
|
|
46
|
-
|
|
47
|
-
// Add a newline between each interface declaration
|
|
48
|
-
factory.createIdentifier('\n')
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
return acc;
|
|
52
|
-
}, []);
|
|
53
|
-
|
|
54
|
-
const allDefinitions = [
|
|
55
|
-
// Imports
|
|
56
|
-
...models.imports.generateImportDefinition(),
|
|
57
|
-
|
|
58
|
-
// Add a newline after the import statement
|
|
59
|
-
factory.createIdentifier('\n'),
|
|
60
|
-
|
|
61
|
-
// Schemas
|
|
62
|
-
...formattedSchemasDefinitions,
|
|
63
|
-
|
|
64
|
-
// Global
|
|
65
|
-
generateSharedExtensionDefinition('ContentTypeSchemas', contentTypesDefinitions),
|
|
66
|
-
];
|
|
67
|
-
|
|
68
|
-
const output = emitDefinitions(allDefinitions);
|
|
69
|
-
const formattedOutput = await format(output);
|
|
70
|
-
|
|
71
|
-
return { output: formattedOutput, stats: {} };
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
module.exports = generateContentTypesDefinitions;
|
package/lib/generators/index.js
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const chalk = require('chalk');
|
|
5
|
-
|
|
6
|
-
const { TYPES_ROOT_DIR, GENERATED_OUT_DIR } = require('./constants');
|
|
7
|
-
const { saveDefinitionToFileSystem, createLogger, timer } = require('./utils');
|
|
8
|
-
const generateContentTypesDefinitions = require('./content-types');
|
|
9
|
-
const generateComponentsDefinitions = require('./components');
|
|
10
|
-
|
|
11
|
-
const GENERATORS = {
|
|
12
|
-
contentTypes: generateContentTypesDefinitions,
|
|
13
|
-
components: generateComponentsDefinitions,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @typedef GenerateConfig
|
|
18
|
-
*
|
|
19
|
-
* @property {object} strapi
|
|
20
|
-
* @property {boolean} pwd
|
|
21
|
-
* @property {object} [artifacts]
|
|
22
|
-
* @property {boolean} [artifacts.contentTypes]
|
|
23
|
-
* @property {boolean} [artifacts.components]
|
|
24
|
-
* @property {boolean} [artifacts.services]
|
|
25
|
-
* @property {boolean} [artifacts.controllers]
|
|
26
|
-
* @property {boolean} [artifacts.policies]
|
|
27
|
-
* @property {boolean} [artifacts.middlewares]
|
|
28
|
-
* @property {object} [logger]
|
|
29
|
-
* @property {boolean} [logger.silent]
|
|
30
|
-
* @property {boolean} [logger.debug]
|
|
31
|
-
* @property {boolean} [logger.verbose]
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Generate types definitions based on the given configuration
|
|
36
|
-
*
|
|
37
|
-
* @param {GenerateConfig} [config]
|
|
38
|
-
*/
|
|
39
|
-
const generate = async (config = {}) => {
|
|
40
|
-
const { pwd, rootDir = TYPES_ROOT_DIR, strapi, artifacts = {}, logger: loggerConfig } = config;
|
|
41
|
-
const reports = {};
|
|
42
|
-
const logger = createLogger(loggerConfig);
|
|
43
|
-
const psTimer = timer().start();
|
|
44
|
-
|
|
45
|
-
const registryPwd = path.join(pwd, rootDir, GENERATED_OUT_DIR);
|
|
46
|
-
const generatorConfig = { strapi, pwd: registryPwd, logger };
|
|
47
|
-
|
|
48
|
-
const returnWithMessage = () => {
|
|
49
|
-
const nbWarnings = chalk.yellow(`${logger.warnings} warning(s)`);
|
|
50
|
-
const nbErrors = chalk.red(`${logger.errors} error(s)`);
|
|
51
|
-
|
|
52
|
-
const status = logger.errors > 0 ? chalk.red('errored') : chalk.green('completed successfully');
|
|
53
|
-
|
|
54
|
-
psTimer.end();
|
|
55
|
-
|
|
56
|
-
logger.info(`The task ${status} with ${nbWarnings} and ${nbErrors} in ${psTimer.duration}s.`);
|
|
57
|
-
|
|
58
|
-
return reports;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const enabledArtifacts = Object.keys(artifacts).filter((p) => artifacts[p] === true);
|
|
62
|
-
|
|
63
|
-
logger.info('Starting the type generation process');
|
|
64
|
-
logger.debug(`Enabled artifacts: ${enabledArtifacts.join(', ')}`);
|
|
65
|
-
|
|
66
|
-
for (const artifact of enabledArtifacts) {
|
|
67
|
-
const boldArtifact = chalk.bold(artifact); // used for log messages
|
|
68
|
-
|
|
69
|
-
logger.info(`Generating types for ${boldArtifact}`);
|
|
70
|
-
|
|
71
|
-
if (artifact in GENERATORS) {
|
|
72
|
-
const generator = GENERATORS[artifact];
|
|
73
|
-
|
|
74
|
-
try {
|
|
75
|
-
const artifactGenTimer = timer().start();
|
|
76
|
-
|
|
77
|
-
reports[artifact] = await generator(generatorConfig);
|
|
78
|
-
|
|
79
|
-
artifactGenTimer.end();
|
|
80
|
-
|
|
81
|
-
logger.debug(`Generated ${boldArtifact} in ${artifactGenTimer.duration}s`);
|
|
82
|
-
} catch (e) {
|
|
83
|
-
logger.error(
|
|
84
|
-
`Failed to generate types for ${boldArtifact}: ${e.message ?? e.toString()}. Exiting`
|
|
85
|
-
);
|
|
86
|
-
return returnWithMessage();
|
|
87
|
-
}
|
|
88
|
-
} else {
|
|
89
|
-
logger.warn(`The types generator for ${boldArtifact} is not implemented, skipping`);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
for (const artifact of Object.keys(reports)) {
|
|
94
|
-
const boldArtifact = chalk.bold(artifact); // used for log messages
|
|
95
|
-
|
|
96
|
-
const artifactFsTimer = timer().start();
|
|
97
|
-
|
|
98
|
-
const report = reports[artifact];
|
|
99
|
-
const filename = `${artifact}.d.ts`;
|
|
100
|
-
|
|
101
|
-
try {
|
|
102
|
-
const outPath = await saveDefinitionToFileSystem(registryPwd, filename, report.output);
|
|
103
|
-
const relativeOutPath = path.relative(process.cwd(), outPath);
|
|
104
|
-
|
|
105
|
-
artifactFsTimer.end();
|
|
106
|
-
|
|
107
|
-
logger.info(`Saved ${boldArtifact} types in ${chalk.bold(relativeOutPath)}`);
|
|
108
|
-
logger.debug(`Saved ${boldArtifact} in ${artifactFsTimer.duration}s`);
|
|
109
|
-
} catch (e) {
|
|
110
|
-
logger.error(
|
|
111
|
-
`An error occurred while saving ${boldArtifact} types to the filesystem: ${
|
|
112
|
-
e.message ?? e.toString()
|
|
113
|
-
}. Exiting`
|
|
114
|
-
);
|
|
115
|
-
return returnWithMessage();
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return returnWithMessage();
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
module.exports = { generate };
|
package/lib/generators/utils.js
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const assert = require('assert');
|
|
5
|
-
const ts = require('typescript');
|
|
6
|
-
const fse = require('fs-extra');
|
|
7
|
-
const chalk = require('chalk');
|
|
8
|
-
|
|
9
|
-
const { factory } = ts;
|
|
10
|
-
|
|
11
|
-
const MODULE_DECLARATION = '@strapi/strapi';
|
|
12
|
-
const PUBLIC_NAMESPACE = 'Public';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Aggregate the given TypeScript nodes into a single string
|
|
16
|
-
*
|
|
17
|
-
* @param {ts.Node[]} definitions
|
|
18
|
-
* @return {string}
|
|
19
|
-
*/
|
|
20
|
-
const emitDefinitions = (definitions) => {
|
|
21
|
-
const nodeArray = factory.createNodeArray(definitions);
|
|
22
|
-
|
|
23
|
-
const sourceFile = ts.createSourceFile(
|
|
24
|
-
'placeholder.ts',
|
|
25
|
-
'',
|
|
26
|
-
ts.ScriptTarget.ESNext,
|
|
27
|
-
true,
|
|
28
|
-
ts.ScriptKind.TS
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
const printer = ts.createPrinter({ omitTrailingSemicolon: true });
|
|
32
|
-
|
|
33
|
-
return printer.printList(ts.ListFormat.MultiLine, nodeArray, sourceFile);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Save the given string representation of TS nodes in a file
|
|
38
|
-
* If the given directory doesn't exist, it'll be created automatically
|
|
39
|
-
*
|
|
40
|
-
* @param {string} dir
|
|
41
|
-
* @param {string} file
|
|
42
|
-
* @param {string} content
|
|
43
|
-
*
|
|
44
|
-
* @return {Promise<string>} The path of the created file
|
|
45
|
-
*/
|
|
46
|
-
const saveDefinitionToFileSystem = async (dir, file, content) => {
|
|
47
|
-
const filepath = path.join(dir, file);
|
|
48
|
-
|
|
49
|
-
fse.ensureDirSync(dir);
|
|
50
|
-
await fse.writeFile(filepath, content);
|
|
51
|
-
|
|
52
|
-
return filepath;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Format the given definitions.
|
|
57
|
-
* Uses the existing config if one is defined in the project.
|
|
58
|
-
*
|
|
59
|
-
* @param {string} content
|
|
60
|
-
* @returns {Promise<string>}
|
|
61
|
-
*/
|
|
62
|
-
const format = async (content) => {
|
|
63
|
-
// eslint-disable-next-line node/no-unsupported-features/es-syntax
|
|
64
|
-
const prettier = await import('prettier'); // ESM-only
|
|
65
|
-
|
|
66
|
-
const configFile = await prettier.resolveConfigFile();
|
|
67
|
-
const config = configFile
|
|
68
|
-
? await prettier.resolveConfig(configFile)
|
|
69
|
-
: // Default config
|
|
70
|
-
{
|
|
71
|
-
singleQuote: true,
|
|
72
|
-
useTabs: false,
|
|
73
|
-
tabWidth: 2,
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
Object.assign(config, { parser: 'typescript' });
|
|
77
|
-
|
|
78
|
-
return prettier.format(content, config);
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Generate the extension block for a shared component from strapi/strapi
|
|
83
|
-
*
|
|
84
|
-
* @param {string} registry The registry to extend
|
|
85
|
-
* @param {Array<{ uid: string; definition: ts.TypeNode }>} definitions
|
|
86
|
-
* @returns {ts.ModuleDeclaration}
|
|
87
|
-
*/
|
|
88
|
-
const generateSharedExtensionDefinition = (registry, definitions) => {
|
|
89
|
-
const properties = definitions.map(({ uid, definition }) =>
|
|
90
|
-
factory.createPropertySignature(
|
|
91
|
-
undefined,
|
|
92
|
-
factory.createStringLiteral(uid, true),
|
|
93
|
-
undefined,
|
|
94
|
-
factory.createTypeReferenceNode(factory.createIdentifier(definition.name.escapedText))
|
|
95
|
-
)
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
return factory.createModuleDeclaration(
|
|
99
|
-
[factory.createModifier(ts.SyntaxKind.DeclareKeyword)],
|
|
100
|
-
factory.createStringLiteral(MODULE_DECLARATION, true),
|
|
101
|
-
factory.createModuleBlock([
|
|
102
|
-
factory.createModuleDeclaration(
|
|
103
|
-
[factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
|
104
|
-
factory.createIdentifier(PUBLIC_NAMESPACE),
|
|
105
|
-
factory.createModuleBlock(
|
|
106
|
-
properties.length > 0
|
|
107
|
-
? [
|
|
108
|
-
factory.createInterfaceDeclaration(
|
|
109
|
-
[factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
|
110
|
-
factory.createIdentifier(registry),
|
|
111
|
-
undefined,
|
|
112
|
-
undefined,
|
|
113
|
-
properties
|
|
114
|
-
),
|
|
115
|
-
]
|
|
116
|
-
: []
|
|
117
|
-
),
|
|
118
|
-
ts.NodeFlags.Namespace
|
|
119
|
-
),
|
|
120
|
-
]),
|
|
121
|
-
ts.NodeFlags.ExportContext
|
|
122
|
-
);
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const createLogger = (options = {}) => {
|
|
126
|
-
const { silent = false, debug = false } = options;
|
|
127
|
-
|
|
128
|
-
const state = { errors: 0, warning: 0 };
|
|
129
|
-
|
|
130
|
-
return {
|
|
131
|
-
get warnings() {
|
|
132
|
-
return state.warning;
|
|
133
|
-
},
|
|
134
|
-
|
|
135
|
-
get errors() {
|
|
136
|
-
return state.errors;
|
|
137
|
-
},
|
|
138
|
-
|
|
139
|
-
debug(...args) {
|
|
140
|
-
if (silent || !debug) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
console.log(chalk.cyan(`[DEBUG]\t[${new Date().toISOString()}] (Typegen)`), ...args);
|
|
145
|
-
},
|
|
146
|
-
|
|
147
|
-
info(...args) {
|
|
148
|
-
if (silent) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
console.info(chalk.blue(`[INFO]\t[${new Date().toISOString()}] (Typegen)`), ...args);
|
|
153
|
-
},
|
|
154
|
-
|
|
155
|
-
warn(...args) {
|
|
156
|
-
state.warning += 1;
|
|
157
|
-
|
|
158
|
-
if (silent) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
console.warn(chalk.yellow(`[WARN]\t[${new Date().toISOString()}] (Typegen)`), ...args);
|
|
163
|
-
},
|
|
164
|
-
|
|
165
|
-
error(...args) {
|
|
166
|
-
state.errors += 1;
|
|
167
|
-
|
|
168
|
-
if (silent) {
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
console.error(chalk.red(`[ERROR]\t[${new Date().toISOString()}] (Typegen)`), ...args);
|
|
173
|
-
},
|
|
174
|
-
};
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
const timer = () => {
|
|
178
|
-
const state = {
|
|
179
|
-
start: null,
|
|
180
|
-
end: null,
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
return {
|
|
184
|
-
start() {
|
|
185
|
-
assert(state.start === null, 'The timer has already been started');
|
|
186
|
-
assert(state.end === null, 'The timer has already been ended');
|
|
187
|
-
|
|
188
|
-
state.start = Date.now();
|
|
189
|
-
|
|
190
|
-
return this;
|
|
191
|
-
},
|
|
192
|
-
|
|
193
|
-
end() {
|
|
194
|
-
assert(state.start !== null, 'The timer needs to be started before ending it');
|
|
195
|
-
assert(state.end === null, 'The timer has already been ended');
|
|
196
|
-
|
|
197
|
-
state.end = Date.now();
|
|
198
|
-
|
|
199
|
-
return this;
|
|
200
|
-
},
|
|
201
|
-
|
|
202
|
-
get duration() {
|
|
203
|
-
assert(state.start !== null, 'The timer has not been started');
|
|
204
|
-
|
|
205
|
-
return ((state.end ?? Date.now) - state.start) / 1000;
|
|
206
|
-
},
|
|
207
|
-
};
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
module.exports = {
|
|
211
|
-
emitDefinitions,
|
|
212
|
-
saveDefinitionToFileSystem,
|
|
213
|
-
format,
|
|
214
|
-
generateSharedExtensionDefinition,
|
|
215
|
-
createLogger,
|
|
216
|
-
timer,
|
|
217
|
-
};
|
package/lib/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const compile = require('./compile');
|
|
4
|
-
const compilers = require('./compilers');
|
|
5
|
-
const utils = require('./utils');
|
|
6
|
-
const generators = require('./generators');
|
|
7
|
-
|
|
8
|
-
module.exports = {
|
|
9
|
-
compile,
|
|
10
|
-
compilers,
|
|
11
|
-
generators,
|
|
12
|
-
...utils,
|
|
13
|
-
};
|
package/lib/utils/format-host.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const ts = require('typescript');
|
|
4
|
-
const { identity } = require('lodash/fp');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @type {ts.FormatDiagnosticsHost}
|
|
8
|
-
*/
|
|
9
|
-
const formatHost = {
|
|
10
|
-
getCanonicalFileName: identity,
|
|
11
|
-
getCurrentDirectory: ts.sys.getCurrentDirectory,
|
|
12
|
-
getNewLine: () => ts.sys.newLine,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
module.exports = formatHost;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const ts = require('typescript');
|
|
5
|
-
|
|
6
|
-
const DEFAULT_TS_CONFIG_FILENAME = 'tsconfig.json';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Get the path of the typescript config file for a given directory
|
|
10
|
-
*
|
|
11
|
-
* @param {string} dir
|
|
12
|
-
* @param {object} [options]
|
|
13
|
-
* @param {string} [options.filename]
|
|
14
|
-
* @param {boolean} [options.ancestorsLookup]
|
|
15
|
-
*
|
|
16
|
-
* @return {string | undefined}
|
|
17
|
-
*/
|
|
18
|
-
module.exports = (dir, { filename = DEFAULT_TS_CONFIG_FILENAME, ancestorsLookup = false } = {}) => {
|
|
19
|
-
const dirAbsolutePath = path.resolve(dir);
|
|
20
|
-
let configFilePath = ts.findConfigFile(dirAbsolutePath, ts.sys.fileExists, filename);
|
|
21
|
-
|
|
22
|
-
if (configFilePath) configFilePath = path.resolve(configFilePath);
|
|
23
|
-
|
|
24
|
-
if (!configFilePath || ancestorsLookup) {
|
|
25
|
-
return configFilePath;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return configFilePath.startsWith(dirAbsolutePath) ? configFilePath : undefined;
|
|
29
|
-
};
|
package/lib/utils/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const isUsingTypeScript = require('./is-using-typescript');
|
|
4
|
-
const isUsingTypeScriptSync = require('./is-using-typescript-sync');
|
|
5
|
-
const getConfigPath = require('./get-config-path');
|
|
6
|
-
const reportDiagnostics = require('./report-diagnostics');
|
|
7
|
-
const resolveConfigOptions = require('./resolve-config-options');
|
|
8
|
-
const formatHost = require('./format-host');
|
|
9
|
-
const resolveOutDir = require('./resolve-outdir');
|
|
10
|
-
const resolveOutDirSync = require('./resolve-outdir-sync');
|
|
11
|
-
|
|
12
|
-
module.exports = {
|
|
13
|
-
isUsingTypeScript,
|
|
14
|
-
isUsingTypeScriptSync,
|
|
15
|
-
getConfigPath,
|
|
16
|
-
reportDiagnostics,
|
|
17
|
-
resolveConfigOptions,
|
|
18
|
-
formatHost,
|
|
19
|
-
resolveOutDir,
|
|
20
|
-
resolveOutDirSync,
|
|
21
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
const fse = require('fs-extra');
|
|
6
|
-
|
|
7
|
-
const getConfigPath = require('./get-config-path');
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Checks if `dir` is a using TypeScript (whether there is a tsconfig file or not)
|
|
11
|
-
* @param {string} dir
|
|
12
|
-
* @param {string | undefined} filename
|
|
13
|
-
* @returns {boolean}
|
|
14
|
-
*/
|
|
15
|
-
module.exports = (dir, filename = undefined) => {
|
|
16
|
-
const filePath = getConfigPath(dir, { filename });
|
|
17
|
-
|
|
18
|
-
return filePath ? fse.pathExistsSync(filePath) : false;
|
|
19
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fse = require('fs-extra');
|
|
4
|
-
|
|
5
|
-
const getConfigPath = require('./get-config-path');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Checks if `dir` is a using TypeScript (whether there is a tsconfig file or not)
|
|
9
|
-
* @param {string} dir
|
|
10
|
-
* @param {string | undefined} filename
|
|
11
|
-
* @returns {Promise<boolean>}
|
|
12
|
-
*/
|
|
13
|
-
module.exports = (dir, filename = undefined) => {
|
|
14
|
-
const filePath = getConfigPath(dir, { filename });
|
|
15
|
-
|
|
16
|
-
return fse.pathExists(filePath);
|
|
17
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const ts = require('typescript');
|
|
4
|
-
|
|
5
|
-
const formatHost = require('./format-host');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Report one or several diagnostic to the console
|
|
9
|
-
* @param {ts.Diagnostic[] | ts.Diagnostic} diagnostics
|
|
10
|
-
*/
|
|
11
|
-
module.exports = (diagnostics) => {
|
|
12
|
-
const formattedDiagnostics = ts.formatDiagnosticsWithColorAndContext(
|
|
13
|
-
Array.isArray(diagnostics) ? diagnostics : [diagnostics],
|
|
14
|
-
formatHost
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
console.error(formattedDiagnostics);
|
|
18
|
-
console.info(`Found ${diagnostics.length} error(s).${ts.sys.newLine}`);
|
|
19
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const ts = require('typescript');
|
|
4
|
-
|
|
5
|
-
const logDiagnostics = require('./report-diagnostics');
|
|
6
|
-
|
|
7
|
-
module.exports = (configPath) => {
|
|
8
|
-
// Parse the tsconfig.json file and resolve every file name & compiler options
|
|
9
|
-
const { errors, ...configOptions } = ts.getParsedCommandLineOfConfigFile(
|
|
10
|
-
configPath,
|
|
11
|
-
undefined,
|
|
12
|
-
ts.sys
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
// If there are errors in the tsconfig.json
|
|
16
|
-
// file, report them and exit early
|
|
17
|
-
if (errors.length > 0) {
|
|
18
|
-
logDiagnostics(errors);
|
|
19
|
-
process.exit(1);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return configOptions;
|
|
23
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const resolveConfigOptions = require('./resolve-config-options');
|
|
5
|
-
const isUsingTypescriptSync = require('./is-using-typescript-sync');
|
|
6
|
-
|
|
7
|
-
const DEFAULT_TS_CONFIG_FILENAME = 'tsconfig.json';
|
|
8
|
-
/**
|
|
9
|
-
* Gets the outDir value from config file (tsconfig)
|
|
10
|
-
* @param {string} dir
|
|
11
|
-
* @param {string | undefined} configFilename
|
|
12
|
-
* @returns {string | undefined}
|
|
13
|
-
*/
|
|
14
|
-
module.exports = (dir, configFilename = DEFAULT_TS_CONFIG_FILENAME) => {
|
|
15
|
-
return isUsingTypescriptSync(dir)
|
|
16
|
-
? resolveConfigOptions(path.join(dir, configFilename)).options.outDir
|
|
17
|
-
: undefined;
|
|
18
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const resolveConfigOptions = require('./resolve-config-options');
|
|
5
|
-
const isUsingTypescript = require('./is-using-typescript');
|
|
6
|
-
|
|
7
|
-
const DEFAULT_TS_CONFIG_FILENAME = 'tsconfig.json';
|
|
8
|
-
/**
|
|
9
|
-
* Gets the outDir value from config file (tsconfig)
|
|
10
|
-
* @param {string} dir
|
|
11
|
-
* @param {string | undefined} configFilename
|
|
12
|
-
* @returns {Promise<string | undefined>}
|
|
13
|
-
*/
|
|
14
|
-
module.exports = async (dir, configFilename = DEFAULT_TS_CONFIG_FILENAME) => {
|
|
15
|
-
return (await isUsingTypescript(dir))
|
|
16
|
-
? resolveConfigOptions(path.join(dir, configFilename)).options.outDir
|
|
17
|
-
: undefined;
|
|
18
|
-
};
|
package/lint-staged.config.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '../../../lint-staged.shared.mjs';
|