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

chore: debug windows #31

Closed
wants to merge 14 commits into from
25 changes: 15 additions & 10 deletions src/services/cli.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,24 @@
return false;
}

const args =
pm === 'yarn' ? ['global', 'list', '--depth=0'] : ['list', '--depth', '0', '--global'];
try {
const args =
pm === 'yarn' ? ['global', 'list', '--depth=0'] : ['list', '--depth', '0', '--global'];

Check failure on line 17 in src/services/cli.services.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`

let stdout = '';
let stdout = '';

await spawn({
command: pm,
args,
stdout: (output: string) => (stdout += output),
silentOut: true
});
await spawn({
command: pm,
args,
stdout: (output: string) => (stdout += output),
silentOut: true
});

return stdout.includes(CLI_PACKAGE);
return stdout.includes(CLI_PACKAGE);
} catch (_err: unknown) {
// According to our tests, on Windows, npm might just throw an error if there are no global lib installed yet. Therefore, we consider here an error as the CLI not being installed yet.
return false;
}
};

const install = async () => {
Expand Down
7 changes: 5 additions & 2 deletions src/services/deps.services.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {nonNullish} from '@junobuild/utils';
import ora from 'ora';
import type {PopulateInput} from '../types/generator';
import {spawn} from '../utils/cmd.utils';
import {whichPMRuns} from '../utils/pm.utils';
import {confirm} from '../utils/prompts.utils';

export const dependencies = async () => {
export const dependencies = async ({where}: PopulateInput) => {
const install = await confirm('Install dependencies?');

if (!install) {
Expand All @@ -18,7 +20,8 @@ export const dependencies = async () => {
await spawn({
command: pm,
args: ['install'],
silentOut: true
silentOut: true,
...(nonNullish(where) && where !== '' && {cwd: where})
});
} finally {
spinner.stop();
Expand Down
15 changes: 2 additions & 13 deletions src/services/generate.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import ora from 'ora';
import {JUNO_CDN_URL} from '../constants/constants';
import {GITHUB_ACTION_DEPLOY} from '../templates/github-actions';
import type {GeneratorInput} from '../types/generator';
import type {GeneratorInput, PopulateInput} from '../types/generator';

Check failure on line 8 in src/services/generate.services.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `GeneratorInput,·`

Check warning on line 8 in src/services/generate.services.ts

View workflow job for this annotation

GitHub Actions / lint

'GeneratorInput' is defined but never used. Allowed unused vars must match /^_/u
import {gunzipFile, untarFile, type UntarOutputFile} from '../utils/compress.utils';
import {downloadFromURL} from '../utils/download.utils';
import {
Expand All @@ -15,18 +15,7 @@
} from '../utils/fs.utils';
import {createDirectory, getLocalFiles, type LocalFileDescriptor} from '../utils/populate.utils';

type PopulateInput = {
where: string | null;
} & Omit<GeneratorInput, 'destination'>;

export const generate = async ({destination, ...rest}: GeneratorInput) => {
await populate({
where: ['.', ''].includes(destination) ? null : destination,
...rest
});
};

const populate = async ({gitHubAction, ...rest}: PopulateInput) => {
export const generate = async ({gitHubAction, ...rest}: PopulateInput) => {
const spinner = ora(`Creating project...`).start();

try {
Expand Down
15 changes: 12 additions & 3 deletions src/services/project.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ export const checkForExistingProject = async (): Promise<{initProject: boolean}>
return {initProject};
};

const generateProject = async ({destination, ...rest}: GeneratorInput) => {
const input = {
where: ['.', ''].includes(destination) ? null : destination,
...rest
};

await generate(input);

await dependencies(input);
};

export const initNewProject = async (args: string[]): Promise<GeneratorInput> => {
const userInputs = initArgs(args);

Expand All @@ -43,9 +54,7 @@ export const initNewProject = async (args: string[]): Promise<GeneratorInput> =>
localDevelopment
};

await generate(input);

await dependencies();
await generateProject(input);

return input;
};
4 changes: 4 additions & 0 deletions src/types/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ export interface GeneratorInput {
}

export type ProjectKind = 'website' | 'app';

export type PopulateInput = {
where: string | null;
} & Omit<GeneratorInput, 'destination'>;
10 changes: 8 additions & 2 deletions src/utils/cmd.utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {nonNullish} from '@junobuild/utils';
import {
spawn as spawnCommand,
type ChildProcess,
Expand All @@ -11,16 +12,21 @@ export const spawn = async ({
args,
stdout,
silentOut = false,
silentErrors = false
silentErrors = false,
cwd
}: {
command: string;
cwd?: string;
args?: readonly string[];
stdout?: (output: string) => void;
silentOut?: boolean;
silentErrors?: boolean;
}): Promise<number | null> => {
return await new Promise<number | null>((resolve, reject) => {
const process: ChildProcessWithoutNullStreams = spawnCommand(command, args);
const process: ChildProcessWithoutNullStreams = spawnCommand(command, args, {
shell: true,
...(nonNullish(cwd) && {cwd})
});

process.stdout.on('data', (data) => {
if (stdout !== null && stdout !== undefined) {
Expand Down
Loading