Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Component CLI #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions bin/createFragment/createFragment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const fs = require('fs');
const path = require('path');

const args = process?.argv?.slice(2);
const newFragmentName = args?.[0];

if (!newFragmentName) {
console.error("Component name is required");
return;
}

const renderComponentTemplate = (componentName, routePath) => (`
const voltran = require('@voltran/core');

import React from 'react';
import classNames from 'classnames';

import ROUTE_PATHS from '../../appRoute/routeConstants';

import style from './${componentName}.scss';

function ${componentName}({ initialState }) {
return (
<div className={classNames(style.root)}>
<div className={classNames(style.container)}>
<h1>Welcome to the VoltranJS</h1>
</div>
</div>
);
}

const component = voltran.default.withBaseComponent(${componentName}, ROUTE_PATHS.${routePath});

export default component;
`);

const createComponet = () => {
const componetName = newFragmentName;
const routeName = newFragmentName?.toUpperCase();

const fileContents = [{
ext: 'js',
renderFn: renderComponentTemplate
},
{
ext: 'scss',
renderFn: () => ''
}
];

const partialsFolder = path.resolve('src', 'partials', componetName);

fs.mkdir(partialsFolder, () => {
fileContents.map(fileContent => {
const componentFolder = path.resolve('src', 'partials', componetName, `${componetName}.${fileContent?.ext}`);
fs.writeFileSync(componentFolder, fileContent?.renderFn(componetName, routeName), { encoding: 'utf-8' });
})
});
}

createComponet();
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
"author": "Hepsiburada Technology Team",
"license": "MIT",
"dependencies": {
"voltranjs": "^1.0.16"
"voltranjs": "^1.0.22"
},
"scripts": {
"start": "yarn voltran --config voltran-app.config.js --dev",
"serve": "yarn voltran --config voltran-app.config.js"
"serve": "yarn voltran --config voltran-app.config.js",
"create-fragment": "node ./bin/createFragment/createFragment.js"
}
}
}
23 changes: 1 addition & 22 deletions src/appConfig.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/appRoute/routeConstants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const ROUTE_PATHS = {
HELLO_WORLD: '/Desktop/HelloWorld',
HELLO_WORLD: '/HelloWorld',
};

export default ROUTE_PATHS;
2 changes: 1 addition & 1 deletion src/partials/HelloWorld/HelloWorld.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function HelloWorld({ initialState }) {
<h1>Welcome to the VoltranJS</h1>

<span>Hello World! It is a Micro Frontend Library</span>
<img className={style.voltran} src={`${appConfig.mediaUrl}/images/voltran.png`}/>
<img className={style.voltran} src={`${appConfig.mediaUrl}/images/voltran.png`} />
</div>
</div>
);
Expand Down
23 changes: 23 additions & 0 deletions src/partials/newComponent/newComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

const voltran = require('@voltran/core');

import React from 'react';
import classNames from 'classnames';

import ROUTE_PATHS from '../../appRoute/routeConstants';

import style from './newComponent.scss';

function newComponent({ initialState }) {
return (
<div className={classNames(style.root)}>
<div className={classNames(style.container)}>
<h1>Welcome to the VoltranJS</h1>
</div>
</div>
);
}

const component = voltran.default.withBaseComponent(newComponent, ROUTE_PATHS.NEWCOMPONENT);

export default component;
Empty file.
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8872,10 +8872,10 @@ vm-browserify@^1.0.1:
resolved "https://registry.yarnpkg.com/vm-browserify/-/vm-browserify-1.1.2.tgz#78641c488b8e6ca91a75f511e7a3b32a86e5dda0"
integrity sha512-2ham8XPWTONajOR0ohOKOHXkm3+gaBmGut3SRuu75xLd/RRaY6vqgh8NBYYk7+RW3u5AtzPQZG8F10LHkl0lAQ==

voltranjs@^1.0.16:
version "1.0.18"
resolved "https://registry.yarnpkg.com/voltranjs/-/voltranjs-1.0.18.tgz#845f77d51bf64c4a84c7c8e464f4d5ed9870d9ca"
integrity sha512-Bvsw1N3Se8Tgn6o4bWIEC3y95c7X1XvzL17d6mx742WacWvt6TF4NzciybvrvjldkAwvbdf0qBLIOLf+wNl4WA==
voltranjs@^1.0.22:
version "1.0.22"
resolved "https://registry.yarnpkg.com/voltranjs/-/voltranjs-1.0.22.tgz#57838cc7c036d639d70840447c67f1449561b3de"
integrity sha512-vcBYVnZv6Kek9J3a57YKCwAvXk3yAr+Y6cbU7adZNxji6c51COg4V925ueIap6WtbZLfOmEeC3HmKHNEkRAiDA==
dependencies:
"@babel/core" "7.14.3"
"@babel/eslint-parser" "^7.12.1"
Expand Down