Skip to content

Commit 74f6ae4

Browse files
committed
Merge branch 'main' of github.com:ngwattcos/react-python into main
2 parents c96598c + 699ea79 commit 74f6ae4

11 files changed

+271
-2796
lines changed

.gitmodules

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
[submodule "DbConnector"]
2-
branch = main
1+
[submodule "pythonxyc"]
2+
path = pythonxyc
3+
url = [email protected]:ngwattcos/pythonxyc.git

.npmignore

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# The compiler
2+
pythonxyc/
3+
4+
# Masc stuff
5+
.DS_Store
6+
7+
# Logs
8+
logs
9+
*.log
10+
npm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
lerna-debug.log*
14+
15+
# Runtime data
16+
pids
17+
*.pid
18+
*.seed
19+
*.pid.lock
20+
21+
# Directory for instrumented libs generated by jscoverage/JSCover
22+
lib-cov
23+
24+
# Coverage directory used by tools like istanbul
25+
coverage
26+
*.lcov
27+
28+
# nyc test coverage
29+
.nyc_output
30+
31+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
32+
.grunt
33+
34+
# Bower dependency directory (https://bower.io/)
35+
bower_components
36+
37+
# node-waf configuration
38+
.lock-wscript
39+
40+
# Compiled binary addons (https://nodejs.org/api/addons.html)
41+
build/Release
42+
43+
# Dependency directories
44+
node_modules/
45+
jspm_packages/
46+
47+
# Snowpack dependency directory (https://snowpack.dev/)
48+
web_modules/
49+
50+
# TypeScript cache
51+
*.tsbuildinfo
52+
53+
# Optional npm cache directory
54+
.npm
55+
56+
# Optional eslint cache
57+
.eslintcache
58+
59+
# Microbundle cache
60+
.rpt2_cache/
61+
.rts2_cache_cjs/
62+
.rts2_cache_es/
63+
.rts2_cache_umd/
64+
65+
# Optional REPL history
66+
.node_repl_history
67+
68+
# Output of 'npm pack'
69+
*.tgz
70+
71+
# Yarn Integrity file
72+
.yarn-integrity
73+
74+
# dotenv environment variables file
75+
.env
76+
.env.test
77+
78+
# parcel-bundler cache (https://parceljs.org/)
79+
.cache
80+
.parcel-cache
81+
82+
# Next.js build output
83+
.next
84+
out
85+
86+
# Nuxt.js build / generate output
87+
.nuxt
88+
dist
89+
90+
# Gatsby files
91+
.cache/
92+
# Comment in the public line in if your project uses Gatsby and not Next.js
93+
# https://nextjs.org/blog/next-9-1#public-directory-support
94+
# public
95+
96+
# vuepress build output
97+
.vuepress/dist
98+
99+
# Serverless directories
100+
.serverless/
101+
102+
# FuseBox cache
103+
.fusebox/
104+
105+
# DynamoDB Local files
106+
.dynamodb/
107+
108+
# TernJS port file
109+
.tern-port
110+
111+
# Stores VSCode versions used for testing VSCode extensions
112+
.vscode-test
113+
114+
# yarn v2
115+
.yarn/cache
116+
.yarn/unplugged
117+
.yarn/build-state.yml
118+
.yarn/install-state.gz
119+
.pnp.*

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# react-python
2-
A Python-like syntax that compiles down into JSX.
2+
npm module wrapper for pythonxyc, a Python-to-React transpiler.

bin/clean.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
*
3+
* Cleans the output directory (as specified by config.json) of ANY files
4+
*/

bin/index.js

+29-49
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,56 @@
11
#!/usr/bin/env node
22

3-
var { watch } = require("gulp");
4-
53
/**
6-
*
4+
* This file will call 'gulp'
75
*
86
* Needs to be made configurable with an input directory and output directory.
97
* Probably should be done through through user-provided config file (their project package.json?)
108
*
119
*/
1210

