Skip to content

Commit

Permalink
Merge pull request #11 from eik-lib/rework
Browse files Browse the repository at this point in the history
feat: Rework module to suite current functionality of Eik
  • Loading branch information
trygve-lie committed Mar 10, 2021
2 parents 6a613a9 + 9223c61 commit 70ac9e0
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 484 deletions.
7 changes: 6 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
coverage
tap-snapshots
node_modules
modules
utils
dist
tmp
28 changes: 13 additions & 15 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
{
"extends": [
"airbnb-base",
"prettier"
],
"plugins": [
"prettier"
],
"env": {
"es6": true,
"node": true,
"browser": false
},
"parserOptions": {
"ecmaVersion": 2020
},
"extends": "airbnb-base",
"rules": {
"strict": [
0,
"global"
],
"class-methods-use-this": [
0
]
"indent": [1, 4],
"import/prefer-default-export": [0],
"import/extensions": [0]
}
}
}
94 changes: 50 additions & 44 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,56 @@
name: Release and Publish

on:
push:
branches:
- master
- alpha
- beta
- next
push:
branches:
- master
- alpha
- beta
- next

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 14.x
- name: npm install
run: |
npm install
- name: npm lint
run: |
npm run lint
- name: npm test
run: |
npm run test:ci
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 14.x
- name: npm install
run: |
npm install
env:
CI: true
- name: npm run lint
run: |
npm run lint
env:
CI: true
- name: npm test
run: |
npm test
env:
CI: true

release:
name: Release
runs-on: ubuntu-latest
needs: [test]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 14.x
- name: npm install
run: |
npm install
- name: npx semantic-release
run: |
npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
release:
name: Release
runs-on: ubuntu-latest
needs: [test]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 14.x
- name: npm install
run: |
npm install
- name: npx semantic-release
run: |
npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
17 changes: 3 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
name: Run Lint and Tests

on:
push:
branches-ignore:
- master
- alpha
- beta
on: push

jobs:
build:
Expand All @@ -23,15 +18,9 @@ jobs:
- name: npm install
run: |
npm install
env:
CI: true
- name: npm lint
run: |
npm run lint
env:
CI: true
- name: npm test
- name: Run tests
run: |
npm run test:ci
env:
CI: true
npm test
172 changes: 45 additions & 127 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,140 +1,58 @@
'use strict';

const { readFileSync } = require('fs');
const { join } = require('path');
const pkgDir = require('pkg-dir');
const { AssetJs, AssetCss } = require('@podium/utils');
const { schemas } = require('@eik/common');

const scripts = Symbol('assets:scripts');
const styles = Symbol('assets:styles');

function validateMeta(meta) {
const { value, error } = schemas.assets(meta);

if (error) {
throw new Error(error);
import { helpers } from '@eik/common';
import { join } from 'path';

const isUrl = (value = '') => value.startsWith('http');

export default class EikNodeClient {
constructor({
development = false,
base = '',
path = process.cwd(),

} = {}) {
this.pDevelopment = development;
this.pConfig = {};
this.pPath = path;
this.pBase = base;
}

return value;
}

function readAssetsJson(path) {
const metaPath = join(pkgDir.sync(), path);
const metaString = readFileSync(metaPath, 'utf8');
return validateMeta(JSON.parse(metaString));
}

module.exports = class Client {
constructor({ js, css, development = false, path = './assets.json' }) {
const meta = readAssetsJson(path);

const {
server,
js: { input: jsInput, options: jsOptions },
css: { input: cssInput, options: cssOptions },
organisation,
name,
version,
} = meta;
this[scripts] = [];
this[styles] = [];

if (development) {
if (js) {
let script = {};
if (typeof js !== 'string') {
script = new AssetJs(js);
} else {
script = new AssetJs({
type: 'module',
value: js,
...jsOptions,
});
}

this[scripts].push(script);
}
if (css) {
let style = {};
if (typeof css !== 'string') {
style = new AssetCss(css);
} else {
style = new AssetCss({ value: css, ...cssOptions });
}
async load() {
this.pConfig = await helpers.getDefaults(this.pPath);
}

this[styles].push(style);
}
return;
}
get name() {
if (this.pConfig.name) return this.pConfig.name;
return '';
}

if (jsInput) {
this[scripts].push(
new AssetJs({
type: 'module',
...jsOptions,
value:
server +
join(
'/',
organisation,
'pkg',
name,
version,
`/main/index.js`,
),
}),
);
this[scripts].push(
new AssetJs({
...jsOptions,
type: 'iife',
nomodule: true,
value:
server +
join(
'/',
organisation,
'pkg',
name,
version,
`/ie11/index.js`,
),
}),
);
}
if (cssInput) {
this[styles].push(
new AssetCss({
...cssOptions,
value:
server +
join(
'/',
organisation,
'pkg',
name,
version,
`/main/index.css`,
),
}),
);
}
get version() {
if (this.pConfig.version) return this.pConfig.version;
return '';
}

get js() {
return this[scripts];
get type() {
if (this.pConfig.type && this.pConfig.type === 'package') return 'pkg';
if (this.pConfig.type) return this.pConfig.type;
return '';
}

get css() {
return this[styles];
get server() {
if (this.pConfig.server) return this.pConfig.server;
return '';
}

get scripts() {
return this.js.map(s => s.toHTML()).join('\n');
get pathname() {
return join('/', this.type, this.name, this.version);
}

get styles() {
return this.css.map(s => s.toHTML()).join('\n');
file(file = '') {
if (this.pDevelopment) {
if (isUrl(this.pBase)) {
const base = new URL(this.pBase);
return new URL(join(base.pathname, file), base).href;
}
return join(this.pBase, file);
}
return new URL(join(this.pathname, file), this.server).href;
}
};
}
Loading

0 comments on commit 70ac9e0

Please sign in to comment.