Skip to content

Commit

Permalink
Add build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjoDiaz committed Jul 21, 2020
1 parent 2fac0f7 commit b1dc381
Show file tree
Hide file tree
Showing 7 changed files with 260 additions and 15 deletions.
28 changes: 28 additions & 0 deletions build.deno.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env node

const path = require('path');
const { mkdirSync, readdirSync, lstatSync, readFileSync, writeFileSync } = require('fs');

function processDir(src, dest) {
mkdirSync(dest, { recursive: true });

readdirSync(src)
.forEach(name => {
const currentPath = path.join(src, name);
const destPath = path.join(dest, name);
const currentStats = lstatSync(currentPath);
if (currentStats.isDirectory()) {
processDir(currentPath, destPath);
return;
}

writeFileSync(
destPath,
readFileSync(currentPath).toString().replace(/from '(\.[.\\/-\w]+)'/gm, "from '$1.ts'"),
);
});
}

const src = process.argv[2]; // './src'
const dest = process.argv[3]; // './dist'
processDir(src, dest);
26 changes: 26 additions & 0 deletions build.mjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env node

const path = require('path');
const { readdirSync, lstatSync, readFileSync, writeFileSync, unlinkSync } = require('fs');

function processDir(src) {
readdirSync(src)
.filter(name => !/.d.ts$/.test(name))
.forEach(name => {
const currentPath = path.join(src, name);
const currentStats = lstatSync(currentPath);
if (currentStats.isDirectory()) {
processDir(currentPath);
return;
}

writeFileSync(
currentPath.replace(/\.js$/, '.mjs'),
readFileSync(currentPath).toString().replace(/from '(\.[.\\/-\w]+)'/gm, "from '$1.mjs'"),
);
unlinkSync(currentPath);
});
}

const src = process.argv[2]; // './dist'
processDir(src);
175 changes: 166 additions & 9 deletions package-lock.json

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

20 changes: 16 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"name": "jsonparse",
"description": "Streaming JSON parser in Javascript for Node.js and the browser",
"version": "0.0.1",
"main": "./dist/index.js",
"main": "./dist/cjs/index.js",
"module": "./dist/mjs/index.js",
"browser": "./dist/umd/index.js",
"types": "./dist/index.d.ts",
"author": "Juanjo Diaz <[email protected]>",
"repository": {
Expand All @@ -11,15 +13,25 @@
},
"bugs": "https://github.com/juanjoDiaz/jsonparse2/issues",
"devDependencies": {
"@types/node": "^14.0.23",
"tap": "^14.10.7"
"@types/node": "^14.0.24",
"rollup": "^2.22.1",
"rollup-plugin-typescript2": "^0.27.1",
"tap": "^14.10.7",
"typescript": "^3.9.7"
},
"scripts": {
"build:deno": "node build.deno.js ./src ./dist/deno",
"build:umd": "rollup -c",
"build:cjs": "tsc --module commonjs --outDir ./dist/cjs",
"build:mjs": "tsc --module esnext --outDir ./dist/mjs && node build.mjs.js ./dist/mjs",
"build": "npm run build:deno && npm run build:umd && npm run build:cjs && npm run build:mjs",
"dev": "rollup -c -w",
"test": "tap test/*.ts"
},
"license": "MIT",
"tags": [
"json",
"stream"
]
],
"dependencies": {}
}
22 changes: 22 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import typescript from 'rollup-plugin-typescript2';
import pkg from './package.json';

export default [
{
input: 'src/index.ts',
output: {
file: pkg.browser,
format: 'umd',
name: 'jsonparse'
},
plugins: [
typescript({
tsconfigOverride: {
compilerOptions: {
target: "es5",
}
}
})
]
},
];
2 changes: 1 addition & 1 deletion src/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const defaultOpts: TokenizerOptions = {
numberBufferSize: 0,
};

export default class Parser {
export default class Tokenizer {
private state = TokenizerStates.START;

private bufferedString: StringBuilder;
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"target": "es6",
"module": "ES2020",
"module": "ESNext",
"lib": ["es2020", "dom"],
"declaration": true,
"outDir": "dist",
Expand Down

0 comments on commit b1dc381

Please sign in to comment.