11+
const fs = require("fs");
12+
const chokidar = require("chokidar");
13+
14+
// probably canges this to ./../react-python-config.json
15+
new Promise((resolve, reject) => {
16+
let rawConfig = fs.readFileSync('./react-python-config.json');
17+
let configData = JSON.parse(rawConfig);
18+
resolve(configData);
19+
}).then(configData => {
20+
// should be read from json
21+
if (!verifyInputDir(configData.inDir)) {
22+
throw new Error("invalid input dir, run react-python-setup again");
23+
}
24+
if (!verifyOutputDir(configData.inDir)) {
25+
throw new Error("invalid output dir, run react-python-setup again");
26+
}
27+
return configData;
28+
}).then(configData => {
29+
console.log(`input directory: ${configData.inDir}`);
30+
console.log(`output directory: ${configData.outDir}`);
1331

32+
chokidar.watch(configData.inDir).on('all', function(event, path) {
33+
console.log(`${event}: ${path}`);
34+
});
35+
}).catch(err => {
36+
console.log(err);
37+
});
1438

15-
exports.print = function() {
16-
console.log("running lol");
17-
}
18-
19-
exports.print();
20-
21-
let inputDir = "";
22-
let outputDir = "";
23-
24-
exports.setInputDir = function(dir) {
25-
if (verifyInputDir(dir)) {
26-
inputDir = dir;
27-
console.log("Set input dir to: " + inputDir);
28-
return;
29-
}
3039

31-
throw new Error("Input directory not properly set.")
32-
}
3340

34-
exports.setOutputDir = function(dir) {
35-
if (verifyOutputDir(dir)) {
36-
outputDir = dir;
37-
console.log("Set output dir to: " + outputDir);
38-
return;
39-
}
4041

41-
throw new Error("Output directory not properly set.")
42-
}
4342

4443
/**
45-
* Verifies that valid Python files exist in this dir.
44+
* Verifies that input dir exists
4645
*/
4746
function verifyInputDir() {
4847
return true;
4948
}
5049

5150
/**
52-
* Verifies that
51+
* Verifies that output dir exists
5352
*/
5453
function verifyOutputDir() {
5554
return true;
5655
}
5756

58-
/**
59-
* Invokes the transpiler
60-
*/
61-
function compile() {
62-
return Promise((resolve, reject) => {
63-
console.log("i am so compiling right now");
64-
})
65-
}
66-
67-
/**
68-
* Watches inputDir for changes.
69-
* On change, call compile on inputDir and rewrite file specified
70-
*/
71-
exports.watchAndCompile = function(done) {
72-
watch(["" + inputDir + "/*.py"], function() {
73-
compile()
74-
.then(done);
75-
})
76-
}

bin/setup.js

+28-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const figlet = require('figlet');
77
const fs = require('fs');
88

99

10+
// probably canges this to ./../react-python-config.json
1011
const fileName = './react-python-config.json';
1112

1213

@@ -16,18 +17,37 @@ const runSetup = async () => {
1617
console.log(
1718
figlet.textSync('React-Python', {
1819
horizontalLayout: 'default'
19-
}));
20+
})
21+
);
2022

2123
const config = await prompts.initTranspiler();
2224

2325
return config;
2426
}
2527

2628

27-
runSetup().then((config) => {
28-
console.log(config);
29-
fs.writeFile(fileName, JSON.stringify(config, null, 2), function writeJSON(err) {
30-
if (err) {
31-
return console.log(err)
32-
};
33-
})});
29+
runSetup()
30+
.then(promptResult => {
31+
const { OCamlInstalled, ...config } = promptResult;
32+
33+
if (!OCamlInstalled) {
34+
throw 'Please install OCaml in the meantime.'
35+
}
36+
37+
return config;
38+
})
39+
.then(config => {
40+
return new Promise((resolve, reject) => {
41+
fs.writeFile(fileName, JSON.stringify(config, null, 2), function writeJSON(err) {
42+
if (err) {
43+
reject(err);
44+
};
45+
resolve(`Wrote to configuration file: ${fileName}`);
46+
})
47+
})})
48+
.then(successMsg => {
49+
console.log(successMsg);
50+
})
51+
.catch(err => {
52+
console.log(err);
53+
});

lib/prompts.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,16 @@ module.exports = {
1919
validate: () => {
2020
return true;
2121
}
22+
},
23+
{
24+
name: 'OCamlInstalled',
25+
type: 'confirm',
26+
message: 'Is OCaml installed on your machine?',
27+
validate: () => {
28+
return true;
29+
}
2230
}
2331
];
2432
return inquirer.prompt(questions);
25-
}
33+
},
2634
}

0 commit comments

Comments
 (0)