-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from eik-lib/rework
feat: Rework module to suite current functionality of Eik
- Loading branch information
Showing
9 changed files
with
167 additions
and
484 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
coverage | ||
tap-snapshots | ||
node_modules | ||
modules | ||
utils | ||
dist | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; | ||
} |
Oops, something went wrong.