@mediatool/frontend-tools 1.0.0 → 1.0.1
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/dist/mtft.cjs +110 -0
- package/lib/test/index.js +6 -6
- package/package.json +5 -3
- package/rollup.config.js +7 -0
package/dist/mtft.cjs
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var commander = require('commander');
|
|
4
|
+
var vite = require('vite');
|
|
5
|
+
var promises = require('node:fs/promises');
|
|
6
|
+
var node_path = require('node:path');
|
|
7
|
+
var ramda = require('ramda');
|
|
8
|
+
var Mocha = require('mocha/lib/mocha.js');
|
|
9
|
+
var runHelpers_js = require('mocha/lib/cli/run-helpers.js');
|
|
10
|
+
|
|
11
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
|
+
|
|
13
|
+
var Mocha__default = /*#__PURE__*/_interopDefaultLegacy(Mocha);
|
|
14
|
+
|
|
15
|
+
async function getModuleContext () {
|
|
16
|
+
const location = process.cwd();
|
|
17
|
+
const pkgLocation = node_path.resolve(location, './package.json');
|
|
18
|
+
const entryLocation = node_path.resolve(location, './index.js');
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
await promises.stat(pkgLocation);
|
|
22
|
+
await promises.stat(entryLocation);
|
|
23
|
+
const pkg = JSON.parse(await promises.readFile(pkgLocation));
|
|
24
|
+
const { name } = pkg;
|
|
25
|
+
const dependencies = ramda.uniq(ramda.keys({ ...pkg.dependencies, ...pkg.peerDependencies }));
|
|
26
|
+
return {
|
|
27
|
+
entry: entryLocation,
|
|
28
|
+
root: location,
|
|
29
|
+
name,
|
|
30
|
+
dependencies,
|
|
31
|
+
}
|
|
32
|
+
} catch (e) {
|
|
33
|
+
throw new Error('Oopsie.')
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async function buildLibrary () {
|
|
38
|
+
const {
|
|
39
|
+
entry,
|
|
40
|
+
root,
|
|
41
|
+
name,
|
|
42
|
+
dependencies,
|
|
43
|
+
} = await getModuleContext();
|
|
44
|
+
|
|
45
|
+
return vite.build({
|
|
46
|
+
root,
|
|
47
|
+
build: {
|
|
48
|
+
lib: {
|
|
49
|
+
entry,
|
|
50
|
+
name,
|
|
51
|
+
},
|
|
52
|
+
rollupOptions: {
|
|
53
|
+
external: dependencies,
|
|
54
|
+
},
|
|
55
|
+
sourcemap: true,
|
|
56
|
+
},
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const types$1 = {
|
|
61
|
+
app: () => {},
|
|
62
|
+
library: buildLibrary,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
function build (type) {
|
|
66
|
+
const fn = types$1[type];
|
|
67
|
+
if (!fn) throw new Error('Unknown type passed as an argument to the "build" command')
|
|
68
|
+
|
|
69
|
+
return fn()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const extensions = '{js,jsx,ts,tsx}';
|
|
73
|
+
const types = {
|
|
74
|
+
all: `./{,!(node_modules)/**}/*-test.${extensions}`,
|
|
75
|
+
unit: `./{,!(node_modules)/**}/test/unit/*-test.${extensions}`,
|
|
76
|
+
it: `./{,!(node_modules)/**}/test/it/*-test.${extensions}`,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
async function test (typeOrSpec) {
|
|
80
|
+
const spec = types[typeOrSpec] || typeOrSpec;
|
|
81
|
+
|
|
82
|
+
const plugins = await runHelpers_js.handleRequires([
|
|
83
|
+
'@mediatool/frontend-tools/lib/test/setup-mocha.cjs',
|
|
84
|
+
]);
|
|
85
|
+
const opts = {
|
|
86
|
+
spec: [ spec ],
|
|
87
|
+
plugins,
|
|
88
|
+
};
|
|
89
|
+
const mocha = new Mocha__default["default"](opts);
|
|
90
|
+
runHelpers_js.runMocha(mocha, opts);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const program = new commander.Command();
|
|
94
|
+
|
|
95
|
+
program
|
|
96
|
+
.name('mtft')
|
|
97
|
+
.description('Mediatool standardized tools for frontend projects')
|
|
98
|
+
.version('0.0.1');
|
|
99
|
+
|
|
100
|
+
program.command('build')
|
|
101
|
+
.description('Builds your pieces into one')
|
|
102
|
+
.argument('<type>', 'app or library')
|
|
103
|
+
.action(build);
|
|
104
|
+
|
|
105
|
+
program.command('test')
|
|
106
|
+
.description('not sure ey? run the tests then')
|
|
107
|
+
.argument('[type]', 'unit (unit tests),it (integration tests)', 'all')
|
|
108
|
+
.action(test);
|
|
109
|
+
|
|
110
|
+
program.parse();
|
package/lib/test/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import Mocha from 'mocha/lib/mocha.js'
|
|
2
2
|
import { handleRequires, runMocha } from 'mocha/lib/cli/run-helpers.js'
|
|
3
3
|
|
|
4
|
+
const extensions = '{js,jsx,ts,tsx}'
|
|
4
5
|
const types = {
|
|
5
|
-
all:
|
|
6
|
-
unit:
|
|
7
|
-
it:
|
|
6
|
+
all: `./{,!(node_modules)/**}/*-test.${extensions}`,
|
|
7
|
+
unit: `./{,!(node_modules)/**}/test/unit/*-test.${extensions}`,
|
|
8
|
+
it: `./{,!(node_modules)/**}/test/it/*-test.${extensions}`,
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
export default async function test (
|
|
11
|
-
const spec = types[
|
|
12
|
-
if (!spec) throw new Error(`Unknown type ${type}`)
|
|
11
|
+
export default async function test (typeOrSpec) {
|
|
12
|
+
const spec = types[typeOrSpec] || typeOrSpec
|
|
13
13
|
|
|
14
14
|
const plugins = await handleRequires([
|
|
15
15
|
'@mediatool/frontend-tools/lib/test/setup-mocha.cjs',
|
package/package.json
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mediatool/frontend-tools",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Common configs and tooling for bundling, testing, linting frontend modules",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"
|
|
9
|
+
"build": "rm -rf dist && rollup -c rollup.config.js",
|
|
10
|
+
"test": "echo 'Testless'",
|
|
11
|
+
"prepublishOnly": "yarn build"
|
|
10
12
|
},
|
|
11
13
|
"bin": {
|
|
12
|
-
"mtft": "./
|
|
14
|
+
"mtft": "./dist/mtft.cjs"
|
|
13
15
|
},
|
|
14
16
|
"dependencies": {
|
|
15
17
|
"@babel/core": "^7.18.9",
|