Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tram-One, now with Types! Typescript! v11.0.0 #175

Merged
merged 28 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
dc2bf8c
Initial Pass at migrating to Typescript
JRJurman Oct 21, 2021
a43298e
re-add lint (placeholder)
JRJurman Oct 21, 2021
e56dc64
migrate test app to ts as well
JRJurman Oct 21, 2021
64dab27
type definitions!
JRJurman Oct 22, 2021
1b76e38
npm ci in pipeline
JRJurman Oct 22, 2021
1ca3030
11.0.0
JRJurman Oct 22, 2021
349d159
remove manual type checks
JRJurman Oct 22, 2021
839e459
add eslint typescript config
JRJurman Oct 22, 2021
029217e
fix lint, add comments to config, update test files to ts
JRJurman Oct 23, 2021
fdcadee
cleanup jsdocs, more types, add unit test for root effect
JRJurman Oct 24, 2021
30f8370
use prettier
JRJurman Oct 24, 2021
f18e844
fix docstring, update dependency name in config
JRJurman Oct 24, 2021
7e8d7fd
clean up layout for tasks test component
JRJurman Oct 24, 2021
c6842cf
Update README
JRJurman Oct 24, 2021
c8a677e
more strict typing
JRJurman Oct 25, 2021
771d55e
formatting for test app
JRJurman Oct 25, 2021
ca74d2a
Fix app by being dependent on loading
JRJurman Oct 29, 2021
31024f5
fix performance test ts
JRJurman Oct 29, 2021
8195f6b
use functions for node filter
JRJurman Oct 30, 2021
da0e1fb
typescript build config
JRJurman Nov 3, 2021
74e2788
use parcel 2.0
JRJurman Nov 3, 2021
2edd8c2
strictNullChecks, remove domino
JRJurman Nov 6, 2021
d7727f9
rearrange and expose types in main export
JRJurman Nov 8, 2021
1df7179
strict ruleset, update test files to verify type
JRJurman Nov 8, 2021
0968852
change to type module
JRJurman Nov 8, 2021
2914e36
update runkit example
JRJurman Nov 8, 2021
eb88229
update eslint, remove logs, expose TramOneElement
JRJurman Nov 10, 2021
adef448
fixes for code coverage
JRJurman Nov 10, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
fingerprints:
- "64:3e:d4:d8:4b:95:68:79:d3:3b:ab:b1:5c:fa:2d:3d"

- run: npm install
- run: npm ci
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this project originally predated npm ci, but now that it exists, we should be using that, and not regenerating the lock file on every PR.


- save_cache:
paths:
Expand Down
51 changes: 51 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
env: {
// allow document, window, etc (these are expected as a frontend-library)
browser: true,
},
plugins: ['jest', '@typescript-eslint'],
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],
rules: {
// some of the dependencies do not support module imports... yet
'@typescript-eslint/no-var-requires': 'off',
// as a framework, we have to sometimes just expect anything
'@typescript-eslint/no-explicit-any': 'off',
// we shouldn't have console logs in our project
'no-console': 'error',
},
overrides: [
// allow module.exports for config, testing, and docs
{
files: [
'**/*.cjs', // any file with the cjs extension
'./*.js', // top level config
'./docs/runkit_example.js', // runkit example
'./integration-tests/broken-app/**.js', // tests that still need runtime import/export
],
env: {
commonjs: true,
},
},

// configure test files to be in the jest environment
{
files: ['integration-tests/**/*', 'performance-tests/**/*'],
env: {
jest: true,
},
rules: {
'@typescript-eslint/no-empty-function': 'off',
},
},

// local scripts are expected to run on local machines with node
{
files: ['dev-scripts/**/*.js'],
env: {
node: true,
},
},
],
};
13 changes: 1 addition & 12 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,9 @@ dist
# Coverage Report
coverage

# docma docs
docs/website

# Logs
logs
*.log
*.log.*

# Dependency directory
node_modules

# SSL certificates
.ssl

Comment on lines -18 to -20
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was most certainly an artifact of when we had the website hosted from this repo, since that is no longer a thing, we can remove this

