Skip to content

Commit

Permalink
Merge pull request #22 from CloudCannon/fix/build-command-source-path
Browse files Browse the repository at this point in the history
Generate build suggestions relative to the root dir
  • Loading branch information
Tate-CC authored Sep 17, 2024
2 parents 3ef700d + f448cde commit 920d7e2
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 20 deletions.
1 change: 0 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ export async function generateBuildCommands(filePaths, options) {
: guessSsg(filterPaths(filePaths, source));

source = source ?? ssg.getSource(filePaths);
filePaths = filterPaths(filePaths, source);

const files = ssg.groupFiles(filePaths);

Expand Down
6 changes: 3 additions & 3 deletions src/ssgs/bridgetown.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { joinPaths } from '../utility.js';
import Ssg from './ssg.js';

export default class Bridgetown extends Ssg {
Expand All @@ -24,7 +23,8 @@ export default class Bridgetown extends Ssg {
async generateBuildCommands(filePaths, options) {
const commands = await super.generateBuildCommands(filePaths, options);

if (filePaths.includes(joinPaths([options.source, 'Gemfile']))) {
const gemfilePath = filePaths.find((path) => path === 'Gemfile' || path.endsWith('/Gemfile'));
if (gemfilePath) {
commands.install.unshift({
value: 'bundle install',
attribution: 'because of your Gemfile',
Expand All @@ -40,7 +40,7 @@ export default class Bridgetown extends Ssg {

if (options.source) {
commands.environment['BUNDLE_GEMFILE'] = {
value: joinPaths([options.source, 'Gemfile']),
value: gemfilePath,
attribution: 'because of your Gemfile',
};
}
Expand Down
5 changes: 3 additions & 2 deletions src/ssgs/jekyll.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,8 @@ export default class Jekyll extends Ssg {
async generateBuildCommands(filePaths, options) {
const commands = await super.generateBuildCommands(filePaths, options);

if (filePaths.includes(joinPaths([options.source, 'Gemfile']))) {
const gemfilePath = filePaths.find((path) => path === 'Gemfile' || path.endsWith('/Gemfile'));
if (gemfilePath) {
commands.install.unshift({
value: 'bundle install',
attribution: 'because of your Gemfile',
Expand All @@ -400,7 +401,7 @@ export default class Jekyll extends Ssg {

if (options.source) {
commands.environment['BUNDLE_GEMFILE'] = {
value: joinPaths([options.source, 'Gemfile']),
value: gemfilePath,
attribution: 'because of your Gemfile',
};
}
Expand Down
5 changes: 2 additions & 3 deletions src/ssgs/mkdocs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { joinPaths } from '../utility.js';
import Ssg from './ssg.js';

export default class MkDocs extends Ssg {
Expand All @@ -25,8 +24,8 @@ export default class MkDocs extends Ssg {
*/
async generateBuildCommands(filePaths, options) {
const commands = await super.generateBuildCommands(filePaths, options);
const usePip = filePaths.includes(joinPaths([options.source, 'requirements.txt']));
const usePipEnv = filePaths.includes(joinPaths([options.source, 'Pipfile']));
const usePip = filePaths.includes('requirements.txt');
const usePipEnv = filePaths.includes('Pipfile');

commands.build.push({
value: 'mkdocs build',
Expand Down
13 changes: 6 additions & 7 deletions src/ssgs/ssg.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { basename } from 'path';
import slugify from '@sindresorhus/slugify';
import titleize from 'titleize';
import { findIcon } from '../icons.js';
import { joinPaths, last, parseDataFile, stripTopPath } from '../utility.js';
import { last, parseDataFile, stripTopPath } from '../utility.js';
import { findBasePath, getCollectionPaths } from '../collections.js';

export default class Ssg {
Expand Down Expand Up @@ -504,12 +504,11 @@ export default class Ssg {
environment: {},
};

const packageJsonPath = joinPaths([options.source, 'package.json']);
if (filePaths.includes(packageJsonPath)) {
const useYarn = filePaths.includes(joinPaths([options.source, 'yarn.lock']));
const usePnpm = filePaths.includes(joinPaths([options.source, 'pnpm-lock.yaml']));
if (filePaths.includes('package.json')) {
const useYarn = filePaths.includes('yarn.lock');
const usePnpm = filePaths.includes('pnpm-lock.yaml');
const useNpm =
filePaths.includes(joinPaths([options.source, 'package-lock.json'])) ||
filePaths.includes('package-lock.json') ||
(!useYarn && !usePnpm);

if (useNpm) {
Expand Down Expand Up @@ -538,7 +537,7 @@ export default class Ssg {

try {
if (options.readFile) {
const parsed = await parseDataFile(packageJsonPath, options.readFile);
const parsed = await parseDataFile('package.json', options.readFile);
if (parsed?.scripts?.build) {
if (useNpm) {
commands.build.push({
Expand Down
6 changes: 2 additions & 4 deletions src/ssgs/sveltekit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { joinPaths } from '../utility.js';
import Ssg from './ssg.js';

export default class Sveltekit extends Ssg {
Expand Down Expand Up @@ -35,9 +34,8 @@ export default class Sveltekit extends Ssg {
*/
async generateBuildCommands(filePaths, options) {
const commands = await super.generateBuildCommands(filePaths, options);
const viteConfigPath = joinPaths([options.source, 'vite.config.js']);

if (filePaths.includes(viteConfigPath)) {

if (filePaths.includes('vite.config.js')) {
commands.build.push({
value: 'npx vite build',
attribution: 'because of your `vite.config.js` file',
Expand Down

0 comments on commit 920d7e2

Please sign in to comment.