Skip to content

Commit 656c708

Browse files
authored
Merge pull request #144 from peschee/feature/cli-version
Adds version from package.json to the default CLI message
2 parents 8dd368b + 55982fc commit 656c708

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

packages/analyzer/index.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import chokidar from 'chokidar';
99
import debounce from 'debounce';
1010

1111
import { create } from './src/create.js';
12-
import {
13-
getUserConfig,
14-
getCliConfig,
15-
addFrameworkPlugins,
12+
import {
13+
getUserConfig,
14+
getCliConfig,
15+
addFrameworkPlugins,
1616
addCustomElementsPropertyToPackageJson,
1717
mergeGlobsAndExcludes,
1818
timestamp,
@@ -24,7 +24,7 @@ import {
2424
const mainDefinitions = [{ name: 'command', defaultOption: true }];
2525
const mainOptions = commandLineArgs(mainDefinitions, { stopAtFirstUnknown: true });
2626
const argv = mainOptions._unknown || [];
27-
27+
2828
if (mainOptions.command === 'analyze') {
2929

3030
const {
@@ -44,31 +44,31 @@ import {
4444
async function run() {
4545
/**
4646
* Create modules for `create()`
47-
*
47+
*
4848
* By default, the analyzer doesn't actually compile a users source code with the TS compiler
4949
* API. This means that by default, the typeChecker is not available in plugins.
50-
*
50+
*
5151
* If users want to use the typeChecker, they can do so by adding a `overrideModuleCreation` property
5252
* in their custom-elements-manifest.config.js. `overrideModuleCreation` is a function that should return
5353
* an array of sourceFiles.
5454
*/
55-
const modules = userConfig?.overrideModuleCreation
55+
const modules = userConfig?.overrideModuleCreation
5656
? userConfig.overrideModuleCreation({ts, globs})
5757
: globs.map(glob => {
5858
const relativeModulePath = path.relative(process.cwd(), glob);
5959
const source = fs.readFileSync(relativeModulePath).toString();
60-
60+
6161
return ts.createSourceFile(
6262
relativeModulePath,
6363
source,
6464
ts.ScriptTarget.ES2015,
6565
true,
6666
);
6767
});
68-
68+
6969
let plugins = await addFrameworkPlugins(mergedOptions);
7070
plugins = [...plugins, ...(userConfig?.plugins || [])];
71-
71+
7272
/**
7373
* Create the manifest
7474
*/
@@ -96,9 +96,9 @@ import {
9696
*/
9797
if(mergedOptions.watch) {
9898
const fileWatcher = chokidar.watch(globs);
99-
99+
100100
const onChange = debounce(run, 100);
101-
101+
102102
fileWatcher.addListener('change', onChange);
103103
fileWatcher.addListener('unlink', onChange);
104104
}
@@ -111,4 +111,4 @@ import {
111111
} else {
112112
console.log(MENU);
113113
}
114-
})();
114+
})();

packages/analyzer/src/utils/cli.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ import fs from 'fs';
33
import path from 'path';
44
import commandLineArgs from 'command-line-args';
55
import { has } from './index.js';
6+
import { createRequire } from 'module';
7+
8+
const require = createRequire(import.meta.url);
9+
const { version } = require('../../package.json');
610

711
const IGNORE = [
8-
'!node_modules/**/*.*',
9-
'!bower_components/**/*.*',
10-
'!**/*.test.{js,ts}',
11-
'!**/*.suite.{js,ts}',
12+
'!node_modules/**/*.*',
13+
'!bower_components/**/*.*',
14+
'!**/*.test.{js,ts}',
15+
'!**/*.suite.{js,ts}',
1216
'!**/*.config.{js,ts}'
1317
];
1418

@@ -70,7 +74,7 @@ export function getCliConfig(argv) {
7074
{ name: 'fast', type: Boolean },
7175
{ name: 'catalyst', type: Boolean },
7276
];
73-
77+
7478
return commandLineArgs(optionDefinitions, { argv });
7579
}
7680

@@ -121,7 +125,7 @@ export function addCustomElementsPropertyToPackageJson(outdir) {
121125
}
122126

123127
export const MENU = `
124-
@custom-elements-manifest/analyzer
128+
@custom-elements-manifest/analyzer (${version})
125129
126130
Available commands:
127131
| Command/option | Type | Description | Example |
@@ -140,4 +144,4 @@ Available commands:
140144
141145
Examples:
142146
custom-elements-manifest analyze --litelement --globs "**/*.js" --exclude "foo.js" "bar.js"
143-
`
147+
`

0 commit comments

Comments
 (0)