Skip to content

Commit

Permalink
🎉 Feat(myplop,config): add to cli init,profile,config,`category…
Browse files Browse the repository at this point in the history
…`,default, new app structure, functions and utils
  • Loading branch information
INeedJobToStartWork committed Jan 31, 2024
1 parent 83fafff commit e0670e7
Show file tree
Hide file tree
Showing 48 changed files with 871 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ out/

# production
build
dist
**/dist/**
lib

# misc
Expand Down
3 changes: 2 additions & 1 deletion config/eslintrc/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export default [
"**/lib/**",
"**/*.d.ts",
"**/tsconfig.json",
"**/theme.config.jsx"
"**/theme.config.jsx",
"**/templates/**",
]
},
{
Expand Down
7 changes: 4 additions & 3 deletions config/eslintrc/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export default [
"@typescript-eslint/consistent-type-imports": ["error", { fixStyle: "separate-type-imports" }],
"@typescript-eslint/default-param-last:": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": ["error", { allowArgumentsExplicitlyTypedAsAny: true }],
"@typescript-eslint/explicit-module-boundary-types": ["error", { allowArgumentsExplicitlyTypedAsAny: false }],
// "@typescript-eslint/explicit-module-boundary-types": ["error", { allowArgumentsExplicitlyTypedAsAny: true }],
// "@typescript-eslint/explicit-module-boundary-types": ["error", { allowArgumentsExplicitlyTypedAsAny: false }],
"@typescript-eslint/init-declarations": "off",
"@typescript-eslint/max-params": "off",
"@typescript-eslint/member-ordering": "error",
Expand Down Expand Up @@ -97,7 +97,8 @@ export default [
"no-implied-eval": "off",
"@typescript-eslint/no-non-null-asserted-nullish-coalescing": "error",
"@typescript-eslint/no-non-null-asserted-optional-chain": "error",
"@typescript-eslint/no-non-null-assertion": "error",
// "@typescript-eslint/no-non-null-assertion": "error",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-redundant-type-constituents": "off",
"no-loop-func": "off",
"@typescript-eslint/no-restricted-imports": "off",
Expand Down
17 changes: 6 additions & 11 deletions config/webpackrc/webpack.base.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import CopyPlugin from "copy-webpack-plugin";
import path from "path";
import { resolve } from "path";

const __dirname = path.resolve();
const PATHOUT = path.resolve(__dirname, "lib");
const __dirname = resolve();
const PATHOUT = resolve(__dirname, "lib");

export default {
entry: {
index: path.resolve(__dirname, "src/index.ts")
index: resolve(__dirname, "src/index.ts")
},
module: {
rules: [
Expand All @@ -23,7 +23,7 @@ export default {
output: {
clean: true,
filename: "[name].cjs",
path: path.resolve(__dirname, "lib"),
path: resolve(__dirname, "lib"),
chunkLoading: false,
library: {
type: "commonjs2",
Expand All @@ -33,13 +33,8 @@ export default {
resolve: {
extensions: ["", ".ts", ".js", ".mjs", ".mts"],
alias: {
"@": path.resolve(__dirname, "src/")
"@": resolve(__dirname, "src/")
}
},
plugins: [
// new CopyPlugin({
// patterns: [{ from: path.resolve(__dirname, "./src/templates"), to: path.join(PATHOUT, "templates") }]
// })
],
target: "node"
};
1 change: 1 addition & 0 deletions config/webpackrc/webpack.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ export default merge(webpackBaseConfig, {
output: {
path: PATHOUT
}

});
1 change: 1 addition & 0 deletions packages/myplop/clean-package.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"indent": 4,
"remove": ["devDependencies", "dependencies", "lint-staged", "bin"],
"replace": {
"main": "index.cjs",
"scripts": {
"npm:postpack": "clean-package restore"
},
Expand Down
13 changes: 12 additions & 1 deletion packages/myplop/config/webpack/webpack.base.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import CopyPlugin from "copy-webpack-plugin";
import { join, resolve } from "path";
import { merge } from "webpack-merge";
import WebpackConfig from "webpackrc/webpack.base.js";

export default merge(WebpackConfig, {});
const __dirname = resolve();
const PATHOUT = resolve(__dirname, "lib");

export default merge(WebpackConfig, {
plugins: [
new CopyPlugin({
patterns: [{ from: resolve(__dirname, "./src/templates"), to: join(PATHOUT, "templates") }]
})
]
});
3 changes: 2 additions & 1 deletion packages/myplop/config/webpack/webpack.dev.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { merge } from "webpack-merge";
import WebpackConfigDev from "webpackrc/webpack.dev.js";
import WebpackConfigBasic from "./webpack.base.js";

export default merge(WebpackConfigDev, {});
export default merge(WebpackConfigDev, WebpackConfigBasic, {});
7 changes: 6 additions & 1 deletion packages/myplop/config/webpack/webpack.prod.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { resolve } from "path";
import { merge } from "webpack-merge";
import WebpackConfigBasic from "./webpack.base.js";
import WebpackConfigProd from "webpackrc/webpack.prod.js";

export default merge(WebpackConfigProd, {});
const __dirname = resolve();
const PATHOUT = resolve(__dirname, "dist");

export default merge(WebpackConfigProd, WebpackConfigBasic);
2 changes: 1 addition & 1 deletion packages/myplop/dist/index.cjs

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions packages/myplop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"version": "0.0.0",
"private": false,
"type": "module",
"main": "src/index.ts",
"bin": {
"myplopDEV": "./lib/index.cjs",
"myplopPROD": "./dist/index.cjs"
},
"scripts": {
"build": "webpack --config ./config/webpack/webpack.prod.js",
"build:npm": "pnpm npm:prepack && webpack --config ./config/webpack/webpack.prod.js && pnpm npm:postpack ",
Expand All @@ -28,9 +33,11 @@
]
},
"devDependencies": {
"@clack/prompts": "^0.7.0",
"bundle-declarations-webpack-plugin": "^5.0.0",
"clean-package": "^2.2.0",
"copy-webpack-plugin": "^12.0.1",
"commander": "^11.1.0",
"copy-webpack-plugin": "^12.0.2",
"eslintrc": "workspace:*",
"prettier": "^3.1.1",
"prettierrc": "workspace:*",
Expand All @@ -40,6 +47,7 @@
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4",
"webpack-merge": "^5.10.0",
"webpackrc": "workspace:*"
"webpackrc": "workspace:*",
"zod": "^3.22.4"
}
}
66 changes: 66 additions & 0 deletions packages/myplop/src/cli/category.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { program } from "commander";
import * as prompter from "@clack/prompts";
import chalk from "chalk";
import logging from "@/utils/logging";
import { join } from "path";
import { config } from "@/function/config";
import { scanDir } from "@/function";

program
.command("category")
.description("Select category")
.option("-D, --DEBUG", "DEBUG MODE")
.action(({ DEBUG }) => {
process.env.DEBUG = DEBUG ? "TRUE" : "FALSE";

const [state, setState] = config();
prompter
.group({
intro: () => {
prompter.intro(chalk.bgCyan(" Select Category "));

Check failure on line 20 in packages/myplop/src/cli/category.ts

View workflow job for this annotation

GitHub Actions / Continuous-Integration

Unsafe argument of type `any` assigned to a parameter of type `string | undefined`

Check failure on line 20 in packages/myplop/src/cli/category.ts

View workflow job for this annotation

GitHub Actions / Continuous-Integration

Unsafe call of an `any` typed value

Check failure on line 20 in packages/myplop/src/cli/category.ts

View workflow job for this annotation

GitHub Actions / Continuous-Integration

Unsafe member access .bgCyan on an `any` value
},
currentlyChecked: () => {
prompter.note(`Currently selected Category:\n${state.category}`, chalk.bgBlue(" Info "));

Check failure on line 23 in packages/myplop/src/cli/category.ts

View workflow job for this annotation

GitHub Actions / Continuous-Integration

Unsafe argument of type `any` assigned to a parameter of type `string | undefined`

Check failure on line 23 in packages/myplop/src/cli/category.ts

View workflow job for this annotation

GitHub Actions / Continuous-Integration

Unsafe call of an `any` typed value

Check failure on line 23 in packages/myplop/src/cli/category.ts

View workflow job for this annotation

GitHub Actions / Continuous-Integration

Unsafe member access .bgBlue on an `any` value
},
selectedCategory: async () => {
if (state.config === null) {
prompter.cancel("You need to select config first.");
process.exit(1);
}
if (state.profile === null) {
prompter.cancel("You need to select profile first.");
process.exit(1);
}
logging.debug("Category path: ", process.env.CONFIGPATH);

const pathToScan = join(process.env.CONFIGPATH, "config", state.config, "profiles", state.profile);
const Categorys = scanDir(pathToScan, "category");

logging.debug("Found Categorys:", Categorys);
const selected = await prompter.select({
message: "Select Category",
initialValue: state.category,
options: Categorys.map(({ name }) => ({ label: name, value: name }))
});

logging.debug("Selected Category: ", selected);
if (prompter.isCancel(selected) || !selected) {
prompter.cancel("Canceled!");
process.exit(0);
}
return selected;
},
selecting: ({ results }) => {
if (results.selectedCategory === state.category) return void 0;
setState(e => ({ ...e, category: results.selectedCategory! }));
logging.debug("Category state: ", state);
},
outro: () => {
prompter.outro(chalk.bgGreen(" Category Selected! "));

Check failure on line 59 in packages/myplop/src/cli/category.ts

View workflow job for this annotation

GitHub Actions / Continuous-Integration

Unsafe argument of type `any` assigned to a parameter of type `string | undefined`

Check failure on line 59 in packages/myplop/src/cli/category.ts

View workflow job for this annotation

GitHub Actions / Continuous-Integration

Unsafe call of an `any` typed value

Check failure on line 59 in packages/myplop/src/cli/category.ts

View workflow job for this annotation

GitHub Actions / Continuous-Integration

Unsafe member access .bgGreen on an `any` value
}
})
.catch(e => {
logging.error(e);
process.exit(1);
});
});
50 changes: 50 additions & 0 deletions packages/myplop/src/cli/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { program } from "commander";
import * as prompter from "@clack/prompts";
import chalk from "chalk";
import logging from "@/utils/logging";
import { join } from "path";
import { config } from "@/function/config";
import { scanDir } from "@/function";

program
.command("config")
.description("Select config")
.option("-D, --DEBUG", "DEBUG MODE")
.action(({ DEBUG }) => {
process.env.DEBUG = DEBUG ? "TRUE" : "FALSE";

const [state, setState] = config();
prompter
.group({
intro: () => {
prompter.intro(chalk.bgCyan(" Select config "));

Check failure on line 20 in packages/myplop/src/cli/config.ts

View workflow job for this annotation

GitHub Actions / Continuous-Integration

Unsafe argument of type `any` assigned to a parameter of type `string | undefined`
},
currentlyChecked: () => {
prompter.note(`Currently selected config:\n${state.config}`, chalk.bgBlue(" Info "));
},
selectedConfig: async () => {
logging.debug("Config path: ", process.env.CONFIGPATH);
const pathToScan = join(process.env.CONFIGPATH, "./config");
const configs = scanDir(pathToScan, "config");
logging.debug("Found Configs:", configs);
const selected = await prompter.select({
message: "Select config",
initialValue: state.config,
options: configs.map(({ name }) => ({ label: name, value: name }))
});
logging.debug("Selected config: ", selected);
return selected;
},
selecting: ({ results }) => {
if (results.selectedConfig === state.config) return;
setState(e => ({ ...e, config: results.selectedConfig!, profile: null, category: null }));
logging.debug("Config state: ", state);
},
outro: () => {
prompter.outro(chalk.bgGreen(" Config Selected! "));
}
})
.catch(e => {
throw e;
});
});
40 changes: 40 additions & 0 deletions packages/myplop/src/cli/default.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { program } from "commander";
import * as prompter from "@clack/prompts";
import chalk from "chalk";
import { config } from "@/function";

program.action(() => {
const [state] = config();

prompter
.group(
{
intro: () => {
prompter.intro(chalk.bgCyan(" MyPlop "));
},
selectAction: () => {
if (state.config === null) {
prompter.cancel("You need to select config first.");
process.exit(1);
}
if (state.profile === null) {
prompter.cancel("You need to select profile first.");
process.exit(1);
}
if (state.category === null) {
prompter.cancel("You need to select category first.");
process.exit(1);
}
}
},
{
onCancel: () => {
console.log(chalk.bgRed("Canceled"));
process.exit(0);
}
}
)
.catch(e => {
throw e;
});
});
6 changes: 6 additions & 0 deletions packages/myplop/src/cli/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from "./default";
export * from "./init";
export * from "./version";
export * from "./config";
export * from "./profile";
export * from "./category";
49 changes: 49 additions & 0 deletions packages/myplop/src/cli/init/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { program } from "commander";
import * as prompter from "@clack/prompts";
import chalk from "chalk";

program
.command("init")
.description("Initialize plopfile")
.option("-D, --DEBUG", "output extra debugging (default: false)", false)
.action(({ DEBUG }) => {
process.env.DEBUG = `${DEBUG}`.toUpperCase();

prompter
.group(
{
intro: () => {
prompter.intro(chalk.bgCyan(" Initializer "));
},
choice: async () =>
prompter.select({
message: "What do you want to initialize?",
initialValue: "app",
options: [
{ label: "App", value: "app", hint: "Initialize app - required to work app" },
{ label: "Config", value: "config" },
{ label: "Profile", value: "profile", hint: "Initialize profile at config" },
{ label: "Component", value: "component", hint: "Initialize component" }
]
}),
outro: () => {
prompter.outro(chalk.bgGreen("Choosed correctly!"));
},
loadModule: async ({ results }) => {
await import(/* webpackMode: "eager" */ `./options/${results.choice}`).catch(err => {
console.error("Module not found - probably file with option doesnt exist.", err);
process.exit(0);
});
}
},
{
onCancel: () => {
console.log(chalk.red("Canceled."));
process.exit(0);
}
}
)
.catch(e => {
throw e;
});
});
Loading

0 comments on commit e0670e7

Please sign in to comment.