Skip to content

Commit

Permalink
Switch to simpler resolution strategies for detecting build setups.
Browse files Browse the repository at this point in the history
  • Loading branch information
ludwigschubert committed Aug 7, 2018
1 parent 694ae95 commit 1644c24
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,30 +82,27 @@ function getRepoFromURL(name, authorizedURL, targetDir) {
.then(_ => fs.readdir(repoFolder))
.then(files => {
let sourceDir;
// if there's a public dir with index.html we use that dir
const repoPublicSubfolder = `${repoFolder}/public`;
if (files.includes('public')) {

// if there's a public dir with index.html we use that dir
if (!sourceDir && files.includes('public')) {
const publicFiles = fs.readdirSync(repoPublicSubfolder);
if (publicFiles.includes('index.html')) {
sourceDir = repoPublicSubfolder
} else {
throw "Found public folder but no index.html in it!";
}
} else {
// some people just have the html in the root folder
if (files.includes('index.html')) {
sourceDir = repoFolder;
} else {
// try npm
if (files.includes('package.json')) {
execSync(`cd ${repoFolder} && npm install && npm run build`);
// TODO: better separate potential build processes and folder conventions!
sourceDir = repoPublicSubfolder;
} else {
throw "Found no public folder and no index.html in root folder!";
}
}
}

// try npm
if (!sourceDir && files.includes('package.json')) {
execSync(`cd ${repoFolder} && npm install && npm run build`);
// TODO: better separate potential build processes and folder conventions!
sourceDir = repoPublicSubfolder;
}

if (!sourceDir) {
throw `${repoFolder}: Found no public folder and no index.html in root folder!`;
}

//TODO: should we support any of these? [make files, npm run build, ...] ?
console.log(name, sourceDir, targetPublicDir);
return fs.copy(sourceDir, targetPublicDir);
Expand Down

0 comments on commit 1644c24

Please sign in to comment.