Skip to content

Commit ed25751

Browse files
committed
initial commit 🎉
1 parent ce948f5 commit ed25751

17 files changed

+1325
-0
lines changed

.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
typings
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Visible Price Range Util - Lightweight Charts™ Plugin
2+
3+
A plugin for providing a utility API to retrieve the visible range of a price scale, and subscribe to changes.
4+
5+
- Developed for Lightweight Charts version: `v4.1.0`
6+
7+
## Installation
8+
9+
```bash
10+
npm install lwc-plugin-visible-price-range-util
11+
```
12+
13+
## Usage
14+
15+
```js
16+
import { VisiblePriceRangeUtil } from 'lwc-plugin-visible-price-range-util';
17+
18+
// Create an instantiated Visible Price Range Util primitive.
19+
const vprUtil = new VisiblePriceRangeUtil();
20+
21+
// Create the chart and series...
22+
const chart = createChart(document.getElementById('container'));
23+
const lineSeries = chart.addLineSeries();
24+
const data = [
25+
{ time: 1642425322, value: 123 },
26+
/* ... more data */
27+
];
28+
29+
// Attach the utility to the series
30+
lineSeries.attachPrimitive(vprUtil);
31+
32+
const currentVisiblePriceRange = vprUtil.getVisiblePriceRange();
33+
vprUtil.priceRangeChanged().subscribe(function(newRange) {
34+
if (!newRange) return;
35+
console.log(`Price Range is now from ${newRange.bottom} to ${newRange.top}`);
36+
});
37+
```
38+
39+
## Developing
40+
41+
### Running Locally
42+
43+
```shell
44+
npm install
45+
npm run dev
46+
```
47+
48+
Visit `localhost:5173` in the browser.
49+
50+
### Compiling
51+
52+
```shell
53+
npm run compile
54+
```
55+
56+
Check the output in the `dist` folder.

compile.mjs

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import { dirname, resolve } from 'node:path';
2+
import { copyFileSync, existsSync, mkdirSync, writeFileSync } from 'node:fs';
3+
import { build, defineConfig } from 'vite';
4+
import { fileURLToPath } from 'url';
5+
import { generateDtsBundle } from 'dts-bundle-generator';
6+
7+
function buildPackageJson(packageName) {
8+
/*
9+
Define the contents of the package's package.json here.
10+
*/
11+
return {
12+
name: packageName,
13+
"author": "Mark Silverwood",
14+
"repository": {
15+
"type": "git",
16+
"url": "https://github.com/slicedsilver/lwc-plugin-visible-price-range-util.git"
17+
},
18+
version: '0.1.0',
19+
keywords: ['lwc-plugin', 'lightweight-charts'],
20+
type: 'module',
21+
main: `./${packageName}.umd.cjs`,
22+
module: `./${packageName}.js`,
23+
types: `./${packageName}.d.ts`,
24+
exports: {
25+
import: {
26+
types: `./${packageName}.d.ts`,
27+
default: `./${packageName}.js`,
28+
},
29+
require: {
30+
types: `./${packageName}.d.cts`,
31+
default: `./${packageName}.umd.cjs`,
32+
},
33+
},
34+
};
35+
}
36+
37+
const __filename = fileURLToPath(import.meta.url);
38+
const currentDir = dirname(__filename);
39+
40+
const pluginFileName = 'visible-price-range-util';
41+
const pluginFile = resolve(currentDir, 'src', `${pluginFileName}.ts`);
42+
43+
const pluginsToBuild = [
44+
{
45+
filepath: pluginFile,
46+
exportName: 'lwc-plugin-visible-price-range-util',
47+
name: 'VisiblePriceRangeUtil',
48+
},
49+
];
50+
51+
const compiledFolder = resolve(currentDir, 'dist');
52+
if (!existsSync(compiledFolder)) {
53+
mkdirSync(compiledFolder);
54+
}
55+
56+
const buildConfig = ({
57+
filepath,
58+
name,
59+
exportName,
60+
formats = ['es', 'umd'],
61+
}) => {
62+
return defineConfig({
63+
publicDir: false,
64+
build: {
65+
outDir: `dist`,
66+
emptyOutDir: true,
67+
copyPublicDir: false,
68+
lib: {
69+
entry: filepath,
70+
name,
71+
formats,
72+
fileName: exportName,
73+
},
74+
rollupOptions: {
75+
external: ['lightweight-charts', 'fancy-canvas'],
76+
output: {
77+
globals: {
78+
'lightweight-charts': 'LightweightCharts',
79+
},
80+
},
81+
},
82+
},
83+
});
84+
};
85+
86+
const startTime = Date.now().valueOf();
87+
console.log('⚡️ Starting');
88+
console.log('Bundling the plugin...');
89+
const promises = pluginsToBuild.map(file => {
90+
return build(buildConfig(file));
91+
});
92+
await Promise.all(promises);
93+
console.log('Generating the package.json file...');
94+
pluginsToBuild.forEach(file => {
95+
const packagePath = resolve(compiledFolder, 'package.json');
96+
const content = JSON.stringify(
97+
buildPackageJson(file.exportName),
98+
undefined,
99+
4
100+
);
101+
writeFileSync(packagePath, content, { encoding: 'utf-8' });
102+
});
103+
console.log('Generating the typings files...');
104+
pluginsToBuild.forEach(file => {
105+
try {
106+
const esModuleTyping = generateDtsBundle([
107+
{
108+
filePath: `./typings/${pluginFileName}.d.ts`,
109+
},
110+
]);
111+
const typingFilePath = resolve(compiledFolder, `${file.exportName}.d.ts`);
112+
writeFileSync(typingFilePath, esModuleTyping.join('\n'), {
113+
encoding: 'utf-8',
114+
});
115+
copyFileSync(typingFilePath, resolve(compiledFolder, `${file.exportName}.d.cts`));
116+
} catch (e) {
117+
console.error('Error generating typings for: ', file.exportName);
118+
}
119+
});
120+
const endTime = Date.now().valueOf();
121+
console.log(`🎉 Done (${endTime - startTime}ms)`);

index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<!-- redirect to example page -->
5+
<meta http-equiv="refresh" content="0; URL=src/example/" />
6+
</head>
7+
</html>

0 commit comments

Comments
 (0)