Skip to content

Commit

Permalink
Merge pull request #16 from julienetie/feature/ts-definitions
Browse files Browse the repository at this point in the history
Feature/ts definitions
  • Loading branch information
julienetie authored Jan 12, 2024
2 parents e3c449a + 147dd78 commit 2ff1577
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ A more practical alternative to [localStorage](https://developer.mozilla.org/en-
- Set and get single or multiple entries
- Delete single, multiple or all entries
- No versioning
- 2.47KB minified
- 2.51KB minified

E.g.
```javascript
Expand Down
51 changes: 37 additions & 14 deletions create-distribution.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs/promises'
import path, { dirname } from 'path'
import { minify } from "terser";

import { minify } from 'terser'
import { execSync } from 'child_process'

const currentFilePath = (new URL(import.meta.url)).pathname
const __dirname = dirname(currentFilePath)
Expand All @@ -11,28 +11,40 @@ const paths = {
readmeSrc: path.join(__dirname, './src/_readme.md'),
readmeRoot: path.join(__dirname, './README.md'),
source: path.join(__dirname, './src/db64.js'),
sourceTSdef: path.join(__dirname, './src/db64.d.ts'),
tsDefDist: path.join(__dirname, './dist/db64.d.ts'),
tsDefMapDist: path.join(__dirname, './dist/db64.d.ts.map'),
cjsDist: path.join(__dirname, './dist/db64.cjs'),
esDist: path.join(__dirname, './dist/db64.js'),
esMinDist: path.join(__dirname, './dist/db64.min.js'),
esMinMapDist: path.join(__dirname, './dist/db64.min.map'),
cjsMinDist: path.join(__dirname, './dist/db64-cjs.min.js'),
cjsMinMapDist: path.join(__dirname, './dist/db64-cjs.min.map'),
cjsMinMapDist: path.join(__dirname, './dist/db64-cjs.min.map')
}




const createCJS = async () => {
try {
const data = await fs.readFile(paths.source, 'utf8')
const tsDefData = await fs.readFile(paths.sourceTSdef, 'utf8')
const readmeSrc = await fs.readFile(paths.readmeSrc, 'utf8')

const insertCJSImport = data.replace(/export default db64/g, 'module.exports = db64')

const minifiedESData = await minify(data, { sourceMap: true })
const minifiedCJSData = await minify(insertCJSImport, { sourceMap: true })
const minifiedESData = await minify(data, {
sourceMap: {
url: path.basename(paths.esMinMapDist)
}
})
const minifiedCJSData = await minify(insertCJSImport, {
sourceMap: {
url: path.basename(paths.cjsMinMapDist)
}
})


// ES
/*
ES */
await fs.writeFile(paths.esDist, data, 'utf8')
console.info(`Created ${paths.esDist}`)

Expand All @@ -41,10 +53,22 @@ const createCJS = async () => {
console.info(`Created ${paths.esMinDist}`)

// ES Map
// await fs.writeFile(paths.esMinMapDist, minifiedESData.map, 'utf8')
// console.info(`Created ${paths.esMinMapDist}`)
await fs.writeFile(paths.esMinMapDist, minifiedESData.map, 'utf8')
console.info(`Created ${paths.esMinMapDist}`)

// CJS

/*
TS Definitions */
await fs.writeFile(paths.tsDefDist, tsDefData, 'utf8')
console.info(`Created ${paths.tsDefDist}`)

// TS Definitions Map
const tsc = './node_modules/.bin/tsc'
execSync(`${tsc} --project tsconfig.json`, { stdio: 'inherit' })
console.info(`Created ${paths.tsDefMapDist}`)

/*
CJS */
await fs.writeFile(paths.cjsDist, insertCJSImport, 'utf8')
console.info(`Created ${paths.cjsDist}`)

Expand All @@ -53,8 +77,8 @@ const createCJS = async () => {
console.info(`Created ${paths.cjsMinDist}`)

// CJS Map
// await fs.writeFile(paths.cjsMinMapDist, minifiedCJSData.map, 'utf8')
// console.info(`Created ${paths.cjsMinMapDist}`)
await fs.writeFile(paths.cjsMinMapDist, minifiedCJSData.map, 'utf8')
console.info(`Created ${paths.cjsMinMapDist}`)

const stats = await fs.stat(paths.esMinDist)

Expand All @@ -63,7 +87,6 @@ const createCJS = async () => {
const readmeWithSize = readmeSrc.replace(/{{ size }}/g, `${fileSizeInKB.toFixed(2)}KB`)
await fs.writeFile(paths.readmeRoot, readmeWithSize, 'utf8')
console.info(`Created ${paths.readmeRoot}`)

} catch (err) {
console.error('Error:', err)
}
Expand Down
3 changes: 2 additions & 1 deletion dist/db64-cjs.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/db64-cjs.min.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions dist/db64.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export default db64;
declare namespace db64 {
export function create(name: any, storeNames: any): Promise<void | {
create: (name: any, storeNames: any) => Promise<void | any>;
use: (name: any, storeName: any) => {
set: (key: any, value: any) => Promise<any>;
setEntries: (value: any) => Promise<any>;
get: (key: any) => Promise<any>;
getEntries: (keys: any) => Promise<any>;
delete: (keys: any) => Promise<any>;
};
clear: (name: any, storeName: any) => Promise<any>;
delete: (name: any) => Promise<any>;
}>;
export function use(name: any, storeName: any): {
set: (key: any, value: any) => Promise<any>;
setEntries: (value: any) => Promise<any>;
get: (key: any) => Promise<any>;
getEntries: (keys: any) => Promise<any>;
delete: (keys: any) => Promise<any>;
};
export function clear(name: any, storeName: any): Promise<any>;
export function _delete(name: any): Promise<any>;
export { _delete as delete };
}
//# sourceMappingURL=db64.d.ts.map
1 change: 1 addition & 0 deletions dist/db64.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion dist/db64.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2ff1577

Please sign in to comment.