Skip to content

Commit

Permalink
chore(cli): add linter
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaslz committed Jan 6, 2024
1 parent 7db3a6c commit bf6bf4e
Show file tree
Hide file tree
Showing 29 changed files with 2,922 additions and 1,656 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"reset:dependencies": "find . -name 'node_modules' -type d -prune -exec rm -rf '{}' +",
"app:dev": "yarn --cwd=./packages/app dev",
"core:build": "yarn --cwd=./packages/core build",
"cli:lint": "yarn --cwd=./packages/cli lint",
"cli:build": "yarn --cwd=./packages/cli build",
"cli:publish": "yarn --cwd=./packages/cli to-publish",
"cli:test": "yarn --cwd=./packages/cli test --reporter=verbose",
Expand Down
17 changes: 17 additions & 0 deletions packages/cli/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// eslint-disable-next-line no-undef
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
env: { node: true, es2020: true },
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
],
plugins: ["simple-import-sort"],
ignorePatterns: ["dist"],
rules: {
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
},
};
12 changes: 11 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"local-build": "ncc build src/index.ts -m -o dist",
"build": "ncc build src/index.ts -m -o publish/dist",
"to-publish": "npx vite-node publish.js",
"test": "vitest"
"test": "vitest",
"lint": "eslint ."
},
"dependencies": {
"@dimaslz/local-ssl-management-core": "*",
Expand All @@ -59,10 +60,19 @@
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"@types/shelljs": "^0.8.12",
"@typescript-eslint/eslint-plugin": "^6.17.0",
"@typescript-eslint/parser": "^6.17.0",
"@vercel/ncc": "^0.36.1",
"@vitest/coverage-v8": "^0.32.2",
"cpy": "^10.1.0",
"cpy-cli": "^4.2.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.2",
"eslint-plugin-simple-import-sort": "^10.0.0",
"oxlint": "^0.0.22",
"prettier": "^3.1.1",
"jest": "^29.5.0",
"rimraf": "^5.0.1",
"typescript": "^5.1.3",
Expand Down
35 changes: 17 additions & 18 deletions packages/cli/prebuild.mjs
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
import fs from "fs";
import cpy from "cpy";
import fs from "fs";
import { rimrafSync } from "rimraf";


const prebuild = async () => {
if (fs.existsSync("dist/.local-ssl-management")) {
await cpy("dist/.local-ssl-management/**/*", ".tmp-local-ssl-management");
}
if (fs.existsSync("dist/.local-ssl-management")) {
await cpy("dist/.local-ssl-management/**/*", ".tmp-local-ssl-management");
}

rimrafSync("dist");
rimrafSync("dist");

if (fs.existsSync(".tmp-local-ssl-management")) {
fs.mkdirSync("dist", { recursive: true });
await cpy(".tmp-local-ssl-management/**/*", "dist/.local-ssl-management");
}
if (fs.existsSync(".tmp-local-ssl-management")) {
fs.mkdirSync("dist", { recursive: true });
await cpy(".tmp-local-ssl-management/**/*", "dist/.local-ssl-management");
}

rimrafSync(".tmp-local-ssl-management");
rimrafSync(".tmp-local-ssl-management");

if (!fs.existsSync(".local-ssl-management/ssl")) {
fs.mkdirSync("dist/.local-ssl-management/ssl", { recursive: true });
}
}
if (!fs.existsSync(".local-ssl-management/ssl")) {
fs.mkdirSync("dist/.local-ssl-management/ssl", { recursive: true });
}
};

if (process.env.CI) {
rimrafSync("dist");
rimrafSync("dist");
} else {
prebuild();
}
prebuild();
}
240 changes: 122 additions & 118 deletions packages/cli/publish.mjs
Original file line number Diff line number Diff line change
@@ -1,132 +1,136 @@
import prompts from "prompts";
import semver from "semver";
import ncc from "@vercel/ncc";
import fs from "fs";
import cpy from "cpy";
import shell from "shelljs";
import fs from "fs";
import path from "path";
import prompts from "prompts";
import { rimrafSync } from "rimraf";
import semver from "semver";
import shell from "shelljs";

import packageFile from "./package.json" assert {
type: "json",
};
import path from "path";
import packageFile from "./package.json" assert { type: "json" };

const BRANCH = "main";

async function prompt(props, onCancel = null) {
return await prompts(props, {
onCancel: onCancel || (() => {
console.log("\n🛑 Command release has been canceled.\n")
return await prompts(props, {
onCancel:
onCancel ||
(() => {
console.log("\n🛑 Command release has been canceled.\n");

shell.exit(1);
})
})
};
shell.exit(1);
}),
});
}

