Skip to content

Commit

Permalink
Adds new build script
Browse files Browse the repository at this point in the history
  • Loading branch information
abeisgoat committed Jul 24, 2019
1 parent a8c0413 commit 2094e68
Show file tree
Hide file tree
Showing 7 changed files with 281 additions and 1,557 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/**/node_modules/**
firepit-**
dist/**
.idea/**
config.js
48 changes: 48 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
const { mkdir, cat, cd, rm, find, echo, exec, mv } = require("shelljs");
const npm = (...args) => exec(["npm", ...args].join(" "));

cd("vendor");

echo("-- Cleaning vendors...");
rm("-f", "config.js");
rm("-rf", "node_modules");

echo("-- Installing new vendor/node_modules");
npm("install", "firebase-tools@latest");

echo("-- Removing native platform addons (.node)");
find(".")
.filter(function(file) {
return file.match(/\.node$/);
})
.forEach(file => {
echo(file);
rm(file);
});
cd("..");

echo("-- Cleaning builds...");
rm("-rf", "dist/*");

echo("-- Building headless binaries...");

const headless_config = cat("config.template.js").replace(
"headless_value",
"true"
);
echo(headless_config).to("config.js");
npm("run", "pkg");
mkdir("-p", "dist/headless");
mv("dist/firpeit-*", "dist/headless");

echo("-- Building headed binaries...");

const headful_config = cat("config.template.js").replace(
"headless_value",
"false"
);
echo(headful_config).to("config.js");
npm("run", "pkg");
mkdir("-p", "dist/headed");
mv("dist/firepit-*", "dist/headed");
6 changes: 0 additions & 6 deletions build.sh

This file was deleted.

12 changes: 12 additions & 0 deletions config.template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
/*
Headless mode forces the firepit builds to exactly imitate firebase-tools,
so the resulting binary "firebase" is a drop in replacement for the script
installed via npm. This is the behavior for CI / Cloud Shell / Docker etc.
When headless mode is disabled, the "double click" experience is enabled
which allows the binary to spawn a terminal on Windows and Mac. The is the
behavior for desktop users.
*/
headless: headless_value
};
76 changes: 43 additions & 33 deletions firepit.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ shell.config.silent = true;
const runtime = require("./runtime");
const version = require("./package.json").version;

let config;
try {
config = require("./config");
} catch (err) {
console.warn("Invalid Firepit configuration, this may be a broken build.");
process.exit(2);
}

function SetWindowTitle(title) {
if (process.platform === "win32") {
process.title = title;
Expand Down Expand Up @@ -107,7 +115,10 @@ debug(`Welcome to firepit v${version}!`);
return;
}

if (isTopLevel) {
if (isTopLevel && !config.headless) {
/*
If firepit is set to be headful then open a shell if needed and spawn the welcome screen
*/
const welcome_path = await getSafeCrossPlatformPath(
isWindows,
path.join(__dirname, "/welcome.js")
Expand Down Expand Up @@ -157,6 +168,9 @@ debug(`Welcome to firepit v${version}!`);
});
}
} else {
/*
If firepit is set to be headless, then just fall through to the normal flow.
*/
SetWindowTitle("Firebase CLI");
await firepit();
}
Expand Down Expand Up @@ -273,15 +287,21 @@ async function firepit() {
return ImitateNode();
}

const firebaseBins = FindTool("firebase-tools/lib/bin/firebase");
if (firebaseBins.length) {
const firebaseBin = firebaseBins[0];
debug(`CLI install found at "${firebaseBin}", starting fork...`);
ImitateFirebaseTools(firebaseBin);
} else {
debug(`CLI not found! Invoking npm...`);
let firebaseBins = FindTool("firebase-tools/lib/bin/firebase");
if (!firebaseBins.length) {
debug(`CLI not found! Invoking setup...`);
SetupFirebaseTools();
firebaseBins = FindTool("firebase-tools/lib/bin/firebase");
}

if (!firebaseBins.length) {
console.warn(`firebase-tools setup failed.`);
process.exit(2);
}

const firebaseBin = firebaseBins[0];
debug(`CLI install found at "${firebaseBin}", starting fork...`);
ImitateFirebaseTools(firebaseBin);
}

function ImitateNPM() {
Expand Down Expand Up @@ -321,36 +341,26 @@ function ImitateNode() {

function SetupFirebaseTools() {
debug(`Attempting to install to "${installPath}"`);
console.log(`Please wait while the Firebase CLI downloads...`);

const nodeModulesPath = path.join(installPath, "lib");
const binPath = path.join(installPath, "bin");
console.log(shell.mkdir("-p", nodeModulesPath));
console.log(shell.mkdir("-p", binPath));
console.log(
shell.cp("-R", path.join(__dirname, "vendor/*"), nodeModulesPath)
debug(shell.mkdir("-p", nodeModulesPath).toString());
debug(shell.mkdir("-p", binPath).toString());
debug(
shell.cp("-R", path.join(__dirname, "vendor/*"), nodeModulesPath).toString()
);
console.log(
shell.ln(
"-sf",
path.join(
nodeModulesPath,
"node_modules/firebase-tools/lib/bin/firebase.js"
),
path.join(binPath, "firebase")
)
debug(
shell
.ln(
"-sf",
path.join(
nodeModulesPath,
"node_modules/firebase-tools/lib/bin/firebase.js"
),
path.join(binPath, "firebase")
)
.toString()
);

/*process.argv = [
...process.argv.slice(0, 2),
"is:npm",
"install",
"-g",
"--verbose",
"npm",
"firebase-tools"
];
ImitateNPM();*/
}

function ImitateFirebaseTools(binPath) {
Expand Down
Loading

0 comments on commit 2094e68

Please sign in to comment.