Skip to content

Commit

Permalink
feat(core)!: Remove info files, menu entries get formatted by miyagi …
Browse files Browse the repository at this point in the history
…instead (#123)
  • Loading branch information
mgrsskls committed Jul 14, 2022
1 parent 165df3a commit f6b89cd
Show file tree
Hide file tree
Showing 16 changed files with 16 additions and 130 deletions.
11 changes: 0 additions & 11 deletions docs/docs/component-files/info.md

This file was deleted.

4 changes: 0 additions & 4 deletions docs/docs/configuration/default-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ Please refer to the [available options](/configuration/options/) for a full expl
"name": "index",
"extension": "css"
},
"info": {
"name": "info",
"extension": "json"
},
"js": {
"name": "index",
"extension": "js"
Expand Down
9 changes: 0 additions & 9 deletions docs/docs/configuration/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,6 @@ default:

_**Note:** You can use `"<component>"` for `name` if the file should have the same name as the component folder._

default:

```json
{
"extension": "json",
"name": "info"
}
```

### `js`

default:
Expand Down
2 changes: 0 additions & 2 deletions docs/docs/how-to/organizing-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,3 @@ _miyagi_ assumes that you have a dedicated folder for each of your components li
```

You can call the folders whatever you want and you can nest them as deep as you want.

Additionally to [info files in your components](/component-files/info/), you can also put a `info.json` or `info.yaml` in every other folder if you want to change the displayed name in the navigation.
1 change: 0 additions & 1 deletion docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ nav:
- Introduction: component-files/introduction.md
- Assets: component-files/assets.md
- Documentation: component-files/documentation.md
- Info: component-files/info.md
- Mocks: component-files/mocks.md
- Schema: component-files/schema.md
- Template: component-files/template.md
Expand Down
1 change: 1 addition & 0 deletions packages/core/assets/css/main/menu.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
border-radius: var(--Miyagi-borderRadius);
display: block;
padding: 0 var(--Miyagi-linkSpacing);
text-transform: capitalize;
}

.Menu-listItem.has-no-match .Menu-component,
Expand Down
4 changes: 0 additions & 4 deletions packages/core/lib/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@
"name": "index",
"extension": "css"
},
"info": {
"name": "info",
"extension": "json"
},
"js": {
"name": "index",
"extension": "js"
Expand Down
14 changes: 0 additions & 14 deletions packages/core/lib/generator/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,6 @@ module.exports = async function componentGenerator(cliParams, config) {
}
}
break;
case "info":
{
const data = {
name: "",
};

if (filesConfig.info.extension === "yaml") {
str = jsonToYaml.dump(data);
} else {
str = `${JSON.stringify(data, null, 2)}\n`;
}
}
break;
case "schema":
{
const data = {
Expand Down Expand Up @@ -209,7 +196,6 @@ module.exports = async function componentGenerator(cliParams, config) {
)}.${filesConfig.templates.extension}`,
mocks: `${filesConfig.mocks.name}.${filesConfig.mocks.extension}`,
docs: "README.md",
info: `${filesConfig.info.name}.${filesConfig.info.extension}`,
css: `${helpers.getResolvedFileName(
filesConfig.css.name,
componentName
Expand Down
32 changes: 0 additions & 32 deletions packages/core/lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,22 +137,6 @@ module.exports = {
return filePath.replace(path.basename(filePath), "README.md");
},

/**
* Accepts a template file path and returns the path to the corresponding info file
*
* @param {object} app - the express instance
* @param {string} filePath - file path to a template file
* @returns {string} file path to the corresponding info file
*/
getInfoPathFromTemplatePath: function (app, filePath) {
return filePath.replace(
path.basename(filePath),
`${app.get("config").files.info.name}.${
app.get("config").files.info.extension
}`
);
},

/**
* Accepts a template file path and returns the path to the corresponding schema file
*
Expand Down Expand Up @@ -197,22 +181,6 @@ module.exports = {
return path.extname(filePath) === ".md";
},

/**
* Accepts a file path and checks if it is an info file
*
* @param {object} app - the express instance
* @param {string} filePath - path to any type of file
* @returns {boolean} is true if the given file is a info file
*/
fileIsInfoFile: function (app, filePath) {
return (
path.basename(filePath) ===
`${app.get("config").files.info.name}.${
app.get("config").files.info.extension
}`
);
},

/**
* Accepts a file path and checks if it is a schema file
*
Expand Down
4 changes: 2 additions & 2 deletions packages/core/lib/init/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ module.exports = yargs
})
.command(
"new",
"Creates a new component folder (including template, mock, documentation, info, css and js files)",
"Creates a new component folder (including template, mock, documentation, css and js files)",
{
skip: {
description:
"files that will not be created\n(comma separated list of css, docs, info, js, mocks, tpl)",
"files that will not be created\n(comma separated list of css, docs, js, mocks, tpl)",
type: "string",
},
only: {
Expand Down
13 changes: 0 additions & 13 deletions packages/core/lib/init/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ async function updateFileContents(app, events) {
helpers.fileIsTemplateFile(app, changedPath) ||
helpers.fileIsDataFile(app, changedPath) ||
helpers.fileIsDocumentationFile(changedPath) ||
helpers.fileIsInfoFile(app, changedPath) ||
helpers.fileIsSchemaFile(app, changedPath)
) {
const fullPath = path.join(process.cwd(), changedPath);
Expand Down Expand Up @@ -239,18 +238,6 @@ async function handleFileChange() {
});

changeFileCallback(true, hasBeenAdded);
// updated file is an info file
} else if (
triggeredEvents.some(({ changedPath }) =>
helpers.fileIsInfoFile(appInstance, changedPath)
)
) {
await setState(appInstance, {
fileContents: await updateFileContents(appInstance, triggeredEvents),
menu: true,
});

changeFileCallback(true, true);
// updated file is a schema file
} else if (
triggeredEvents.some(({ changedPath }) =>
Expand Down
9 changes: 3 additions & 6 deletions packages/core/lib/render/views/iframe/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ module.exports = async function renderIframeComponent({
app.get("state").fileContents[
helpers.getDocumentationPathFromTemplatePath(templateFilePath)
];
const componentInfo =
app.get("state").fileContents[
helpers.getInfoPathFromTemplatePath(app, templateFilePath)
];
const schemaFilePath = helpers.getSchemaPathFromTemplatePath(
app,
templateFilePath
Expand Down Expand Up @@ -108,11 +104,12 @@ module.exports = async function renderIframeComponent({

let componentName = path.basename(path.dirname(file));

if (componentInfo) {
// @TODO
/*if (componentInfo) {
if (componentInfo.name) {
componentName = componentInfo.name;
}
}
}*/

let context;

Expand Down
3 changes: 1 addition & 2 deletions packages/core/lib/state/file-contents.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ async function getFilePaths(app) {
)}.${files.templates.extension}`,
`${files.mocks.name}.${files.mocks.extension}`,
`${files.schema.name}.${files.schema.extension}`,
`${files.info.name}.${files.info.extension}`,
`data.${files.mocks.extension}`,
]) ||
helpers.fileIsDocumentationFile(res)
Expand Down Expand Up @@ -209,7 +208,7 @@ async function readFile(app, fileName) {
* and their content.
*
* @param {object} app - the express instance
* @returns {Promise} gets resolved with the content of all docs, mocks, schema, info files
* @returns {Promise} gets resolved with the content of all docs, mocks, schema files
*/
async function getFileContents(app) {
const fileContents = {};
Expand Down
33 changes: 8 additions & 25 deletions packages/core/lib/state/menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,12 @@ function hasComponentFileWithCorrectNameAsChild(app, directory) {
* @returns {object} adapted file tree object
*/
function getDataForLinkedDirectory(app, directory) {
const info =
app.get("state").fileContents[
path.join(
directory.path,
`${app.get("config").files.info.name}.${
app.get("config").files.info.extension
}`
)
];
const shortPath = helpers.getShortPathFromFullPath(app, directory.path);
const normalizedShortPath = helpers.normalizeString(shortPath);

return {
type: directory.type,
name: info && info.name ? info.name : directory.name,
name: directory.name.replaceAll("-", " "),
fullPath: directory.path,
shortPath,
normalizedShortPath,
Expand All @@ -79,7 +70,10 @@ function getDataForDocumentationFile(app, file) {

return {
type: file.type,
name: path.basename(file.name, ".md"),
name: path
.basename(file.name, ".md")
.replaceAll("-", " ")
.replaceAll("_", " "),
fullPath: file.path,
shortPath,
normalizedShortPath,
Expand All @@ -89,24 +83,13 @@ function getDataForDocumentationFile(app, file) {
}

/**
* @param {object} app - the express instance
* @param {object} directory - file tree object
* @returns {object} adapted file tree object
*/
function getDataForDirectory(app, directory) {
const info =
app.get("state").fileContents[
path.join(
directory.path,
`${app.get("config").files.info.name}.${
app.get("config").files.info.extension
}`
)
];

function getDataForDirectory(directory) {
return {
type: directory.type,
name: info && info.name ? info.name : directory.name,
name: directory.name.replaceAll("-", " "),
fullPath: directory.path,
index: directory.index,
id: helpers.normalizeString(directory.path),
Expand All @@ -124,7 +107,7 @@ function restructureDirectory(app, directory) {
if (hasComponentFileWithCorrectNameAsChild(app, directory)) {
item = getDataForLinkedDirectory(app, directory);
} else {
item = getDataForDirectory(app, directory);
item = getDataForDirectory(directory);
}

return item;
Expand Down
4 changes: 0 additions & 4 deletions packages/core/tests/lib/init/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,6 @@ describe("lib/init/config", () => {
extension: "css",
name: "index",
},
info: {
extension: "json",
name: "info",
},
js: {
extension: "js",
name: "index",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tests/mock-data/menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
},
{
"type": "directory",
"name": "link-list",
"name": "link list",
"fullPath": "/miyagi/tests/src/components/link-list",
"shortPath": "components/link-list",
"normalizedShortPath": "components-link-list",
Expand Down

0 comments on commit f6b89cd

Please sign in to comment.