Skip to content

Commit

Permalink
Feat: Added Next.js Configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
amoskyalo committed Mar 8, 2024
1 parent 202dfcd commit eebde6b
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "templates/vite-js"]
path = templates/vite-js
url = https://github.com/amoskyalo/vite-template
[submodule "templates/mui-next-template"]
path = templates/mui-next-template
url = https://github.com/amoskyalo/mui-next-template
5 changes: 3 additions & 2 deletions commands/projectInit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ async function projectInit(projectName, installAll, architecture, tool, monorepo
function getTemplateUrl() {
switch (tool) {
case 'cra': return "https://github.com/amoskyalo/mui-cra-template";
case 'vite': return "https://github.com/amoskyalo/vite-template"
default: return null;
case 'vite': return "https://github.com/amoskyalo/vite-template";
case 'next': return "https://github.com/amoskyalo/mui-next-template";
default: throw new Error("Unknown tool:" + tool);
}
}

Expand Down
2 changes: 1 addition & 1 deletion commands/themeInit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const path = require("path");
const createTheme = require("../components/theme");
const createTheme = require("../components/Theme/theme");
const fs = require('fs');
const { logger } = require('../utils/logger')
const { defaultColors } = require('../utils/constants');
Expand Down
33 changes: 33 additions & 0 deletions components/Theme/nextThemeConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function getNextThemeConfigFile(){
return `
'use client';
import { createTheme, ThemeProvider } from '@mui/material/styles';
import { createContext, useState } from 'react';
import { CssBaseline } from '@mui/material';
import themeConfig from '.';
export const ThemeContext = createContext();
export const LayoutThemeConfig = ({ children }) => {
const [mode, setMode] = useState('dark');
const toggleColorMode = () => {
setMode((prevMode) => prevMode === 'dark' ? 'light' : 'dark');
};
const theme = createTheme(themeConfig(mode));
return (
<ThemeProvider theme={theme}>
<ThemeContext.Provider value={{ toggleColorMode, mode }}>
<CssBaseline />
{children}
</ThemeContext.Provider>
</ThemeProvider>
)
}
`
}

module.exports = getNextThemeConfigFile;
File renamed without changes.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ program.command('project-init')
choices: [
{ name: "CRA", value: "cra" },
{ name: "Vite", value: "vite" },
{ name: "Next.js", value: "next.js" }
{ name: "Next.js", value: "next" }
]
});

Expand Down
19 changes: 14 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "mui-cli",
"version": "1.0.0",
"description": "CLI for material UI",
"name": "material-ui-cli",
"version": "0.0.2",
"description": "Build Material UI apps 10x faster with material-ui-cli ⚡",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"bin": {
"mui": "./index.js"
"material-ui": "index.js"
},
"keywords": [
"materialUI",
Expand All @@ -26,5 +26,14 @@
"ejs": "^3.1.9",
"fs-extra": "^11.2.0",
"joi": "^17.12.1"
}
},
"devDependencies": {},
"repository": {
"type": "git",
"url": "git+https://github.com/amoskyalo/material-UI-CLI.git"
},
"bugs": {
"url": "https://github.com/amoskyalo/material-UI-CLI/issues"
},
"homepage": "https://github.com/amoskyalo/material-UI-CLI#readme"
}
1 change: 1 addition & 0 deletions templates/mui-next-template
Submodule mui-next-template added at 7f4377
6 changes: 5 additions & 1 deletion utils/getComponentTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { mkdir, writeFile, readFile, rename } = require('fs').promises;
const { componentsCategories } = require('../utils/constants');
const { logger } = require('../utils/logger');
const { exec } = require('child_process');
const getNextThemeConfigFile = require('../components/Theme/nextThemeConfig');
const CLI = require('clui');
const path = require('path');
const ejs = require('ejs');
Expand Down Expand Up @@ -104,9 +105,12 @@ class ComponentGenerator {
return Promise.all([...categoriesPromises, ...componentsPromises])
}

async function createTheme() {
const createTheme = async () => {
try {
await mkdir(themePath);
this.tool === "next" ?
await writeFile(path.join(themePath, "config.js"), getNextThemeConfigFile())
: null;
themeInit({}, false);
} catch (error) {
throw error
Expand Down

0 comments on commit eebde6b

Please sign in to comment.