Skip to content

Commit

Permalink
fix: use the correct app_artifact_location
Browse files Browse the repository at this point in the history
  • Loading branch information
manekinekko committed Jul 2, 2020
1 parent 2668b6c commit 532be71
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 53 deletions.
9 changes: 4 additions & 5 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
const shell = require("shelljs");
const path = require("path");
const program = require("commander");
const builder = require("./builder");
const { readConfigFile } = require("./utils");
const builder = require("../src/builder");
const { readConfigFile } = require("../src/utils");

program
.name("swa")
Expand All @@ -30,7 +30,6 @@ const authUriPort = program.authUri.split(":").map(Number)[2] || 4242;
// parse the APP URI port or default to 4200
const appUriSegments = program.appUri.split(":");
const appUriPort = appUriSegments[2] || 4200;
const appUriAddress = (appUriSegments[1] || "localhost").replace("//", "");

// provide binaries
const concurrentlyBin = path.resolve(__dirname, "..", "./node_modules/.bin/concurrently");
Expand Down Expand Up @@ -76,10 +75,10 @@ const startCommand = [
// serve the app
// See available options for http-server: https://github.com/http-party/http-server#available-options
// Note: the --proxy options allows http-server to work with SPA routing.
`"${httpServerBin} ${app_artifact_location} -p ${appUriPort} -c-1 --proxy http://localhost:${appUriPort}?"`,
`"${httpServerBin} ${app_artifact_location} -p ${appUriPort} -c-1"`,

// serve the api
`"(cd ${api_location}; func start)"`,
`"(cd ${api_location}; func start --cors *)"`,
`--color=always`,
];

Expand Down
48 changes: 0 additions & 48 deletions bin/utils.js

This file was deleted.

File renamed without changes.
48 changes: 48 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const cookie = require("cookie");
const { default: fetch } = require("node-fetch");
const path = require("path");
const fs = require("fs");
const shell = require("shelljs");
const YAML = require("yaml");

module.exports.response = ({ context, status, headers, cookies, body = "" }) => {
let location;
Expand Down Expand Up @@ -69,3 +73,47 @@ module.exports.ɵɵUseGithubDevToken = async () => {
const token = await swaTokensResponse.json();
return token.github;
};

module.exports.readConfigFile = () => {
const githubActionFolder = path.resolve(process.cwd(), ".github/workflows/");

// find the SWA GitHub action file
let githubActionContent;
try {
let githubActionFile = fs
.readdirSync(githubActionFolder)
.filter((file) => file.includes("azure-static-web-apps") && file.endsWith(".yml"))
.pop();

githubActionFile = path.resolve(githubActionFolder, githubActionFile);

githubActionContent = fs.readFileSync(githubActionFile, "utf8");
} catch (err) {
console.error(err);
shell.echo("No SWA configuration build found.");
shell.exit(0);
}

const swaYaml = YAML.parse(githubActionContent);
const swaBuildConfig = swaYaml.jobs.build_and_deploy_job.steps.find((step) => step.uses && step.uses.includes("static-web-apps-deploy"));
const {
app_build_command = "npm run build --if-present",
api_build_command = "npm run build --if-present",

app_location = "/",
app_artifact_location = "/",
api_location = "api",
} = swaBuildConfig.with;

const config = {
app_build_command,
api_build_command,

// these locations must be under the user's project folder
app_location: path.join(process.cwd(), app_location),
api_location: path.join(process.cwd(), api_location),
app_artifact_location: path.join(process.cwd(), app_location, app_artifact_location),
};

return config;
};

0 comments on commit 532be71

Please sign in to comment.