feat(misc): add a spinner when creating a workspace
This commit is contained in:
parent
d4629be208
commit
e40c65194d
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
import { execSync } from 'child_process';
|
import { exec, execSync } from 'child_process';
|
||||||
import { writeFileSync } from 'fs';
|
import { writeFileSync } from 'fs';
|
||||||
import * as inquirer from 'inquirer';
|
import * as inquirer from 'inquirer';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
@ -8,6 +8,8 @@ import { dirSync } from 'tmp';
|
|||||||
import * as yargsParser from 'yargs-parser';
|
import * as yargsParser from 'yargs-parser';
|
||||||
import { showNxWarning, unparse } from './shared';
|
import { showNxWarning, unparse } from './shared';
|
||||||
import { output } from './output';
|
import { output } from './output';
|
||||||
|
import * as ora from 'ora';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getPackageManagerCommand,
|
getPackageManagerCommand,
|
||||||
getPackageManagerVersion,
|
getPackageManagerVersion,
|
||||||
@ -121,7 +123,7 @@ determineWorkspaceName(parsedArgs).then((name) => {
|
|||||||
return determineLinter(preset, parsedArgs).then((linter) => {
|
return determineLinter(preset, parsedArgs).then((linter) => {
|
||||||
return askAboutNxCloud(parsedArgs).then((nxCloud) => {
|
return askAboutNxCloud(parsedArgs).then((nxCloud) => {
|
||||||
const tmpDir = createSandbox(packageManager);
|
const tmpDir = createSandbox(packageManager);
|
||||||
createApp(tmpDir, name, {
|
return createApp(tmpDir, name, {
|
||||||
...parsedArgs,
|
...parsedArgs,
|
||||||
cli,
|
cli,
|
||||||
preset,
|
preset,
|
||||||
@ -129,9 +131,10 @@ determineWorkspaceName(parsedArgs).then((name) => {
|
|||||||
style,
|
style,
|
||||||
linter,
|
linter,
|
||||||
nxCloud,
|
nxCloud,
|
||||||
|
}).then(() => {
|
||||||
|
showNxWarning(name);
|
||||||
|
pointToTutorialAndCourse(preset);
|
||||||
});
|
});
|
||||||
showNxWarning(name);
|
|
||||||
pointToTutorialAndCourse(preset);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -444,7 +447,7 @@ function createSandbox(packageManager: string) {
|
|||||||
return tmpDir;
|
return tmpDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createApp(tmpDir: string, name: string, parsedArgs: any) {
|
async function createApp(tmpDir: string, name: string, parsedArgs: any) {
|
||||||
const { _, cli, ...restArgs } = parsedArgs;
|
const { _, cli, ...restArgs } = parsedArgs;
|
||||||
const args = unparse(restArgs).join(' ');
|
const args = unparse(restArgs).join(' ');
|
||||||
|
|
||||||
@ -466,12 +469,10 @@ function createApp(tmpDir: string, name: string, parsedArgs: any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const fullCommand = `${pmc.exec} tao ${command}/collection.json --cli=${cli} --nxWorkspaceRoot=${nxWorkspaceRoot}`;
|
const fullCommand = `${pmc.exec} tao ${command}/collection.json --cli=${cli} --nxWorkspaceRoot=${nxWorkspaceRoot}`;
|
||||||
|
const spinner = ora('Creating your workspace').start();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
execSync(fullCommand, {
|
await execAndWait(fullCommand, tmpDir);
|
||||||
stdio: ['ignore', 'ignore', 'ignore'],
|
|
||||||
cwd: tmpDir,
|
|
||||||
});
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
output.error({
|
output.error({
|
||||||
title:
|
title:
|
||||||
@ -481,6 +482,8 @@ function createApp(tmpDir: string, name: string, parsedArgs: any) {
|
|||||||
stdio: [0, 1, 2],
|
stdio: [0, 1, 2],
|
||||||
cwd: tmpDir,
|
cwd: tmpDir,
|
||||||
});
|
});
|
||||||
|
} finally {
|
||||||
|
spinner.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
output.success({
|
output.success({
|
||||||
@ -496,6 +499,18 @@ function createApp(tmpDir: string, name: string, parsedArgs: any) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function execAndWait(command: string, cwd: string) {
|
||||||
|
return new Promise((res, rej) => {
|
||||||
|
exec(command, { cwd }, (error, stdout, stderr) => {
|
||||||
|
if (error) {
|
||||||
|
rej();
|
||||||
|
} else {
|
||||||
|
res(null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async function askAboutNxCloud(parsedArgs: any) {
|
async function askAboutNxCloud(parsedArgs: any) {
|
||||||
if (parsedArgs.nxCloud === undefined) {
|
if (parsedArgs.nxCloud === undefined) {
|
||||||
return inquirer
|
return inquirer
|
||||||
|
|||||||
@ -31,6 +31,7 @@
|
|||||||
"yargs-parser": "20.0.0",
|
"yargs-parser": "20.0.0",
|
||||||
"inquirer": "^6.3.1",
|
"inquirer": "^6.3.1",
|
||||||
"flat": "^5.0.2",
|
"flat": "^5.0.2",
|
||||||
"chalk": "4.1.0"
|
"chalk": "4.1.0",
|
||||||
|
"ora": "5.3.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user