const run = async () => {
await rimrafSync("publish");
const { value: canRelease } = await prompt({
type: 'confirm',
name: 'value',
message: 'Are you sure to release now?',
initial: null
});

if (!canRelease) process.exit(1);

const { value: releaseType } = await prompt({
type: "select",
name: "value",
message: "Set the update type",
choices: [
{ title: 'major', description: '', value: 'major' },
{ title: 'minor', description: '', value: 'minor' },
{ title: 'patch', description: '', value: 'patch' },
{ title: 'premajor', description: '', value: 'premajor' },
{ title: 'preminor', description: '', value: 'preminor' },
{ title: 'prepatch', description: '', value: 'prepatch' },
{ title: 'prerelease', description: '', value: 'prerelease' },
],
initial: 0,
});

if (!releaseType) process.exit(1);

const [version, prefix] = packageFile.version.split("-");
const [type, n] = prefix.split(".");
const newVersion = semver.inc(version, releaseType, type, +n + 1);

shell.echo(`New version is ${newVersion}`);

const { value: canCommit } = await prompt({
type: 'confirm',
name: 'value',
message: 'Do you want to commit changes?',
initial: true
});

if (canCommit) {
shell.exec(`git add . && git commit -m "chore(tag): bump version to ${newVersion}"`);
}

const { value: canTag } = await prompt({
type: 'confirm',
name: 'value',
message: 'Do you want to tag the package version?',
initial: true
});

if (canTag) {
shell.exec(`git add . && git tag ${newVersion} && git push -f --tags origin ${BRANCH}`);
}

const { value: canPublishPackage } = await prompt({
type: 'confirm',
name: 'value',
message: 'Do you want to publish the package?',
initial: true
});

if (canPublishPackage) {
const pckg = packageFile;
delete pckg.dependencies;
delete pckg.devDependencies;
delete pckg.scripts;
delete pckg.publishConfig;
pckg.version = newVersion;

if (!fs.existsSync("publish")) {
fs.mkdirSync("publish", { recursive: true });
}

if (fs.existsSync("dist/.local-ssl-management")) {
await cpy("dist/.local-ssl-management/**/*", ".tmp-local-ssl-management");
}

rimrafSync("dist");
shell.exec("yarn build");

if (fs.existsSync("package.json")) {
fs.writeFileSync("publish/package.json", JSON.stringify(pckg, null, 2));
}

if (fs.existsSync(".tmp-local-ssl-management")) {
fs.mkdirSync("dist", { recursive: true });
await cpy(".tmp-local-ssl-management/**/*", "dist/.local-ssl-management");
}

rimrafSync(".tmp-local-ssl-management");

if (!fs.existsSync(".local-ssl-management/ssl")) {
fs.mkdirSync("dist/.local-ssl-management/ssl", { recursive: true });
}

shell.cd("publish");
shell.exec(`npm publish --access public`);
shell.cd("..");
}

console.log("🎉 Done!");
await rimrafSync("publish");
const { value: canRelease } = await prompt({
type: "confirm",
name: "value",
message: "Are you sure to release now?",
initial: null,
});

if (!canRelease) process.exit(1);

const { value: releaseType } = await prompt({
type: "select",
name: "value",
message: "Set the update type",
choices: [
{ title: "major", description: "", value: "major" },
{ title: "minor", description: "", value: "minor" },
{ title: "patch", description: "", value: "patch" },
{ title: "premajor", description: "", value: "premajor" },
{ title: "preminor", description: "", value: "preminor" },
{ title: "prepatch", description: "", value: "prepatch" },
{ title: "prerelease", description: "", value: "prerelease" },
],
initial: 0,
});

if (!releaseType) process.exit(1);

const [version, prefix] = packageFile.version.split("-");
const [type, n] = prefix.split(".");
const newVersion = semver.inc(version, releaseType, type, +n + 1);

shell.echo(`New version is ${newVersion}`);

const { value: canCommit } = await prompt({
type: "confirm",
name: "value",
message: "Do you want to commit changes?",
initial: true,
});

if (canCommit) {
shell.exec(
`git add . && git commit -m "chore(tag): bump version to ${newVersion}"`,
);
}

const { value: canTag } = await prompt({
type: "confirm",
name: "value",
message: "Do you want to tag the package version?",
initial: true,
});

if (canTag) {
shell.exec(
`git add . && git tag ${newVersion} && git push -f --tags origin ${BRANCH}`,
);
}

const { value: canPublishPackage } = await prompt({
type: "confirm",
name: "value",
message: "Do you want to publish the package?",
initial: true,
});

if (canPublishPackage) {
const pckg = packageFile;
delete pckg.dependencies;
delete pckg.devDependencies;
delete pckg.scripts;
delete pckg.publishConfig;
pckg.version = newVersion;

if (!fs.existsSync("publish")) {
fs.mkdirSync("publish", { recursive: true });
}

if (fs.existsSync("dist/.local-ssl-management")) {
await cpy("dist/.local-ssl-management/**/*", ".tmp-local-ssl-management");
}

rimrafSync("dist");
shell.exec("yarn build");

if (fs.existsSync("package.json")) {
fs.writeFileSync("publish/package.json", JSON.stringify(pckg, null, 2));
}

if (fs.existsSync(".tmp-local-ssl-management")) {
fs.mkdirSync("dist", { recursive: true });
await cpy(".tmp-local-ssl-management/**/*", "dist/.local-ssl-management");
}

rimrafSync(".tmp-local-ssl-management");

if (!fs.existsSync(".local-ssl-management/ssl")) {
fs.mkdirSync("dist/.local-ssl-management/ssl", { recursive: true });
}

shell.cd("publish");
shell.exec(`npm publish --access public`);
shell.cd("..");
}

console.log("🎉 Done!");
};

run();
2 changes: 1 addition & 1 deletion packages/cli/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const { pathname: DIRNAME } = new URL(import.meta.url);
export const { pathname: DIRNAME } = new URL(import.meta.url);
Loading

0 comments on commit bf6bf4e

Please sign in to comment.