Skip to content

Commit

Permalink
using json config now (#10)
Browse files Browse the repository at this point in the history
using json config now
  • Loading branch information
alechp authored Jul 15, 2019
2 parents 67abfa0 + 62c4371 commit c353372
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 57 deletions.
17 changes: 0 additions & 17 deletions .protato.js

This file was deleted.

15 changes: 15 additions & 0 deletions .protato.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"parent": {
"dir": "sandbox/node-starter"
},
"children": [
{
"dir": "sandbox/npm-starter-sample-module",
"src": "src"
},
{
"dir": "sandbox/library-genesis",
"src": "src"
}
]
}
2 changes: 1 addition & 1 deletion build/main.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "protato-lib",
"version": "0.2.3",
"version": "0.2.4",
"main": "build/main.js",
"license": "MIT",
"repository": {
Expand Down
47 changes: 24 additions & 23 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
const log = console.log;
import path from "path";
import isEmpty from "is-empty";
import fs from "fs-extra";
import { getWatcherConfig } from "./parser";
import { initWatcher } from "./watcher";
import { printLine, printMirror } from "tacker";
import { pathsExistAsync } from "./utilities";
import chalk from "chalk";

export function init(cwd = process.env.configRootDir || process.cwd(), config) {
export async function init(
cwd = process.env.configRootDir || process.cwd(),
oConfigOverride
) {
let oConfig;
if (!isEmpty(config)) {
oConfig = config;
printLine("green");
printMirror({ oConfig }, "green", "grey");
printLine("green");
if (!isEmpty(oConfigOverride)) {
printLine("cyan");
printMirror({ oConfigOverride }, "cyan", "grey");
printLine("cyan");
oConfig = oConfigOverride;
} else {
let protatoPath = path.join(cwd, ".protato.js");
let { config } = require(protatoPath);
oConfig = config;
pathsExistAsync(protatoPath, ".protato.js config not found")
.then(resp => {
printMirror({ resp }, "magenta", "grey");
let { config } = require(protatoPath);

printLine("blue");
printMirror({ protatoPath }, "blue", "grey");
printMirror({ config }, "blue", "grey");
printLine("blue");
})
.catch(err => {
log(`init failed\n ${err}`);
});
let protatoPath = path.resolve(cwd, ".protato.json");
printLine("cyan");
printMirror({ protatoPath }, "cyan", "grey");
//TODO: Change to fs.readJsonSync
// let { config } = require(protatoPath);
oConfig = await fs.readJson(protatoPath);
let pathInfo = await pathsExistAsync(
protatoPath,
".protato.json config not found"
);
let protatoPathFlag = pathInfo[0];
printMirror({ protatoPathFlag }, "cyan", "grey");
printLine("cyan");
}
let oWC = getWatcherConfig(oConfig);
let hWatcher = initWatcher(oWC);
hWatcher.getDirectories();
}

// init();
const inlineConfig = {
parent: {
dir: "sandbox/node-starter"
Expand Down
6 changes: 4 additions & 2 deletions src/linker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import path from "path";
import isEmpty from "is-empty";
import pkgDir from "pkg-dir";
import exec from "await-exec";
import fs from "fs-extra";

import { printLine, printMirror } from "tacker";

//TODO: Try using yalc instead
//TODO: Check to see whether yalc installed globally. If not, install. If install fails, throw err & explain

export async function linker(szModifiedFilePath, szParentDirPath) {
Expand All @@ -21,7 +21,9 @@ export async function linker(szModifiedFilePath, szParentDirPath) {
printMirror({ modifiedRootDir }, "magenta", "green");
let modifiedPkgPath = path.join(modifiedRootDir, "package.json");
printMirror({ modifiedPkgPath }, "magenta", "green");
const { name } = require(modifiedPkgPath);
//TODO: Change to fs.readJsonSync
const { name } = await fs.readJson(modifiedPkgPath);
// const { name } = require(modifiedPkgPath);
childModuleName = name;
printMirror({ childModuleName }, "blue", "grey");
printLine("blue");
Expand Down
13 changes: 5 additions & 8 deletions src/parser.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
/*
* Objective
1. Autodetect user config (ie. ".protato.js")
2. Transform user config into: [ watchTargets, watchOptions ]
2a. Do this via: getWatcherConfig
2ai. Do this via: [getWatchTargets, getWatchOptions]
*/

const log = console.log;
import path from "path";
import chalk from "chalk";
Expand Down Expand Up @@ -38,6 +30,11 @@ PTOParser.prototype.getWatcherTargets = function getWatcherTargets(
let rootDir = process.env.configRootDir || process.cwd();
let childDirPath = path.join(rootDir, dir, src);
let childPackagePath = path.join(rootDir, dir, "package.json");

printLine("magenta");
printMirror({ childDirPath }, "magenta", "grey");
printMirror({ childPackagePath }, "magenta", "grey");
printLine("magenta");
let pathsToCheck = [childDirPath, childPackagePath];

pathsExistSync(
Expand Down
5 changes: 5 additions & 0 deletions src/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export async function pathsExistSync(
try {
await fs.access(pathToCheck);
} catch (err) {
/*
TODO: Figure out why this is being thrown
? Array of paths failed ----------------------------------------------------------- Path did not exist
? TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be one of type string, Buffer, or URL. Received type object
*/
log(
`${chalk.red("Array of paths failed")} ${printLine(
"red"
Expand Down

0 comments on commit c353372

Please sign in to comment.