[ci] format
This commit is contained in:
parent
72ef7ae64a
commit
145e418edd
4 changed files with 24 additions and 31 deletions
|
@ -4,4 +4,4 @@ module.exports = {
|
||||||
extend: {},
|
extend: {},
|
||||||
},
|
},
|
||||||
plugins: [],
|
plugins: [],
|
||||||
}
|
};
|
||||||
|
|
|
@ -108,14 +108,14 @@ export async function cli(args: string[]) {
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case 'add': {
|
case 'add': {
|
||||||
try {
|
try {
|
||||||
const packages = flags._.slice(3) as string[];
|
const packages = flags._.slice(3) as string[];
|
||||||
await add(packages, { cwd: projectRoot, flags, logging });
|
await add(packages, { cwd: projectRoot, flags, logging });
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throwAndExit(err);
|
throwAndExit(err);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case 'dev': {
|
case 'dev': {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -126,7 +126,7 @@ export default async function add(names: string[], { cwd, flags, logging }: AddO
|
||||||
configResult = await updateAstroConfig({ configURL, ast, flags, logging });
|
configResult = await updateAstroConfig({ configURL, ast, flags, logging });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
debug('add', 'Error updating astro config', err);
|
debug('add', 'Error updating astro config', err);
|
||||||
throw createPrettyError(err as Error);
|
throw createPrettyError(err as Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,9 +138,9 @@ export default async function add(names: string[], { cwd, flags, logging }: AddO
|
||||||
case UpdateResult.none: {
|
case UpdateResult.none: {
|
||||||
const pkgURL = new URL('./package.json', configURL);
|
const pkgURL = new URL('./package.json', configURL);
|
||||||
if (existsSync(fileURLToPath(pkgURL))) {
|
if (existsSync(fileURLToPath(pkgURL))) {
|
||||||
const { dependencies = {}, devDependencies = {} } = await fs.readFile(fileURLToPath(pkgURL)).then(res => JSON.parse(res.toString()));
|
const { dependencies = {}, devDependencies = {} } = await fs.readFile(fileURLToPath(pkgURL)).then((res) => JSON.parse(res.toString()));
|
||||||
const deps = Object.keys(Object.assign(dependencies, devDependencies));
|
const deps = Object.keys(Object.assign(dependencies, devDependencies));
|
||||||
const missingDeps = integrations.filter(integration => !deps.includes(integration.packageName));
|
const missingDeps = integrations.filter((integration) => !deps.includes(integration.packageName));
|
||||||
if (missingDeps.length === 0) {
|
if (missingDeps.length === 0) {
|
||||||
info(logging, null, msg.success(`Configuration up-to-date.`));
|
info(logging, null, msg.success(`Configuration up-to-date.`));
|
||||||
return;
|
return;
|
||||||
|
@ -158,7 +158,7 @@ export default async function add(names: string[], { cwd, flags, logging }: AddO
|
||||||
case UpdateResult.updated: {
|
case UpdateResult.updated: {
|
||||||
const len = integrations.length;
|
const len = integrations.length;
|
||||||
if (integrations.find((integration) => integration.id === 'tailwind')) {
|
if (integrations.find((integration) => integration.id === 'tailwind')) {
|
||||||
const possibleConfigFiles = ['./tailwind.config.cjs', './tailwind.config.mjs', './tailwind.config.js'].map(p => fileURLToPath(new URL(p, configURL)));
|
const possibleConfigFiles = ['./tailwind.config.cjs', './tailwind.config.mjs', './tailwind.config.js'].map((p) => fileURLToPath(new URL(p, configURL)));
|
||||||
let alreadyConfigured = false;
|
let alreadyConfigured = false;
|
||||||
for (const possibleConfigPath of possibleConfigFiles) {
|
for (const possibleConfigPath of possibleConfigFiles) {
|
||||||
if (existsSync(possibleConfigPath)) {
|
if (existsSync(possibleConfigPath)) {
|
||||||
|
@ -176,7 +176,7 @@ export default async function add(names: string[], { cwd, flags, logging }: AddO
|
||||||
debug('add', `Using existing Tailwind configuration`);
|
debug('add', `Using existing Tailwind configuration`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const list = integrations.map(integration => ` - ${integration.packageName}`).join('\n')
|
const list = integrations.map((integration) => ` - ${integration.packageName}`).join('\n');
|
||||||
info(logging, null, msg.success(`Added the following integration${len === 1 ? '' : 's'} to your project:\n${list}`));
|
info(logging, null, msg.success(`Added the following integration${len === 1 ? '' : 's'} to your project:\n${list}`));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -208,12 +208,12 @@ const toIdent = (name: string) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
function createPrettyError(err: Error) {
|
function createPrettyError(err: Error) {
|
||||||
err.message = `Astro could not update your astro.config.js file safely.
|
err.message = `Astro could not update your astro.config.js file safely.
|
||||||
Reason: ${err.message}
|
Reason: ${err.message}
|
||||||
|
|
||||||
You will need to add these integration(s) manually.
|
You will need to add these integration(s) manually.
|
||||||
Documentation: https://next--astro-docs-2.netlify.app/en/guides/integrations-guide/`
|
Documentation: https://next--astro-docs-2.netlify.app/en/guides/integrations-guide/`;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addIntegration(ast: t.File, integration: IntegrationInfo) {
|
async function addIntegration(ast: t.File, integration: IntegrationInfo) {
|
||||||
|
@ -281,10 +281,7 @@ async function updateAstroConfig({ configURL, ast, flags, logging }: { configURL
|
||||||
|
|
||||||
let changes = [];
|
let changes = [];
|
||||||
for (const change of diffWords(input, output)) {
|
for (const change of diffWords(input, output)) {
|
||||||
let lines = change.value
|
let lines = change.value.trim().split('\n').slice(0, change.count);
|
||||||
.trim()
|
|
||||||
.split('\n')
|
|
||||||
.slice(0, change.count)
|
|
||||||
if (lines.length === 0) continue;
|
if (lines.length === 0) continue;
|
||||||
if (change.added) {
|
if (change.added) {
|
||||||
if (!change.value.trim()) continue;
|
if (!change.value.trim()) continue;
|
||||||
|
@ -366,11 +363,7 @@ async function tryToInstallIntegrations({
|
||||||
} else {
|
} else {
|
||||||
const coloredOutput = `${bold(installCommand.pm)} ${installCommand.command} ${installCommand.flags.join(' ')} ${cyan(installCommand.dependencies.join(' '))}`;
|
const coloredOutput = `${bold(installCommand.pm)} ${installCommand.command} ${installCommand.flags.join(' ')} ${cyan(installCommand.dependencies.join(' '))}`;
|
||||||
const message = `\n${boxen(coloredOutput, { margin: 0.5, padding: 0.5, borderStyle: 'round' })}\n`;
|
const message = `\n${boxen(coloredOutput, { margin: 0.5, padding: 0.5, borderStyle: 'round' })}\n`;
|
||||||
info(
|
info(logging, null, `\n ${magenta('Astro will run the following command:')}\n ${dim('If you skip this step, you can always run it yourself later')}\n${message}`);
|
||||||
logging,
|
|
||||||
null,
|
|
||||||
`\n ${magenta('Astro will run the following command:')}\n ${dim('If you skip this step, you can always run it yourself later')}\n${message}`
|
|
||||||
);
|
|
||||||
|
|
||||||
if (await askToContinue({ flags })) {
|
if (await askToContinue({ flags })) {
|
||||||
const spinner = ora('Installing dependencies...').start();
|
const spinner = ora('Installing dependencies...').start();
|
||||||
|
|
|
@ -266,10 +266,10 @@ interface LoadConfigOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve the file URL of the user's `astro.config.js|cjs|mjs|ts` file
|
* Resolve the file URL of the user's `astro.config.js|cjs|mjs|ts` file
|
||||||
* Note: currently the same as loadConfig but only returns the `filePath`
|
* Note: currently the same as loadConfig but only returns the `filePath`
|
||||||
* instead of the resolved config
|
* instead of the resolved config
|
||||||
*/
|
*/
|
||||||
export async function resolveConfigURL(configOptions: LoadConfigOptions): Promise<URL | undefined> {
|
export async function resolveConfigURL(configOptions: LoadConfigOptions): Promise<URL | undefined> {
|
||||||
const root = configOptions.cwd ? path.resolve(configOptions.cwd) : process.cwd();
|
const root = configOptions.cwd ? path.resolve(configOptions.cwd) : process.cwd();
|
||||||
const flags = resolveFlags(configOptions.flags || {});
|
const flags = resolveFlags(configOptions.flags || {});
|
||||||
|
|
Loading…
Reference in a new issue