Skip to content

Commit 8779eae

Browse files
committed
chore: format, lint, fix lint
1 parent 4019cee commit 8779eae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+726
-643
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@ merge of your pull request!
1515
-->
1616

1717
**What**:
18+
1819
<!-- What changes are being made? (What feature/bug is being fixed here?) -->
1920

2021
**Why**:
22+
2123
<!-- Why are these changes necessary? -->
2224

2325
**How**:
24-
<!-- How were these changes implemented? -->
2526

27+
<!-- How were these changes implemented? -->
2628

2729
**Checklist**:
30+
2831
<!-- Have you done all of these things? -->
2932

3033
<!-- To check an item, place an "x" in the box like so: "- [x] Documentation" -->

jest.config.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ config.moduleNameMapper = {
1010

1111
config.testEnvironment = 'jsdom'
1212

13-
config.setupFilesAfterEnv = [
14-
'<rootDir>/testenv/jest.js',
15-
]
13+
config.setupFilesAfterEnv = ['<rootDir>/testenv/jest.js']
1614

1715
config.testMatch.push('<rootDir>/tests/**/*.+(js|jsx|ts|tsx)')
1816

scripts/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
{"type": "module"}
1+
{
2+
"type": "module"
3+
}

scripts/setup.js

Lines changed: 115 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'fs/promises'
22
import path from 'path'
3-
import { createBundleBuilder } from '@ph.fritsche/toolbox/dist/builder/index.js'
4-
import { spawn } from 'child_process'
3+
import {createBundleBuilder} from '@ph.fritsche/toolbox/dist/builder/index.js'
4+
import {spawn} from 'child_process'
55

66
const dirname = path.dirname(new URL(import.meta.url).pathname)
77
const indexDirLib = path.join(dirname, '../testenv/libs')
@@ -13,124 +13,140 @@ const cmd = process.argv[2]
1313
const names = process.argv.length > 3 ? process.argv.slice(3) : undefined
1414

1515
if (cmd === 'install-lib') {
16-
await Promise.all(
17-
(await getLibDirs(names))
18-
.map(([name, dir]) => installLib(name, dir))
19-
)
16+
await Promise.all(
17+
(await getLibDirs(names)).map(([name, dir]) => installLib(name, dir)),
18+
)
2019
} else if (cmd === 'bundle-lib') {
21-
await Promise.all(
22-
(await getLibDirs(names))
23-
.map(([name, dir]) => buildLib(name, dir))
24-
)
20+
await Promise.all(
21+
(await getLibDirs(names)).map(([name, dir]) => buildLib(name, dir)),
22+
)
2523
} else if (cmd === 'bundle-env') {
26-
await Promise.all(
27-
(await getEnvFiles(names))
28-
.map(([name, file]) => buildEnv(name, file))
29-
)
24+
await Promise.all(
25+
(await getEnvFiles(names)).map(([name, file]) => buildEnv(name, file)),
26+
)
3027
} else if (!cmd) {
31-
await Promise.all([
32-
...(await getLibDirs()).map(([name, dir]) => installLib(name, dir).then(() => buildLib(name, dir))),
33-
...(await getEnvFiles()).map(([name, file]) => buildEnv(name, file)),
34-
])
28+
await Promise.all([
29+
...(
30+
await getLibDirs()
31+
).map(([name, dir]) =>
32+
installLib(name, dir).then(() => buildLib(name, dir)),
33+
),
34+
...(await getEnvFiles()).map(([name, file]) => buildEnv(name, file)),
35+
])
3536
}
3637

3738
async function getLibDirs(names) {
38-
names ??= (await fs.readdir(indexDirLib)).filter(n => !n.startsWith('.'))
39-
40-
return await Promise.all(names.map(name => {
41-
const dir = `${indexDirLib}/${name}`
42-
43-
return fs.stat(`${dir}/index.js`).then(
44-
() => [name, dir],
45-
() => {throw new Error(`${dir}/index.js could not be found.`)}
46-
)
47-
}))
39+
names ??= (await fs.readdir(indexDirLib)).filter(n => !n.startsWith('.'))
40+
41+
return await Promise.all(
42+
names.map(name => {
43+
const dir = `${indexDirLib}/${name}`
44+
45+
return fs.stat(`${dir}/index.js`).then(
46+
() => [name, dir],
47+
() => {
48+
throw new Error(`${dir}/index.js could not be found.`)
49+
},
50+
)
51+
}),
52+
)
4853
}
4954

5055
async function getEnvFiles(names) {
51-
names ??= (await fs.readdir(indexDirEnv))
52-
.filter(n => /^\w+\.js$/.test(n))
53-
.filter(n => !ignoreEnv.includes(n))
54-
.map(f => f.slice(0, f.length - 3))
55-
56-
return await Promise.all(names.map(async name => {
57-
const file = `${indexDirEnv}/${name}.js`
58-
59-
return fs.stat(file).then(
60-
() => [name, file],
61-
() => { throw new Error(`${file} could not be found.`)}
62-
)
63-
}))
56+
names ??= (await fs.readdir(indexDirEnv))
57+
.filter(n => /^\w+\.js$/.test(n))
58+
.filter(n => !ignoreEnv.includes(n))
59+
.map(f => f.slice(0, f.length - 3))
60+
61+
return await Promise.all(
62+
names.map(async name => {
63+
const file = `${indexDirEnv}/${name}.js`
64+
65+
return fs.stat(file).then(
66+
() => [name, file],
67+
() => {
68+
throw new Error(`${file} could not be found.`)
69+
},
70+
)
71+
}),
72+
)
6473
}
6574

6675
async function installLib(name, dir) {
67-
return new Promise((res, rej) => {
68-
const child = spawn('npm', ['i'], {cwd: dir})
76+
return new Promise((res, rej) => {
77+
const child = spawn('npm', ['i'], {cwd: dir})
6978

70-
process.stdout.write(`Installing library "${name}" at ${dir}\n`)
79+
process.stdout.write(`Installing library "${name}" at ${dir}\n`)
7180

72-
child.on('error', e => {
73-
process.stdout.write(`${e.stack ?? String(e)}\n`)
74-
})
75-
child.on('exit', (code, signal) => {
76-
(code || signal ? rej(code) : res())
77-
})
81+
child.on('error', e => {
82+
process.stdout.write(`${e.stack ?? String(e)}\n`)
83+
})
84+
child.on('exit', (code, signal) => {
85+
code || signal ? rej(code) : res()
7886
})
87+
})
7988
}
8089

8190
async function buildLib(name, dir) {
82-
const { globals } = JSON.parse(await fs.readFile(`${dir}/package.json`))
83-
84-
process.stdout.write(`Bundling library "${name}" at ${dir}/index.js\n`)
85-
86-
const builder = createBundleBuilder({
87-
basePath: `${dir}/`,
88-
globals,
89-
})
90-
builder.inputFiles.set(`${dir}/index.js`, undefined)
91-
92-
builder.emitter.addListener('complete', e => {
93-
const content = String(e.outputFiles.get('index.js')?.content)
94-
fs.writeFile(`${dir}/index.bundle.js`, content)
95-
.then(() => process.stdout.write([
96-
'<<<',
97-
`Wrote ${dir}/index.bundle.js`,
98-
`[${content.length} bytes]`,
99-
...((globals && Object.keys(globals).length)
100-
? [
101-
` Depending on:`,
102-
...Object.entries(globals).map(([module, name]) => ` ${name} => ${module}`),
103-
]
104-
: []),
105-
'>>>',
106-
'',
107-
].join('\n')))
108-
})
91+
const {globals} = JSON.parse(await fs.readFile(`${dir}/package.json`))
92+
93+
process.stdout.write(`Bundling library "${name}" at ${dir}/index.js\n`)
94+
95+
const builder = createBundleBuilder({
96+
basePath: `${dir}/`,
97+
globals,
98+
})
99+
builder.inputFiles.set(`${dir}/index.js`, undefined)
100+
101+
builder.emitter.addListener('complete', e => {
102+
const content = String(e.outputFiles.get('index.js')?.content)
103+
fs.writeFile(`${dir}/index.bundle.js`, content).then(() =>
104+
process.stdout.write(
105+
[
106+
'<<<',
107+
`Wrote ${dir}/index.bundle.js`,
108+
`[${content.length} bytes]`,
109+
...(globals && Object.keys(globals).length
110+
? [
111+
` Depending on:`,
112+
...Object.entries(globals).map(
113+
([module, name]) => ` ${name} => ${module}`,
114+
),
115+
]
116+
: []),
117+
'>>>',
118+
'',
119+
].join('\n'),
120+
),
121+
)
122+
})
109123

110-
builder.build()
124+
builder.build()
111125
}
112126

113127
async function buildEnv(name, file) {
114-
process.stdout.write(`Bundling environment "${name}" at ${file}\n`)
115-
116-
const builder = createBundleBuilder({
117-
basePath: `${indexDirEnv}/`,
118-
})
119-
const basename = path.basename(file, '.js')
120-
builder.inputFiles.set(file, undefined)
121-
122-
builder.emitter.addListener('complete', e => {
123-
const content = String(e.outputFiles.get(`${basename}.js`)?.content)
124-
fs.writeFile(`${indexDirEnv}/${basename}.bundle.js`, content)
125-
.then(() => process.stdout.write([
126-
'<<<',
127-
`Wrote ${indexDirEnv}/${basename}.bundle.js`,
128-
`[${content.length} bytes]`,
129-
'>>>',
130-
'',
131-
].join('\n')))
132-
})
128+
process.stdout.write(`Bundling environment "${name}" at ${file}\n`)
129+
130+
const builder = createBundleBuilder({
131+
basePath: `${indexDirEnv}/`,
132+
})
133+
const basename = path.basename(file, '.js')
134+
builder.inputFiles.set(file, undefined)
135+
136+
builder.emitter.addListener('complete', e => {
137+
const content = String(e.outputFiles.get(`${basename}.js`)?.content)
138+
fs.writeFile(`${indexDirEnv}/${basename}.bundle.js`, content).then(() =>
139+
process.stdout.write(
140+
[
141+
'<<<',
142+
`Wrote ${indexDirEnv}/${basename}.bundle.js`,
143+
`[${content.length} bytes]`,
144+
'>>>',
145+
'',
146+
].join('\n'),
147+
),
148+
)
149+
})
133150

134-
builder.build()
151+
builder.build()
135152
}
136-

0 commit comments

Comments
 (0)