Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposed changes from B and J, including launching webboard #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 81 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@ import onboarding from "./onboarding.js";

import figlet from 'figlet';

import os from 'os';

// from stackoverflow, but
// TODO: do this without fileURLToPath? I think the "real" node way is to use URLs throughout
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename);

const userFolderPath = os.homedir();
const fileName = '.st.txt';

const filePath = path.join(userFolderPath, fileName);

// function log(msg) {
// console.log(`STEACC>> ${msg}`)
// }
Expand All @@ -40,6 +47,9 @@ switch (process.argv[2]) {
case "version":
console.log(version);
break
case "ver":
console.log(version);
break
case "figlet-fonts":
child_process.exec('figlet -l', (err, stdout, stderr) => {
if (err) {
Expand All @@ -53,12 +63,50 @@ switch (process.argv[2]) {
}
})
break
case "winget":
const ps = child_process.spawn('powershell', ['-File', 'run-winget.ps1'], { stdio: "inherit", cwd: __dirname });

ps.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
case "setup":
setup()
break
case "webboard":
if (process.argv[3] && process.argv[3] === "modify") {
URL = await askQuestion("Enter the URL of the web board: ")
const writeToFile = (filePath, content) => {
fs.writeFile(filePath, content, (err) => {
if (err) {
console.error('Error writing to the file:', err);
} else {
console.log('File .st.txt written successfully in the user folder');
}
});
};
const openURLInBrowser = (url) => {
const start = process.platform == 'darwin' ? 'open' :
process.platform == 'win32' ? 'start' :
'xdg-open';
exec(`${start} ${url}`, (err) => {
if (err) {
console.error('Error opening URL in browser:', err);
} else {
console.log('URL opened in browser successfully');
}
});
};

// Check if the file already exists
if (fs.existsSync(filePath)) {
console.log('File .st.txt already exists. Clearing contents and writing new URL.');
writeToFile(filePath, URL);
} else {
// Create the file '.st.txt' and write the URL to it
console.log('Creating file .st.txt and writing URL.');
writeToFile(filePath, URL);
}
} else {
// open in browser
if (fs.existsSync(filePath)) {
const URL = fs.readFileSync(filePath, 'utf8').trim();
openURLInBrowser(URL);
}
}
break
default:
let name, projectName
Expand Down Expand Up @@ -160,3 +208,30 @@ function update() {
console.log(stdout);
})
}
function installp5p() {
console.log("Installing p5.play...") // TODO: replace with npm install p5play when it's available in npm.
child_process.exec('npm i p5play', (err, stdout, stderr) => {
if (err) {
console.error(err);
return;
}
console.log(stdout);
})
}

function setup() {
// Made with <3 by GustyCube (Bennett Schwartz) and Joshua Kellman
console.log("Initializing setup...")
console.log("Starting App installation")
const ps = child_process.spawn('powershell', ['-File', 'run-winget.ps1'], { stdio: "inherit", cwd: __dirname });
console.log("Installing VS Code extentions")
const ExentionInstall = child_process.spawn('powershell', ['-File', 'installExtention.ps1'], { stdio: "inherit", cwd: __dirname });
installp5p()
ps.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
ExentionInstall.on('close', (code) => {
console.log(`p5.play extention installation exited with code ${code}`);
});
}
export { setup }
8 changes: 8 additions & 0 deletions installExtention.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Made with <3 by GustyCube (Bennett Schwartz) and Joshua Kellman
Write-Output "Installing P5-VSCode"
code --install-extension samplavigne.p5-vscode
Write-Output "Installed P5-VSCode"
Write-Output "Installing Live Server"
code --install-extension ritwickdey.liveserver
Write-Output "Installed Live Server"
pause
51 changes: 23 additions & 28 deletions onboarding.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,31 @@
import * as fs from 'fs'
import child_process from 'child_process'
import { marked } from 'marked';
import { markedTerminal } from 'marked-terminal';
import { createDirectives } from 'marked-directive';
import { askQuestion } from './question-asker.js'
import stripAnsi from 'strip-ansi';
import path from 'node:path'
import figlet from 'figlet';
import { fileURLToPath } from 'node:url';
import { setup } from './index.js';


let contentDir = ""
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename);

async function run(name, cd) {

contentDir = cd

console.log(
figlet.textSync(`Welcome,`, {
width: process.stdout.columns
})
)
console.log(
figlet.textSync(`${name}`, {
font: 'Small Keyboard',
width: process.stdout.columns
})
)

await askQuestion("Press ENTER to continue..."); // TODO: any key
console.log(figlet.textSync(`Welcome,`, { width: process.stdout.columns }));
console.log(figlet.textSync(`${name}`, { font: 'Small Keyboard', width: process.stdout.columns }));

await askQuestion("Press ENTER to continue...");
console.clear();



const text = fs.readFileSync(path.join(contentDir, 'aup.md'), 'utf8');

marked.use(markedTerminal(), createDirectives([{
// TODO: I don't love this syntax.
// It seems to violate John Gruber's original principle of
// Markdown being readable as plain text.
// I'd prefer something that looks like HTML, e.g., <center>...</center>.
level: "block",
marker: "::",
renderer(token) {
Expand All @@ -47,7 +35,7 @@ async function run(name, cd) {
const pad = Math.floor((process.stdout.columns - len) / 2);
return `${" ".repeat(pad)}${parsedText.trim()}\n`;
}
return false
return false;
}
}]));

Expand All @@ -56,18 +44,16 @@ async function run(name, cd) {

await askForAgreementWithRulesAndExitIfNotAgreed();

displayHardwareRules()

displayHardwareRules();
await askForAgreementWithRulesAndExitIfNotAgreed();

await installDeps(); //! Ensure this completes before proceeding

console.log("Creating directory...");
console.log(`mkdir C:\\${name}\\`);
fs.mkdirSync(`C:\\${name}\\`);

const data = {
"all": Date.now()
};

const data = { "all": Date.now() };
const jsonData = JSON.stringify(data, null, 2);
fs.writeFileSync(`C:\\${name}\\agreed.json`, jsonData);
}
Expand All @@ -92,4 +78,13 @@ async function askForAgreementWithRulesAndExitIfNotAgreed() {
}
}

async function installDeps() {
// Made with <3 by GustyCube (Bennett Schwartz) and Joshua Kellman
const answer = await askQuestion("Do you want to install programs? Enter YES or NO: ")

if (answer === "YES") {
setup()
}
}

export default { run }
4 changes: 2 additions & 2 deletions package-lock.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 @@ -32,10 +32,11 @@
"marked-directive": "^1.0.5",
"marked-terminal": "^7.0.0",
"open": "^9.1.0",
"os": "^0.1.2",
"server-destroy": "^1.0.1",
"strip-ansi": "^7.1.0"
},
"devDependencies": {
"genversion": "^3.2.0"
}
}
}
4 changes: 4 additions & 0 deletions run-winget.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Made with <3 by GustyCube (Bennett Schwartz) and Joshua Kellman
Write-Output "Installing Windows Terminal"
winget install -e --id Microsoft.WindowsTerminal
Write-Output "Installing Visual Studio Code"
winget install -e --id Microsoft.VisualStudioCode
Write-Output "App install complete."
pause
7 changes: 7 additions & 0 deletions vscodecli.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Made with <3 by GustyCube (Bennett Schwartz) and Joshua Kellman
$searchPath = "~\AppData\Local\Programs\Microsoft VS Code\bin"
if ($env:Path -split ";" -contains $searchPath) {
Write-Output "Path exists in the PATH environment variable."
} else {
Write-Output "Path does not exist in the PATH environment variable. You may need to install it."
}
Loading