# parcel test app files
dist
.parcel-cache
.parcel-dist
5 changes: 5 additions & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
useTabs: true,
singleQuote: true,
printWidth: 120,
};
44 changes: 26 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
</a>
</div>
<div align="center">
<a href="https://www.npmjs.com/package/tram-one">
<img src="https://github.com/Tram-One/tram-one/raw/master/docs/badges/cjs.svg?sanitize=true" alt="Common JS build size">
<a href="https://unpkg.com/tram-one/dist/tram-one.cjs">
<img src="https://github.com/Tram-One/tram-one/raw/master/docs/badges/cjs.svg?sanitize=true" alt="Common JS build">
</a>
<a href="https://unpkg.com/tram-one/dist/tram-one.js">
<img src="https://github.com/Tram-One/tram-one/raw/master/docs/badges/umd.svg?sanitize=true" alt="UMD build">
</a>
<a href="https://unpkg.com/tram-one/dist/tram-one.umd.js">
<img src="https://github.com/Tram-One/tram-one/raw/master/docs/badges/umd.svg?sanitize=true" alt="UMD build size">
<a href="https://unpkg.com/tram-one/dist/tram-one.mjs">
<img src="https://github.com/Tram-One/tram-one/raw/master/docs/badges/umd.svg?sanitize=true" alt="ES Module build">
</a>
<a href="https://discord.gg/dpBXAQC">
<img src="https://img.shields.io/badge/discord-join-83ded3.svg?style=flat" alt="Join Discord">
Expand All @@ -30,6 +33,7 @@ Modern View Framework for Vanilla Javascript
<br>

## Summary

Tram-One is a Modern View Framework that has advance features like hooks, observables, and JSX-like template components, all in plain vanilla javascript.

Tram-One takes inspiration from frameworks like Choo, React, and Svelte, and provides a rich feature set without additional libraries.
Expand All @@ -39,32 +43,36 @@ Tram-One takes inspiration from frameworks like Choo, React, and Svelte, and pro
[If you have any questions from this page or about Tram-One, or just want to say hi, join our Discord!](https://discord.gg/dpBXAQC)

```javascript
import {registerHtml, start} from 'tram-one'
import { registerHtml, start } from 'tram-one';

const html = registerHtml()
const html = registerHtml();
const home = () => {
return html`
<main>
<h1> Tram-One </h1>
<h2>
A Modern View Framework
For Vanilla Javascript
</h2>
</main>
`
}

start('#app', home)
return html`
<main>
<h1>Tram-One</h1>
<h2>A Modern View Framework For Vanilla Javascript</h2>
</main>
`;
};

start('#app', home);
```

### Why?

Tram-One is a project that emphasizes vanilla JS and HTML syntax, while providing the features of modern JS frameworks. It is born out of love of the JSX syntax, and an attempt to build something unique with existing open source libraries.

While Tram-One makes use of many dependencies, an effort has been made to expose those dependencies in a way that will hopefully
encourage other developers to mix-and-match their own libraries, make improvements, and potentially
build off of what is here to make their own front-end frameworks!

### Is Tram-One for Javascript or Typescript?

Both! While the source code and type checking exist in Typescript, smart editors (such as Visual Studio Code), will make use of
the Typescript annotations regardless of what language you work in!

Comment on lines +69 to +73
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love to make a more general FAQ and Principles section in the Tram-One Website, but in the interim, this will have to do 😅

## This Repo and the Tram-One Org

This repo contains the main Tram-One framework, which can be installed and
used to make web-apps. [The Tram-One org](https://github.com/Tram-One)
includes many of the dependencies as well as the websites and generators for the project.
Expand Down
31 changes: 10 additions & 21 deletions configs/rollup.config.cjs.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
const filesize = require('rollup-plugin-filesize')
const commonjs = require('rollup-plugin-commonjs')
const pkg = require('../package.json')
import filesize from 'rollup-plugin-filesize';
import commonjs from 'rollup-plugin-commonjs';
import pkg from '../package.json';
import typescript from '@rollup/plugin-typescript';

const external = Object.keys(pkg.dependencies)
.concat([
'type/function/ensure',
'type/object/ensure',
'type/string/ensure',
'type/value/ensure'
])

const plugins = [
commonjs(),
filesize()
]
const plugins = [typescript(), commonjs(), filesize()];

export default {
input: 'src/tram-one',
external,
input: 'src/tram-one.ts',
plugins,
output: {
file: pkg.commonjs,
exports: 'named',
format: 'cjs',
interop: false
}
}
interop: 'auto',
sourcemap: true,
},
};
25 changes: 25 additions & 0 deletions configs/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import filesize from 'rollup-plugin-filesize';
import dts from 'rollup-plugin-dts';

