@mediatool/frontend-tools 0.0.8 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/build/build-library.js +28 -0
- package/lib/build/get-module-context.js +28 -0
- package/lib/build/index.js +13 -0
- package/lib/cli.js +23 -0
- package/lib/test/index.js +23 -0
- package/lib/test/setup-mocha.cjs +14 -0
- package/package.json +10 -3
- package/lib/cli +0 -19
- package/lib/tests/babel.config.js +0 -7
- package/lib/tests/mocha.js +0 -5
- package/lib/tests/setup.js +0 -9
- /package/{.eslintrc.js → .eslintrc.cjs} +0 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { build } from 'vite'
|
|
2
|
+
|
|
3
|
+
import getModuleContext from './get-module-context.js'
|
|
4
|
+
|
|
5
|
+
async function buildLibrary () {
|
|
6
|
+
const {
|
|
7
|
+
entry,
|
|
8
|
+
root,
|
|
9
|
+
name,
|
|
10
|
+
dependencies,
|
|
11
|
+
} = await getModuleContext()
|
|
12
|
+
|
|
13
|
+
return build({
|
|
14
|
+
root,
|
|
15
|
+
build: {
|
|
16
|
+
lib: {
|
|
17
|
+
entry,
|
|
18
|
+
name,
|
|
19
|
+
},
|
|
20
|
+
rollupOptions: {
|
|
21
|
+
external: dependencies,
|
|
22
|
+
},
|
|
23
|
+
sourcemap: true,
|
|
24
|
+
},
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default buildLibrary
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { readFile, stat } from 'node:fs/promises'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
4
|
+
import { keys, uniq } from 'ramda'
|
|
5
|
+
|
|
6
|
+
async function getModuleContext () {
|
|
7
|
+
const location = process.cwd()
|
|
8
|
+
const pkgLocation = resolve(location, './package.json')
|
|
9
|
+
const entryLocation = resolve(location, './index.js')
|
|
10
|
+
|
|
11
|
+
try {
|
|
12
|
+
await stat(pkgLocation)
|
|
13
|
+
await stat(entryLocation)
|
|
14
|
+
const pkg = JSON.parse(await readFile(pkgLocation))
|
|
15
|
+
const { name } = pkg
|
|
16
|
+
const dependencies = uniq(keys({ ...pkg.dependencies, ...pkg.peerDependencies }))
|
|
17
|
+
return {
|
|
18
|
+
entry: entryLocation,
|
|
19
|
+
root: location,
|
|
20
|
+
name,
|
|
21
|
+
dependencies,
|
|
22
|
+
}
|
|
23
|
+
} catch (e) {
|
|
24
|
+
throw new Error('Oopsie.')
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default getModuleContext
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import buildLibrary from './build-library.js'
|
|
2
|
+
|
|
3
|
+
const types = {
|
|
4
|
+
app: () => {},
|
|
5
|
+
library: buildLibrary,
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default function build (type) {
|
|
9
|
+
const fn = types[type]
|
|
10
|
+
if (!fn) throw new Error('Unknown type passed as an argument to the "build" command')
|
|
11
|
+
|
|
12
|
+
return fn()
|
|
13
|
+
}
|
package/lib/cli.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Command } from 'commander'
|
|
2
|
+
|
|
3
|
+
import build from './build/index.js'
|
|
4
|
+
import test from './test/index.js'
|
|
5
|
+
|
|
6
|
+
const program = new Command()
|
|
7
|
+
|
|
8
|
+
program
|
|
9
|
+
.name('mtft')
|
|
10
|
+
.description('Mediatool standardized tools for frontend projects')
|
|
11
|
+
.version('0.0.1')
|
|
12
|
+
|
|
13
|
+
program.command('build')
|
|
14
|
+
.description('Builds your pieces into one')
|
|
15
|
+
.argument('<type>', 'app or library')
|
|
16
|
+
.action(build)
|
|
17
|
+
|
|
18
|
+
program.command('test')
|
|
19
|
+
.description('not sure ey? run the tests then')
|
|
20
|
+
.argument('[type]', 'unit (unit tests),it (integration tests)', 'all')
|
|
21
|
+
.action(test)
|
|
22
|
+
|
|
23
|
+
program.parse()
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Mocha from 'mocha/lib/mocha.js'
|
|
2
|
+
import { handleRequires, runMocha } from 'mocha/lib/cli/run-helpers.js'
|
|
3
|
+
|
|
4
|
+
const types = {
|
|
5
|
+
all: 'test/**/*-test.*',
|
|
6
|
+
unit: 'test/unit/*-test.*',
|
|
7
|
+
it: 'test/it/*-test.*',
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default async function test (type) {
|
|
11
|
+
const spec = types[type]
|
|
12
|
+
if (!spec) throw new Error(`Unknown type ${type}`)
|
|
13
|
+
|
|
14
|
+
const plugins = await handleRequires([
|
|
15
|
+
'@mediatool/frontend-tools/lib/test/setup-mocha.cjs',
|
|
16
|
+
])
|
|
17
|
+
const opts = {
|
|
18
|
+
spec: [ spec ],
|
|
19
|
+
plugins,
|
|
20
|
+
}
|
|
21
|
+
const mocha = new Mocha(opts)
|
|
22
|
+
runMocha(mocha, opts)
|
|
23
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* eslint-env es6 */
|
|
2
|
+
/* eslint-disable import/no-extraneous-dependencies */
|
|
3
|
+
const babel = require('@babel/register').default
|
|
4
|
+
const jsdom = require('global-jsdom')
|
|
5
|
+
|
|
6
|
+
babel({
|
|
7
|
+
presets: [
|
|
8
|
+
'@babel/preset-env',
|
|
9
|
+
'@babel/preset-react',
|
|
10
|
+
'@babel/preset-typescript',
|
|
11
|
+
],
|
|
12
|
+
extensions: [ '.ts', '.tsx', '.js', '.jsx' ],
|
|
13
|
+
})
|
|
14
|
+
jsdom()
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mediatool/frontend-tools",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Common configs and tooling for bundling, testing, linting frontend modules",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
|
+
"type": "module",
|
|
7
8
|
"scripts": {
|
|
8
9
|
"test": "echo 'Testless'"
|
|
9
10
|
},
|
|
10
11
|
"bin": {
|
|
11
|
-
"
|
|
12
|
+
"mtft": "./lib/cli.js"
|
|
12
13
|
},
|
|
13
14
|
"dependencies": {
|
|
14
15
|
"@babel/core": "^7.18.9",
|
|
@@ -22,13 +23,19 @@
|
|
|
22
23
|
"@testing-library/user-event": "^14.3.0",
|
|
23
24
|
"@types/chai": "^4.3.1",
|
|
24
25
|
"@types/mocha": "^9.1.1",
|
|
26
|
+
"@vitejs/plugin-react": "^2.1.0",
|
|
25
27
|
"chai": "^4.3.6",
|
|
28
|
+
"commander": "^9.4.0",
|
|
26
29
|
"global-jsdom": "^8.5.0",
|
|
27
30
|
"jsdom": "^20.0.0",
|
|
28
|
-
"mocha": "^10.0.0"
|
|
31
|
+
"mocha": "^10.0.0",
|
|
32
|
+
"vite": "^3.1.0"
|
|
29
33
|
},
|
|
30
34
|
"peerDependencies": {
|
|
31
35
|
"react": "^18.2.0",
|
|
32
36
|
"react-dom": "^18.2.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"ramda": "^0.28.0"
|
|
33
40
|
}
|
|
34
41
|
}
|
package/lib/cli
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# arguments
|
|
4
|
-
cmd=${1}
|
|
5
|
-
|
|
6
|
-
# variables
|
|
7
|
-
mocharc_path="@mediatool/frontend-tools/lib/tests/mocha.js"
|
|
8
|
-
|
|
9
|
-
if [ "$cmd" = "test" ]; then
|
|
10
|
-
yarn mocha --config ${mocharc_path} "test/**/*-test.*"
|
|
11
|
-
elif [ "$cmd" = "test.unit" ]; then
|
|
12
|
-
yarn mocha --config ${mocharc_path} "test/unit/**/*-test.*"
|
|
13
|
-
elif [ "$cmd" = "test.unit.components" ]; then
|
|
14
|
-
yarn mocha --config ${mocharc_path} "test/unit/**/*-test.{jsx,tsx}"
|
|
15
|
-
elif [ "$cmd" = "test.unit.functions" ]; then
|
|
16
|
-
yarn mocha --config ${mocharc_path} "test/unit/**/*-test.{js,ts}"
|
|
17
|
-
elif [ "$cmd" = "test.it" ]; then
|
|
18
|
-
yarn mocha --config ${mocharc_path} "test/it/**/*-test.*"
|
|
19
|
-
fi
|
package/lib/tests/mocha.js
DELETED
package/lib/tests/setup.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/no-extraneous-dependencies */
|
|
2
|
-
const { default: babel } = require('@babel/register')
|
|
3
|
-
const jsdom = require('global-jsdom')
|
|
4
|
-
|
|
5
|
-
babel({
|
|
6
|
-
configFile: '@mediatool/frontend-tools/lib/tests/babel.config.js',
|
|
7
|
-
extensions: [ '.ts', '.tsx', '.js', '.jsx' ],
|
|
8
|
-
})
|
|
9
|
-
jsdom()
|
|
File without changes
|