Skip to content

Commit

Permalink
feat: implemented new eslint flat config and checked with new stylist…
Browse files Browse the repository at this point in the history
…ic settings
  • Loading branch information
Blaquewithaq committed Dec 10, 2023
1 parent 9c99f5a commit dbbda38
Show file tree
Hide file tree
Showing 16 changed files with 443 additions and 587 deletions.
39 changes: 0 additions & 39 deletions .eslintrc.json

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,6 @@ dist
.ara
.private
pkg
tests/playground
ara-*.*
bun.lockb
104 changes: 25 additions & 79 deletions ci.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import {readableStreamToText} from "bun";
import {rm, mkdir} from "node:fs/promises";
import {doesDirectoryExist, getFileList} from "./src/utils";
import { readableStreamToText } from "bun";
import { rm, mkdir } from "node:fs/promises";
import { doesDirectoryExist, getFileList } from "./src/utils";
import os from "node:os";

const packageFiles: Array<string> = [
"ara.config.json",
"ara.config.jsonc",
"ara.config.toml",
"LICENSE",
"README.md"
"README.md",
];

// ---------------------------------------------------

async function clean (type?: Array<"archive" | "pkg" | "wipe">) {

async function clean(type?: Array<"archive" | "pkg" | "wipe">) {
const clean: Array<string> = [];

if (type?.includes("archive") || type?.includes("wipe")) {

// Find files with these patterns: ara-*.zip, ara-*.tar.gz
const {stdout} = Bun.spawn([
// Find files with these patterns: ara-*.zip, ara-*.tar.gz
const { stdout } = Bun.spawn([
"find",
".",
"-type",
Expand All @@ -29,142 +27,106 @@ async function clean (type?: Array<"archive" | "pkg" | "wipe">) {
"ara-*.zip",
"-o",
"-name",
"ara-*.tar.gz"
"ara-*.tar.gz",
]);

if (stdout) {

const output = await readableStreamToText(stdout);
const files = output.split("\n");

for (const file of files) {

if (file) {

clean.push(file);

}

}

}

}

if (type?.includes("pkg") || type?.includes("wipe")) {

clean.push("pkg");

}

if (type?.includes("wipe")) {

clean.push(
"node_modules",
"bun.lockb"
"bun.lockb",
);

}

for (const path of clean) {

try {

await rm(
path,
{
"force": true,
"recursive": true
}
force: true,
recursive: true,
},
);

} catch (error) {

}
catch (error) {
console.error(error);

}

}

}

async function build () {

async function build() {
await clean(["pkg"]);

const {stdout, stderr} = Bun.spawn([
const { stdout, stderr } = Bun.spawn([
"bun",
"build",
"./src/index.ts",
"--compile",
"--outfile",
"pkg/ara"
"pkg/ara",
]);

if (stderr) {

const error = await readableStreamToText(stderr);
console.error(error);
return;

}

if (stdout) {

const output = await readableStreamToText(stdout);
console.log(output);

}

}

async function pkg () {

async function pkg() {
if (!await doesDirectoryExist("pkg")) {

mkdir("pkg");

}

for await (const path of packageFiles) {

const file = await Bun.file(path).exists();

if (file) {

console.log(`Copying ${path} to pkg...`);

const {stderr} = Bun.spawn([
const { stderr } = Bun.spawn([
"cp",
path,
"pkg"
"pkg",
]);

if (stderr) {

const error = await readableStreamToText(stderr);
console.error(error);
return;

}

}

}

}

async function archive () {

async function archive() {
await clean(["archive"]);

const pkgDirectory = "pkg";

if (!await doesDirectoryExist(pkgDirectory)) {

console.error(`${pkgDirectory} isn't ready yet`);
return;

}

const packageJSON = await Bun.file("package.json").json();
Expand All @@ -173,11 +135,9 @@ async function archive () {
const arch = os.arch();
let extension = ".tar.gz";
const fileList = await getFileList("pkg");

let cmd = "";

switch (platform) {

case "linux":
case "darwin":

Expand All @@ -191,44 +151,34 @@ async function archive () {
default:
console.error("Unsupported platform");
return;

}

const {stdout, stderr} = Bun.spawn(
const { stdout, stderr } = Bun.spawn(
cmd.split(" "),
{
"cwd": "pkg"
}
cwd: "pkg",
},
);

if (stderr) {

const error = await readableStreamToText(stderr);
console.error(error);

}

if (stdout) {

const output = await readableStreamToText(stdout);
console.log(output);

}

}

// ---------------------------------------------------

(async () => {

if (process.argv.length > 2) {

switch (process.argv[2]) {

case "-c":
case "clean":
switch (process.argv[3]) {

case "-a":
case "archive":
await clean(["archive"]);
Expand All @@ -244,10 +194,9 @@ async function archive () {
default:
await clean([
"archive",
"pkg"
"pkg",
]);
break;

}
break;
case "-b":
Expand All @@ -265,9 +214,6 @@ async function archive () {
default:
console.log("Invalid argument");
break;

}

}

})();
40 changes: 40 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/** @type {import('eslint').Linter.FlatConfig[]} */

import pluginImport from "eslint-plugin-import";
import parserTypescript from "@typescript-eslint/parser";
import pluginTypescript from "@typescript-eslint/eslint-plugin";
import stylistic from "@stylistic/eslint-plugin";

export default [
{
files: ["*.ts"],
ignores: [
"*.js",
"*.d.ts",
"*.json",
".private",
"pkg/",
"node_modules/**/*",
],
languageOptions: {
ecmaVersion: "latest",
sourceType: "module",
parser: parserTypescript,
},
plugins: {
pluginImport,
pluginTypescript,
stylistic,
},
settings: {
"import/resolver": {
typescript: true,
},
},
},
stylistic.configs.customize({
indent: 4,
quotes: "double",
semi: true,
}),
];
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"builder": "bun compile && bun pkg",
"archive": "bun run ./ci.ts archive",
"all": "bun builder && bun archive",
"lint": "eslint \"src/**/*.ts\"",
"check": "eslint \"src/**/*.ts\" --fix"
"lint": "eslint --config eslint.config.js .",
"check": "eslint --config eslint.config.js . --fix"
},
"devDependencies": {
"@stylistic/eslint-plugin": "^1.5.0",
Expand Down
2 changes: 1 addition & 1 deletion src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {paths, configPath} from "./paths";
export { paths, configPath } from './paths'
Loading

0 comments on commit dbbda38

Please sign in to comment.