Better packaging
This commit is contained in:
parent
fc23d1b779
commit
6408493ea3
|
@ -1,16 +0,0 @@
|
||||||
import * as fs from 'fs';
|
|
||||||
|
|
||||||
const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf-8'));
|
|
||||||
|
|
||||||
for (let f of fs.readdirSync('dist')) {
|
|
||||||
const prefix = `syndicate-${pkg.version}`;
|
|
||||||
if (f.startsWith(prefix)) {
|
|
||||||
const linkname = `dist/syndicate${f.substring(prefix.length)}`;
|
|
||||||
try {
|
|
||||||
fs.unlinkSync(linkname);
|
|
||||||
} catch (e) {
|
|
||||||
if (e.code !== 'ENOENT') throw e;
|
|
||||||
}
|
|
||||||
fs.symlinkSync(f, linkname);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env -S node --es-module-specifier-resolution=node
|
#!/usr/bin/env node
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
// @syndicate-lang/core, an implementation of Syndicate dataspaces for JS.
|
// @syndicate-lang/core, an implementation of Syndicate dataspaces for JS.
|
||||||
// Copyright (C) 2016-2021 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
// Copyright (C) 2016-2021 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
import { Dataspace, Skeleton, Ground, Record, Discard, Capture, Observe } from '../lib/index';
|
const { Dataspace, Skeleton, Ground, Record, Discard, Capture, Observe } = require('../dist/syndicate.js');
|
||||||
const __ = Discard._instance;
|
const __ = Discard._instance;
|
||||||
const _$ = Capture(__);
|
const _$ = Capture(__);
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ const N = 100000;
|
||||||
|
|
||||||
console.time('box-and-client-' + N.toString());
|
console.time('box-and-client-' + N.toString());
|
||||||
|
|
||||||
export function boot(thisFacet) {
|
function boot(thisFacet) {
|
||||||
thisFacet.spawn('box', function (thisFacet) {
|
thisFacet.spawn('box', function (thisFacet) {
|
||||||
thisFacet.declareField(this, 'value', 0);
|
thisFacet.declareField(this, 'value', 0);
|
||||||
thisFacet.addEndpoint(() => {
|
thisFacet.addEndpoint(() => {
|
||||||
|
@ -87,4 +87,6 @@ export function boot(thisFacet) {
|
||||||
console.timeEnd('box-and-client-' + N.toString()));
|
console.timeEnd('box-and-client-' + N.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports.boot = boot;
|
||||||
|
|
||||||
new Ground(boot).start();
|
new Ground(boot).start();
|
||||||
|
|
|
@ -11,12 +11,12 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepare": "npm run compile && npm run rollup",
|
"prepare": "npm run compile && npm run rollup",
|
||||||
"compile": "../../node_modules/.bin/tsc --incremental",
|
"compile": "../../node_modules/.bin/tsc --incremental",
|
||||||
"rollup": "../../node_modules/.bin/rollup -c syndicate.dist.js && node ./dist-link.js",
|
"rollup": "../../node_modules/.bin/rollup -c",
|
||||||
"test": "../../node_modules/.bin/jest",
|
"test": "../../node_modules/.bin/jest",
|
||||||
"cover": "../../node_modules/.bin/nyc --reporter=html ../../node_modules/.bin/jest"
|
"cover": "../../node_modules/.bin/nyc --reporter=html ../../node_modules/.bin/jest"
|
||||||
},
|
},
|
||||||
"type": "module",
|
"main": "dist/syndicate.js",
|
||||||
"main": "lib/index.js",
|
"module": "lib/index.js",
|
||||||
"types": "lib/index.d.ts",
|
"types": "lib/index.d.ts",
|
||||||
"author": "Tony Garnock-Jones <tonyg@leastfixedpoint.com>",
|
"author": "Tony Garnock-Jones <tonyg@leastfixedpoint.com>",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
import resolve from '@rollup/plugin-node-resolve';
|
||||||
|
import { terser } from 'rollup-plugin-terser';
|
||||||
|
|
||||||
|
function distfile(insertion) {
|
||||||
|
const f = `syndicate${insertion}.js`;
|
||||||
|
return `dist/${f}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function umd(insertion, extra) {
|
||||||
|
return {
|
||||||
|
file: distfile(insertion),
|
||||||
|
format: 'umd',
|
||||||
|
name: 'Syndicate',
|
||||||
|
globals: {
|
||||||
|
'crypto': 'crypto',
|
||||||
|
},
|
||||||
|
... (extra || {})
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function es6(insertion, extra) {
|
||||||
|
return {
|
||||||
|
file: distfile('.es6' + insertion),
|
||||||
|
format: 'es',
|
||||||
|
... (extra || {})
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default [
|
||||||
|
{
|
||||||
|
input: 'lib/index.js',
|
||||||
|
plugins: [
|
||||||
|
resolve({
|
||||||
|
preferBuiltins: false,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
output: [
|
||||||
|
umd(''),
|
||||||
|
umd('.min', { plugins: [terser()] }),
|
||||||
|
],
|
||||||
|
}, {
|
||||||
|
input: 'lib/index.js',
|
||||||
|
plugins: [
|
||||||
|
resolve({
|
||||||
|
moduleDirectories: ['stubs', 'node_modules'],
|
||||||
|
preferBuiltins: false,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
output: [
|
||||||
|
es6(''),
|
||||||
|
es6('.min', { plugins: [terser()] }),
|
||||||
|
],
|
||||||
|
}
|
||||||
|
];
|
|
@ -1,4 +1,4 @@
|
||||||
import fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as S from '../syntax/index.js';
|
import * as S from '../syntax/index.js';
|
||||||
import { Substitution } from '../syntax/index.js';
|
import { Substitution } from '../syntax/index.js';
|
||||||
import * as G from './grammar.js';
|
import * as G from './grammar.js';
|
||||||
|
|
|
@ -27,17 +27,22 @@ export function _btoa(s: string): string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function randomId(byteCount: number, hexOutput: boolean = false): string {
|
function _finish(hexOutput: boolean, buf: Uint8Array): string {
|
||||||
let buf: Uint8Array;
|
|
||||||
if (node_crypto.randomBytes !== void 0) {
|
|
||||||
buf = node_crypto.randomBytes(byteCount);
|
|
||||||
} else {
|
|
||||||
buf = new Uint8Array(byteCount);
|
|
||||||
crypto.getRandomValues(buf);
|
|
||||||
}
|
|
||||||
if (hexOutput) {
|
if (hexOutput) {
|
||||||
return Bytes.from(buf).toHex();
|
return Bytes.from(buf).toHex();
|
||||||
} else {
|
} else {
|
||||||
return _btoa(String.fromCharCode.apply(null, buf as unknown as number[])).replace(/=/g,'');
|
return _btoa(String.fromCharCode.apply(null, buf as unknown as number[])).replace(/=/g,'');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const randomId =
|
||||||
|
(typeof crypto !== 'undefined' && 'getRandomValues' in crypto)
|
||||||
|
? ((byteCount: number, hexOutput: boolean = false): string => {
|
||||||
|
const buf = new Uint8Array(byteCount);
|
||||||
|
crypto.getRandomValues(buf);
|
||||||
|
return _finish(hexOutput, buf);
|
||||||
|
})
|
||||||
|
: ((byteCount: number, hexOutput: boolean = false): string => {
|
||||||
|
let buf = node_crypto.randomBytes(byteCount);
|
||||||
|
return _finish(hexOutput, buf);
|
||||||
|
});
|
||||||
|
|
|
@ -1,41 +0,0 @@
|
||||||
import pkg from './package.json';
|
|
||||||
import resolve from '@rollup/plugin-node-resolve';
|
|
||||||
import { terser } from 'rollup-plugin-terser';
|
|
||||||
|
|
||||||
function distfile(insertion) {
|
|
||||||
const f = `syndicate-${pkg.version}${insertion}.js`;
|
|
||||||
return `dist/${f}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function umd(insertion, extra) {
|
|
||||||
return {
|
|
||||||
file: distfile(insertion),
|
|
||||||
format: 'umd',
|
|
||||||
name: 'Syndicate',
|
|
||||||
... (extra || {})
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function es6(insertion, extra) {
|
|
||||||
return {
|
|
||||||
file: distfile('.es6' + insertion),
|
|
||||||
format: 'es',
|
|
||||||
... (extra || {})
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export default {
|
|
||||||
input: 'lib/index.js',
|
|
||||||
plugins: [
|
|
||||||
resolve({
|
|
||||||
moduleDirectories: ['stubs', 'node_modules'],
|
|
||||||
preferBuiltins: false,
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
output: [
|
|
||||||
umd(''),
|
|
||||||
umd('.min', { plugins: [terser()] }),
|
|
||||||
es6(''),
|
|
||||||
es6('.min', { plugins: [terser()] }),
|
|
||||||
],
|
|
||||||
}
|
|
Loading…
Reference in New Issue