import pkg from '../load-package.cjs';
import typescript from '@rollup/plugin-typescript';

export default [
{
input: 'src/tram-one.ts',
plugins: [typescript(), filesize()],
output: {
file: pkg.module,
format: 'es',
sourcemap: true,
},
},
{
input: 'src/tram-one.ts',
plugins: [dts()],
output: {
file: pkg.types,
format: 'es',
},
},
];
36 changes: 17 additions & 19 deletions configs/rollup.config.umd.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
const builtins = require('rollup-plugin-node-builtins')
const commonjs = require('rollup-plugin-commonjs')
const filesize = require('rollup-plugin-filesize')
const globals = require('rollup-plugin-node-globals')
const resolve = require('rollup-plugin-node-resolve')
const { terser } = require('rollup-plugin-terser')
// const sizes = require('rollup-plugin-sizes')
import builtins from 'rollup-plugin-node-builtins';
import commonjs from 'rollup-plugin-commonjs';
import filesize from 'rollup-plugin-filesize';
import globals from 'rollup-plugin-node-globals';
import resolve from 'rollup-plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
import typescript from '@rollup/plugin-typescript';
// import sizes from 'rollup-plugin-sizes'

const pkg = require('../package.json')
import pkg from '../package.json';

const plugins = [
typescript(),
resolve({
preferBuiltins: true,
browser: true
browser: true,
}),
builtins(),
commonjs(),
globals(),
builtins(),
terser(),
// sizes(), // useful for finding large dependencies
filesize()
]
filesize(),
];

// domino is a package used by belit to support server side rendering,
// it does not need to be included in browser builds, which will have document
export default {
input: 'src/tram-one',
external: ['domino'],
input: 'src/tram-one.ts',
output: {
name: 'tram-one',
exports: 'named',
file: pkg.umd,
globals: { domino: 'domino' },
format: 'umd'
format: 'umd',
},
plugins
}
plugins,
};
10 changes: 5 additions & 5 deletions dev-scripts/badge.js → dev-scripts/badge.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = (label, value) => {
const labelWidth = label.length * 11
const valueWidth = 58 + (value.length * 4)
const labelOffset = 16.5
const labelWidth = label.length * 11;
const valueWidth = 58 + value.length * 4;
const labelOffset = 16.5;
return `<svg xmlns="http://www.w3.org/2000/svg" width="${valueWidth}" height="20">
<linearGradient id="b" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1"/>
Expand All @@ -22,5 +22,5 @@ module.exports = (label, value) => {
<text x="59" y="14">${value}</text>
</g>
</svg>
`
}
`;
};
27 changes: 27 additions & 0 deletions dev-scripts/build-size-badges.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const path = require('path');
const fs = require('fs');
const badge = require('./badge.cjs');

const buildPath = 'dist';
const destPath = 'docs/badges';
const units = ['B', 'kB', 'MB', 'GB'];

// get filesize and transform to correct unit
const getSize = (fileName) => {
const bytes = fs.statSync(path.resolve(buildPath, fileName)).size;
const n = Math.floor(Math.log(bytes) / Math.log(1024));
const formatted = (bytes / 1024 ** n).toFixed(2);
return `${formatted} ${units[n]}`;
};

// generate an SVG string and write it to dest
const generateBadge = (label, fileName) => {
const value = getSize(fileName);
const svg = badge(label, value);
const dest = path.resolve(destPath, `${label}.svg`);
fs.writeFile(dest, svg, (err) => err && process.stdout.write(err));
};

generateBadge('cjs', 'tram-one.cjs');
generateBadge('umd', 'tram-one.js');
generateBadge('mjs', 'tram-one.mjs');
26 changes: 0 additions & 26 deletions dev-scripts/build-size-badges.js

This file was deleted.

4 changes: 2 additions & 2 deletions docs/badges/cjs.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions docs/badges/mjs.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading