mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Remove Makefile from all intree extensions
- Makefiles are not really common (rightly so) in JS projects and script entries in the package.json are good enough and what they're there for. - Move to using yarn for installing dependencies and running scripts as that is what we mostly use for the rest of the project. - Move from using make syntax to a dedicated script for building and testing extensions. Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
df0f080380
commit
f2a3710d04
32 files changed
+17914
-21705
No files matched your search
@@ -0,0 +1,94 @@
|
||||
import path from "path"
|
||||
import fse from "fs-extra"
|
||||
import execa from "execa"
|
||||
import { Writable } from "stream"
|
||||
|
||||
function firstLongest(a: string, b: string) {
|
||||
if (a.length >= b.length) {
|
||||
return a
|
||||
}
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
function makeSink(prefix: string) {
|
||||
let buf = ""
|
||||
|
||||
return new Writable({
|
||||
write(chunk: any, encoding: string, cb: () => void) {
|
||||
buf += chunk
|
||||
|
||||
const parts = buf.split(/\r?\n/)
|
||||
const endsWithNL = buf.endsWith("\n")
|
||||
if (endsWithNL) {
|
||||
buf = parts.pop()
|
||||
} else {
|
||||
buf = ""
|
||||
}
|
||||
|
||||
for (const line of parts) {
|
||||
console.log(`${prefix}${line}`)
|
||||
}
|
||||
|
||||
cb()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const args = process.argv.slice(2) // remove node call and file name call
|
||||
|
||||
async function buildInTreeExtension(extensionPath: string, prefix: string) {
|
||||
console.log(`Building: ${extensionPath}`)
|
||||
|
||||
const install = execa("yarn", { cwd: extensionPath })
|
||||
install.stdout.pipe(makeSink(prefix))
|
||||
await install
|
||||
|
||||
const build = execa("yarn", ["run", "build"], { cwd: extensionPath })
|
||||
build.stdout.pipe(makeSink(prefix))
|
||||
await build
|
||||
}
|
||||
|
||||
async function testInTreeExtension(extensionPath: string, prefix: string) {
|
||||
console.log(`Testing: ${extensionPath}`)
|
||||
|
||||
const test = execa("yarn", ["test"], { cwd: extensionPath })
|
||||
test.stdout.pipe(makeSink(prefix))
|
||||
await test
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const cwd = process.cwd()
|
||||
const [extensionsFolder, action] = args
|
||||
const pathToRootExtensions = path.resolve(path.join(cwd, extensionsFolder))
|
||||
|
||||
const folders: string[] = []
|
||||
const names: string[] = []
|
||||
|
||||
for (const entry of await fse.readdir(pathToRootExtensions)) {
|
||||
const entryPath = path.resolve(pathToRootExtensions, entry)
|
||||
const info = await fse.stat(entryPath)
|
||||
if (!info.isDirectory()) {
|
||||
continue
|
||||
}
|
||||
|
||||
folders.push(entryPath)
|
||||
names.push(entry)
|
||||
}
|
||||
|
||||
const longestName = names.reduce(firstLongest, "")
|
||||
const prefixWidth = longestName.length + 1
|
||||
const prefixes = names.map(name => `${name}:${" ".repeat(prefixWidth - name.length)}`)
|
||||
|
||||
switch (action.toLowerCase()) {
|
||||
case "build":
|
||||
await Promise.all(folders.map((folder, i) => buildInTreeExtension(folder, prefixes[i])))
|
||||
break
|
||||
case "test":
|
||||
await Promise.all(folders.map((folder, i) => testInTreeExtension(folder, prefixes[i])))
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
main().catch(console.error)
|
||||
Reference in new issue
Block a user