Skip to content

Commit

Permalink
Add auto indentation for modules.json to template generator app for g…
Browse files Browse the repository at this point in the history
…it tracking
  • Loading branch information
Anonymxtrix committed Mar 22, 2021
1 parent e45c88f commit a58c40a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 38 deletions.
13 changes: 12 additions & 1 deletion modules.json
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
{"repeat":{"tabs":["Repeat"]}, "pix_n_flix":{"tabs":["Pixnflix"]}}
{
"repeat": {
"tabs": [
"Repeat"
]
},
"pix_n_flix": {
"tabs": [
"Pixnflix"
]
}
}
28 changes: 14 additions & 14 deletions templates/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,8 @@ const print = require('./print');
const utilities = require('./utilities');
const manifest = require('../modules.json');

async function addNew() {
const moduleName = await askModuleName();
const bundleDestination = `${paths.root}/src/bundles/${moduleName}`;
await fs.mkdir(bundleDestination, { recursive: true });
await fs.copyFile(paths.bundleTemplate, `${bundleDestination}/index.ts`);
await fs.writeFile(
paths.manifest,
JSON.stringify({ ...manifest, [moduleName]: { tabs: [] } })
);
print.success(
`Bundle for module ${moduleName} created at ${bundleDestination}.`
);
function check(moduleName) {
return Object.keys(manifest).includes(moduleName);
}

async function askModuleName() {
Expand All @@ -33,8 +23,18 @@ async function askModuleName() {
return name;
}

function check(moduleName) {
return Object.keys(manifest).includes(moduleName);
async function addNew() {
const moduleName = await askModuleName();
const bundleDestination = `${paths.root}/src/bundles/${moduleName}`;
await fs.mkdir(bundleDestination, { recursive: true });
await fs.copyFile(paths.bundleTemplate, `${bundleDestination}/index.ts`);
await fs.writeFile(
paths.manifest,
JSON.stringify({ ...manifest, [moduleName]: { tabs: [] } }, null, 2)
);
print.success(
`Bundle for module ${moduleName} created at ${bundleDestination}.`
);
}

module.exports = {
Expand Down
51 changes: 28 additions & 23 deletions templates/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,13 @@ const utilities = require('./utilities');
const modules = require('./module');
const manifest = require('../modules.json');

const existingTabs = Object.keys(manifest).reduce((accumulator, current) => {
return accumulator.concat(manifest[current].tabs);
}, []);
const existingTabs = Object.keys(manifest).reduce(
(accumulator, current) => accumulator.concat(manifest[current].tabs),
[]
);

async function addNew() {
const moduleName = await askModuleName();
const tabName = await askTabName();

// Copy module tab template into correct destination and show success message
const tabDestination = `${paths.root}/src/tabs/${tabName}`;
await fs.mkdir(tabDestination, { recursive: true });
await fs.copyFile(paths.tabTemplate, `${tabDestination}/index.tsx`);
await fs.writeFile(
paths.manifest,
JSON.stringify({
...manifest,
[moduleName]: { tabs: [...manifest[moduleName].tabs, tabName] },
})
);
print.success(
`Tab ${tabName} for module ${moduleName} created at ${tabDestination}.`
);
function check(tabName) {
return existingTabs.includes(tabName);
}

async function askModuleName() {
Expand All @@ -53,8 +38,28 @@ async function askTabName() {
return name;
}

function check(tabName) {
return existingTabs.includes(tabName);
async function addNew() {
const moduleName = await askModuleName();
const tabName = await askTabName();

// Copy module tab template into correct destination and show success message
const tabDestination = `${paths.root}/src/tabs/${tabName}`;
await fs.mkdir(tabDestination, { recursive: true });
await fs.copyFile(paths.tabTemplate, `${tabDestination}/index.tsx`);
await fs.writeFile(
paths.manifest,
JSON.stringify(
{
...manifest,
[moduleName]: { tabs: [...manifest[moduleName].tabs, tabName] },
},
null,
2
)
);
print.success(
`Tab ${tabName} for module ${moduleName} created at ${tabDestination}.`
);
}

module.exports = {
Expand Down

0 comments on commit a58c40a

Please sign in to comment.