Skip to content

Commit 06c1519

Browse files
committed
managing env
1 parent 9f348f2 commit 06c1519

File tree

13 files changed

+69
-46
lines changed

13 files changed

+69
-46
lines changed

_templates/component_js.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import PlayHeader from 'common/playlists/PlayHeader';
22
import './styles.%PLAY_STYLE%';
33

4-
function %PLAY_PASCAL_NAME%(props) {
4+
function %PLAY_TITLE_NAME%(props) {
55

66
// Your Code Start below.
77

@@ -12,7 +12,7 @@ function %PLAY_PASCAL_NAME%(props) {
1212
<div className="play-details-body">
1313
{/* Your Code Starts Here */}
1414
<div>
15-
<h1>Play Details - %PLAY_TITLE_NAME%</h1>
15+
<h1>Play Details - %PLAY_TITLE_STRING%</h1>
1616
<p>
1717
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
1818
Pellentesque euismod, urna eu tincidunt consectetur,
@@ -27,4 +27,4 @@ function %PLAY_PASCAL_NAME%(props) {
2727
);
2828
}
2929

30-
export default %PLAY_PASCAL_NAME%;
30+
export default %PLAY_TITLE_NAME%;

_templates/component_ts.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import PlayHeader from 'common/playlists/PlayHeader';
33
import './styles.{{style}}';
44

5-
function {{pascalCase name}}(props:any) {
5+
function %PLAY_TITLE_NAME%(props) {
66

77
// Your Code Start below.
88

@@ -13,7 +13,7 @@ function {{pascalCase name}}(props:any) {
1313
<div className="play-details-body">
1414
{/* Your Code Starts Here */}
1515
<div>
16-
<h1>Play Details - {{titleCase name}}</h1>
16+
<h1>Play Details - %PLAY_TITLE_STRING%</h1>
1717
<p>
1818
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
1919
Pellentesque euismod, urna eu tincidunt consectetur,
@@ -28,4 +28,4 @@ function {{pascalCase name}}(props:any) {
2828
);
2929
}
3030

31-
export default {{pascalCase name}};
31+
export default %PLAY_TITLE_NAME%;

bin/global.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
import { invoke_process } from "../lib/index.js";
44
import { CONSOLE_COLORS } from "../util/const.js";
5+
import fs from "fs";
6+
// import * as meta from "";
57

68
// Displays the text in the console
7-
9+
let meta = JSON.parse(fs.readFileSync("package.json", "utf-8"));
810
console.log(
911
CONSOLE_COLORS.FgGreen,
1012
"┌─────────────────────────────────────────────────────────────────────────┐"
@@ -16,13 +18,13 @@ console.log(
1618
" | Welcome to |"
1719
);
1820
console.log(
19-
" | React Play Development Kit |"
21+
` | Create Rect Play (v ${meta.version}) |`
2022
);
2123
console.log(
2224
" | |"
2325
);
2426
console.log(
25-
" | For help hit : rpdk -h/help |"
27+
" | For help hit : create-react-play -h/help |"
2628
);
2729
console.log(
2830
" └─────────────────────────────────────────────────────────────────────────┘"

hooks/env_hooks.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ export const prepare_environment = (data) => {
77
processPlayContent(data);
88
processPlayIndex(data);
99
};
10+
11+
export const prepare_content_index = () => {
12+
processPlayIndex();
13+
};

lib/index.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,6 @@ import { ALL_ARGS_TYPES } from "../util/const.js";
55
import * as hooks from "../hooks/index.js";
66
import { Log } from "../log/index.js";
77

8-
const properties = [
9-
{
10-
name: "issue",
11-
description: "Enter issue number",
12-
validator: /^[0-9]*$/,
13-
warning: "Issue can only be numbers",
14-
},
15-
{
16-
name: "issue_details",
17-
description: "Enter issue details (max 5 words)",
18-
validator: /^[a-zA-Z0-9]{1,5}$/,
19-
warning: "Maximum length can be five words",
20-
},
21-
];
22-
238
export const invoke_process = async () => {
249
// hooks.basic_check_shell_connectivity();
2510
// Step 1: Sanity check
@@ -96,6 +81,11 @@ export const invoke_process = async () => {
9681
// console.log("> Starting the application");
9782
// // Step 8: yarn/npm start
9883
break;
84+
case "prepare":
85+
Log.log("Preparing environment for build process");
86+
// Preparing src/plays/index.js
87+
hooks.prepare_content_index();
88+
break;
9989
case "help":
10090
Log.newLine();
10191
Log.segementStart(`Help instructions`);

lib/services/datasource/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
toKebabCase,
66
toPascalcase,
77
toTitleCase,
8+
toTitleCaseTrimmed,
89
} from "../../../util/string.js";
910

1011
// const URL = `${process.env.NHOST_ROTOCOL}://${process.env.NHOST_SERVER}/${process.env.NHOST_ENDPOINT}`;
@@ -74,7 +75,8 @@ export const loadAllPlaysAsync = () => {
7475
const processPlayInformation = (play) => {
7576
play.kebab_name = toKebabCase(play.name);
7677
play.pascal_name = toPascalcase(play.name);
77-
play.title_name = toTitleCase(play.name);
78+
play.title_string = toTitleCase(play.name);
79+
play.title_name = toTitleCaseTrimmed(play.name);
7880
play.level = play.level.name;
7981
return play;
8082
};

lib/services/datasource/query.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const FETH_ALL_PLAYS = {
1313
"featured",
1414
"github",
1515
"id",
16+
"dev_mode",
1617
"language",
1718
{ level: ["name"] },
1819
"name",

lib/services/template/play_content.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import fs from "fs";
22
import * as path from "path";
3-
import {
4-
replaceAll,
5-
toKebabCase,
6-
toPascalcase,
7-
toTitleCase,
8-
} from "../../../util/string.js";
3+
import { replaceAll } from "../../../util/string.js";
94
import { fileURLToPath } from "url";
105
import { Log } from "../../../log/index.js";
116

@@ -85,7 +80,7 @@ const processTemplate = (play, template_type, play_path) => {
8580
if (template_type === "js" || template_type === "ts") {
8681
target_template_name = target_template_name.replace(
8782
"component",
88-
play.kebab_name
83+
play.title_name
8984
);
9085
}
9186
const file_path = `${__filename}/${TEMPLATE_DIRECTORY}/${file_name}`;

lib/services/template/play_index.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { isValidString } from "../../../util/string.js";
55
import { loadAllPlaysAsync } from "../datasource/index.js";
66

77
const INDEX_FILE_PATH = `${DIRECTORIES.PLAY}/index.js`;
8-
export const processPlayIndex = (play) => {
8+
export const processPlayIndex = () => {
99
loadAllPlaysAsync().then((plays) => {
1010
const all_dirs = getAllPlaysLocally();
1111
writeFile(plays, all_dirs);
@@ -23,16 +23,33 @@ const writeFile = (plays, dirs) => {
2323
"// Do not modify the content of this file"
2424
);
2525
plays.forEach((play) => {
26-
if (dirs.indexOf(play.kebab_name) > -1) {
27-
Log.log(`Play found locally : ${play.kebab_name}`);
26+
let playPath = play.kebab_name;
27+
if (play.path) {
28+
const pathSegmentation = play.path.split("/");
29+
if (pathSegmentation.length > 1 && play.dev_mode !== true) {
30+
playPath = pathSegmentation[2];
31+
if (playPath !== play.kebab_name) {
32+
Log.log(
33+
`Play name and path is not matching : ${
34+
play.name
35+
}(${playPath} >> ${JSON.stringify(play)})`
36+
);
37+
}
38+
}
39+
}
40+
Log.log(`Checking play locally: ${play.name}(${playPath})`);
41+
if (dirs.indexOf(playPath) > -1) {
42+
Log.log(`Play found locally : ${playPath}`);
2843
fs.appendFileSync(
2944
INDEX_FILE_PATH,
3045
`\n export { default as ${
31-
isValidString(play.component) || play.pascal_name
32-
} } from 'plays/${play.kebab_name}/${
33-
isValidString(play.component) || play.kebab_name
46+
isValidString(play.component) || play.title_name
47+
} } from 'plays/${playPath}/${
48+
isValidString(play.component) || play.title_name || play.kebab_name
3449
}';`
3550
);
51+
} else {
52+
Log.warning(`Play not found locally : ${play.name}(${playPath})`);
3653
}
3754
});
3855
};

log/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
let node = "CRP";
2-
const log = (text, ignoreHeader = false) => {
3-
console.log(` ${ignoreHeader ? "" : `${getDate()}: ${node} : `} ${text}`);
2+
const log = (text, ignoreHeader = false, node = "INFO") => {
3+
console.log(
4+
` ${node} : ${ignoreHeader ? "" : `${getDate()}: ${node} : `} ${text}`
5+
);
6+
};
7+
8+
const warning = (text, ignoreHeader = false) => {
9+
log(text, ignoreHeader, "WARNING");
410
};
511

612
const header = (text) => {
@@ -36,6 +42,7 @@ const getDate = () => {
3642

3743
export const Log = {
3844
log,
45+
warning,
3946
header,
4047
highlight,
4148
segementEnd,

0 commit comments

Comments
 (0)