Skip to content
This repository has been archived by the owner on Nov 23, 2022. It is now read-only.

Commit

Permalink
Added basic file/folder checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
valera-rozuvan committed Oct 26, 2020
1 parent 0b4a6e6 commit 50c01bb
Show file tree
Hide file tree
Showing 5 changed files with 274 additions and 17 deletions.
121 changes: 116 additions & 5 deletions bin/main.js

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

2 changes: 1 addition & 1 deletion bin/main.js.map

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

51 changes: 47 additions & 4 deletions npm-shrinkwrap.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"clean": "rm -rf ./bin/*"
},
"dependencies": {
"mdlinkc": "0.0.3"
"chalk": "^4.1.0",
"mdlinkc": "0.0.4"
},
"devDependencies": {
"@types/node": "10.12.18",
Expand Down
114 changes: 108 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,117 @@
import { AppVersion } from './app-version';
import { Mdlinkc } from 'mdlinkc';
import * as chalk from 'chalk'
import * as path from 'path'

import { AppVersion } from './app-version';

function greeter(msg: string) {
return msg;
}

const helloMsg = `mdlinkc v${AppVersion.version}`;

const helloMsg = `mdlinkc-cli v${AppVersion.version}`;
console.log(greeter(helloMsg));
console.log('');

Mdlinkc.getLinks().forEach((link, id) => {
console.log(`[link ${id}]: ${link}`);
});
const passSymbol = '\u2714'
const failSymbol = '\u2716'

async function testDir(dirName) {
let status = await Mdlinkc.checkIfDirExists(dirName)

if (status) {
console.log(`[${chalk.green(passSymbol)}] ${chalk.bold(dirName)} directory exists.`)
return 1
} else {
console.log(`[${chalk.red(failSymbol)}] ${chalk.bold(dirName)} directory does NOT exist.`)
return 0
}
}

async function checkRequiredDirs() {
let testDirCounter = 0
const dirsToTest = ['templates', 'contents', 'configs', 'scripts']
for (let c1 = 0; c1 < dirsToTest.length; c1 += 1) {
const dir = dirsToTest[c1]
testDirCounter += await testDir(dir)
}
if (testDirCounter !== 4) {
console.log('')
console.log('Some directories are missing. Exiting ...')
process.exit(1)
}
}

async function loadConfigFile(configName) {
const shortPath = `./configs/${configName}.js`
const fullPath = path.join(process.cwd(), shortPath)

let config
try {
config = require(fullPath)
console.log(`[${chalk.green(passSymbol)}] ${chalk.bold(shortPath)} config file was loaded.`)
return config
} catch (err) {
console.log(`[${chalk.red(failSymbol)}] ${chalk.bold(shortPath)} config file could NOT be loaded.`)
return null
}
}

async function loadAllConfigs(configs) {
let configCounter = 0
const configsToLoad = ['pages', 'variables', 'meta']
for (let c1 = 0; c1 < configsToLoad.length; c1 += 1) {
const configName = configsToLoad[c1]
configs[configName] = await loadConfigFile(configName)

if (configs[configName] !== null) {
configCounter += 1
}
}
if (configCounter !== 3) {
console.log('')
console.log('Some configs are missing. Exiting ...')
process.exit(1)
}
}

async function printNumThreads(configs) {
console.log('configs.meta = ', configs.meta)
console.log('configs.meta.threads = ', configs.meta.threads)
}

async function printFirstPage(configs) {
console.log('configs.pages = ', configs.pages)
console.log('configs.pages[0] = ', configs.pages[0])
}

async function printAuthorVariable(configs) {
console.log('configs.variables = ', configs.variables)
console.log('configs.variables.AUTHOR = ', configs.variables.AUTHOR)
}

async function run(configs) {
console.log('[DIRS]')
await checkRequiredDirs()
console.log('')

console.log('[CONFIGS]')
await loadAllConfigs(configs)
console.log('')

await printNumThreads(configs)
console.log('')

await printFirstPage(configs)
console.log('')

await printAuthorVariable(configs)
console.log('')
}

const configs = {
pages: null,
variables: null,
meta: null
}

run(configs)

0 comments on commit 50c01bb

Please sign in to comment.