@komaci/cli 240.1.3 → 242.1.0
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/build/cmds/modgen/index.js +12 -0
- package/build/cmds/modgen/lib/readAndParseBundle.d.ts +9 -0
- package/build/cmds/modgen/lib/readAndParseBundle.js +39 -1
- package/build/cmds/modgen/lib/run.js +33 -15
- package/build/cmds/modgen/types.d.ts +3 -2
- package/build/index.js +1 -3
- package/package.json +4 -3
|
@@ -35,6 +35,18 @@ export default {
|
|
|
35
35
|
type: Boolean,
|
|
36
36
|
defaultValue: false,
|
|
37
37
|
},
|
|
38
|
+
{
|
|
39
|
+
name: 'raw',
|
|
40
|
+
alias: 'r',
|
|
41
|
+
type: Boolean,
|
|
42
|
+
defaultValue: false,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'withExceptions',
|
|
46
|
+
alias: 'e',
|
|
47
|
+
type: Boolean,
|
|
48
|
+
defaultValue: false,
|
|
49
|
+
},
|
|
38
50
|
],
|
|
39
51
|
run,
|
|
40
52
|
};
|
|
@@ -22,5 +22,14 @@ export declare function readBundle(path: string): BundleFile[];
|
|
|
22
22
|
* @returns ParsedBundle that includes the BundleConfig & GeneratorInput inputs, and BundleMetadata and generated module output
|
|
23
23
|
*/
|
|
24
24
|
export declare function readAndParseBundle(path: string, configOverrides: Partial<BundleConfig>): ParsedBundle;
|
|
25
|
+
/**
|
|
26
|
+
* Takes the directory path of an LWC module bundle and an optional set of config overrides. Returns the ParsedBundle, including
|
|
27
|
+
* the bundle's 1) LWC Metadata and 2) Komaci / Resolvable module.
|
|
28
|
+
* NOTE: This function allows an exception to be thrown in the generation process for us to consume instead of creating an error adg function.
|
|
29
|
+
* @param path
|
|
30
|
+
* @param configOverrides
|
|
31
|
+
* @returns ParsedBundle that includes the BundleConfig & GeneratorInput inputs, and BundleMetadata and generated module output
|
|
32
|
+
*/
|
|
33
|
+
export declare function readAndParseBundleWithExceptions(path: string, configOverrides: Partial<BundleConfig>): string;
|
|
25
34
|
export {};
|
|
26
35
|
//# sourceMappingURL=readAndParseBundle.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readdirSync, existsSync, readFileSync } from 'fs';
|
|
2
2
|
import { basename, dirname, extname, resolve } from 'path';
|
|
3
3
|
import { collectBundleMetadata } from '@lwc-platform/lwc-metadata-next';
|
|
4
|
-
import { generateKomaciModule } from '@komaci/esm-generator';
|
|
4
|
+
import { generateKomaciModule, processGeneratorInputAndState } from '@komaci/esm-generator';
|
|
5
5
|
/**
|
|
6
6
|
* Finds all .js, .mjs, .css, and .html files within the given directory, reads their contents, and combines them into a bundle,
|
|
7
7
|
* and returning the array of BundleFile containing the file's fileName and source
|
|
@@ -66,4 +66,42 @@ export function readAndParseBundle(path, configOverrides) {
|
|
|
66
66
|
output: { modGenOutput, metadata },
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Takes the directory path of an LWC module bundle and an optional set of config overrides. Returns the ParsedBundle, including
|
|
71
|
+
* the bundle's 1) LWC Metadata and 2) Komaci / Resolvable module.
|
|
72
|
+
* NOTE: This function allows an exception to be thrown in the generation process for us to consume instead of creating an error adg function.
|
|
73
|
+
* @param path
|
|
74
|
+
* @param configOverrides
|
|
75
|
+
* @returns ParsedBundle that includes the BundleConfig & GeneratorInput inputs, and BundleMetadata and generated module output
|
|
76
|
+
*/
|
|
77
|
+
export function readAndParseBundleWithExceptions(path, configOverrides) {
|
|
78
|
+
const files = readBundle(path);
|
|
79
|
+
const name = basename(path);
|
|
80
|
+
const namespace = basename(dirname(path));
|
|
81
|
+
const bundleConfig = {
|
|
82
|
+
namespace,
|
|
83
|
+
name,
|
|
84
|
+
type: 'internal',
|
|
85
|
+
namespaceMapping: {},
|
|
86
|
+
files,
|
|
87
|
+
enableKomaci: true,
|
|
88
|
+
...configOverrides,
|
|
89
|
+
};
|
|
90
|
+
const metadata = collectBundleMetadata(bundleConfig);
|
|
91
|
+
// Create input to module generator.
|
|
92
|
+
const srcFileMap = files.reduce((map, { fileName, source }) => ({ ...map, [fileName]: source }), {});
|
|
93
|
+
const inputFiles = Object.fromEntries(metadata.files
|
|
94
|
+
.map(({ fileName, komaciDoc }) => [fileName, komaciDoc])
|
|
95
|
+
.filter(([, komaciDoc]) => !!komaciDoc));
|
|
96
|
+
const input = {
|
|
97
|
+
moduleInfo: {
|
|
98
|
+
name,
|
|
99
|
+
namespace: bundleConfig.namespace,
|
|
100
|
+
type: 'bundle',
|
|
101
|
+
files: inputFiles,
|
|
102
|
+
},
|
|
103
|
+
srcFileMap,
|
|
104
|
+
};
|
|
105
|
+
return processGeneratorInputAndState(input);
|
|
106
|
+
}
|
|
69
107
|
//# sourceMappingURL=readAndParseBundle.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readAndParseBundle } from './readAndParseBundle.js';
|
|
1
|
+
import { readAndParseBundle, readAndParseBundleWithExceptions } from './readAndParseBundle.js';
|
|
2
2
|
import logger, { serialize } from '../../../lib/log.js';
|
|
3
3
|
const { log, warn } = logger;
|
|
4
4
|
/**
|
|
@@ -8,13 +8,30 @@ const { log, warn } = logger;
|
|
|
8
8
|
export function run(cmdOptions) {
|
|
9
9
|
const { paths = [], disableKomaci = false, bundleType: type } = cmdOptions;
|
|
10
10
|
if (paths.length) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
if (cmdOptions.withExceptions) {
|
|
12
|
+
const errors = [];
|
|
13
|
+
paths.map((path) => {
|
|
14
|
+
try {
|
|
15
|
+
readAndParseBundleWithExceptions(path, { enableKomaci: !disableKomaci, type });
|
|
16
|
+
}
|
|
17
|
+
catch (e) {
|
|
18
|
+
errors.push({ path: path, error: e });
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
log('Total Errors: ' + errors.length);
|
|
22
|
+
errors.forEach((ec) => {
|
|
23
|
+
log(ec);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const parsedBundles = paths.map((path) => readAndParseBundle(path, { enableKomaci: !disableKomaci, type }));
|
|
28
|
+
for (const parsedBundle of parsedBundles) {
|
|
29
|
+
const { input: { bundleConfig = null } = {}, output } = parsedBundle || {};
|
|
30
|
+
const { type, namespace, name, namespaceMapping = {}, enableKomaci = false, files = [], } = bundleConfig || {};
|
|
31
|
+
const fileNames = files.map(({ fileName }) => fileName);
|
|
32
|
+
const toPrint = { type, namespace, name, namespaceMapping, enableKomaci, fileNames, output };
|
|
33
|
+
printOutput(cmdOptions, toPrint);
|
|
34
|
+
}
|
|
18
35
|
}
|
|
19
36
|
}
|
|
20
37
|
else {
|
|
@@ -28,10 +45,11 @@ export function run(cmdOptions) {
|
|
|
28
45
|
*/
|
|
29
46
|
function printOutput(cmdOptions, toPrint) {
|
|
30
47
|
const { output: { metadata, modGenOutput } = {} } = toPrint;
|
|
31
|
-
const { json, only = [] } = cmdOptions;
|
|
48
|
+
const { json, only = [], raw } = cmdOptions;
|
|
49
|
+
const prettyOutput = !json && !raw;
|
|
32
50
|
if (only.includes('lwc')) {
|
|
33
|
-
log('===== LWC Metadata =====');
|
|
34
|
-
log(serialize(metadata,
|
|
51
|
+
raw || log('===== LWC Metadata =====');
|
|
52
|
+
log(serialize(metadata, prettyOutput));
|
|
35
53
|
}
|
|
36
54
|
if (only.includes('doc')) {
|
|
37
55
|
const files = (metadata?.files ?? []);
|
|
@@ -39,13 +57,13 @@ function printOutput(cmdOptions, toPrint) {
|
|
|
39
57
|
.filter(({ fileType }) => ['js', 'html'].includes(fileType))
|
|
40
58
|
.map((file) => [file.fileName, file.komaciDoc]);
|
|
41
59
|
for (const [fileName, doc] of docs) {
|
|
42
|
-
log('===== Komaci Document =====');
|
|
43
|
-
log(`===== ${fileName} =====`);
|
|
44
|
-
log(serialize(doc,
|
|
60
|
+
raw || log('===== Komaci Document =====');
|
|
61
|
+
raw || log(`===== ${fileName} =====`);
|
|
62
|
+
log(serialize(doc, prettyOutput));
|
|
45
63
|
}
|
|
46
64
|
}
|
|
47
65
|
if (only.includes('mod')) {
|
|
48
|
-
log('===== Komaci Module =====');
|
|
66
|
+
raw || log('===== Komaci Module =====');
|
|
49
67
|
log(modGenOutput);
|
|
50
68
|
}
|
|
51
69
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CommandLineOptions } from 'command-line-args';
|
|
2
|
-
import type { BundleType } from '@lwc
|
|
3
|
-
import { BundleConfig, BundleMetadata } from '@lwc
|
|
2
|
+
import type { BundleType } from '@lwc/metadata/dist/shared/config';
|
|
3
|
+
import { BundleConfig, BundleMetadata } from '@lwc/metadata';
|
|
4
4
|
import { GeneratorInput } from '@komaci/esm-generator';
|
|
5
5
|
export declare type ParsedBundle = {
|
|
6
6
|
input: {
|
|
@@ -18,5 +18,6 @@ export interface ModGenOptions extends CommandLineOptions {
|
|
|
18
18
|
disableKomaci: boolean;
|
|
19
19
|
bundleType: BundleType;
|
|
20
20
|
json: boolean;
|
|
21
|
+
withExceptions: boolean;
|
|
21
22
|
}
|
|
22
23
|
//# sourceMappingURL=types.d.ts.map
|
package/build/index.js
CHANGED
|
@@ -2,12 +2,10 @@ import commandLineArgs from 'command-line-args';
|
|
|
2
2
|
import { modgen } from './cmds/index.js';
|
|
3
3
|
import { commander } from './lib/commander.js';
|
|
4
4
|
import logger from './lib/log.js';
|
|
5
|
-
|
|
6
|
-
const { info, error } = logger;
|
|
5
|
+
const { error } = logger;
|
|
7
6
|
const optionDefinitions = [{ name: 'command', defaultOption: true }];
|
|
8
7
|
const mainCommand = commandLineArgs(optionDefinitions, { stopAtFirstUnknown: true });
|
|
9
8
|
const { command, _unknown: argv = [] } = mainCommand;
|
|
10
|
-
info(chalk.cyan(`Command: ${chalk.bgCyan(chalk.black(command))}.`));
|
|
11
9
|
if (!commander(command, argv, [modgen])) {
|
|
12
10
|
error(`No command "${command}" found`);
|
|
13
11
|
process.exit(1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@komaci/cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "242.1.0",
|
|
4
4
|
"description": "CLI utility that enables developers to use komaci from the command line.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -24,8 +24,9 @@
|
|
|
24
24
|
"url": "https://github.com/AndrewHuffman/komaci/issues"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@komaci/esm-generator": "
|
|
28
|
-
"@lwc
|
|
27
|
+
"@komaci/esm-generator": "242.1.0",
|
|
28
|
+
"@lwc/metadata": "2.22.0-0",
|
|
29
|
+
"@lwc/sfdc-compiler-utils": "2.22.0-0",
|
|
29
30
|
"chalk": "^5.0.1",
|
|
30
31
|
"command-line-args": "^5.2.1"
|
|
31
32
|
},
|