Urara-Blog/node_modules/.pnpm-store/v3/files/bd/aed5fd58eb3d05980748846bd8b7c48b084f97719d7231513296a07d7ed95085ff42f3f7ac0a500f1bba9779d9130fd60cff8faaffe7ebe28f1cdff92cb165
2022-08-14 01:14:53 +08:00

118 lines
3.2 KiB
Text
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import fs__default from 'fs';
import path__default from 'path';
import { l as load_config, $ } from './chunks/index.js';
import sade from 'sade';
import { c as coalesce_to_error } from './chunks/error.js';
import 'url';
/** @param {unknown} e */
function handle_error(e) {
const error = coalesce_to_error(e);
if (error.name === 'SyntaxError') throw error;
console.error($.bold().red(`> ${error.message}`));
if (error.stack) {
console.error($.gray(error.stack.split('\n').slice(1).join('\n')));
}
process.exit(1);
}
const prog = sade('svelte-kit').version('1.0.0-next.405');
prog
.command('package')
.describe('Create a package')
.option('-w, --watch', 'Rerun when files change', false)
.action(async ({ watch }) => {
try {
const config = await load_config();
const packaging = await import('./chunks/index2.js');
await (watch ? packaging.watch(config) : packaging.build(config));
} catch (error) {
handle_error(error);
}
});
prog
.command('sync')
.describe('Synchronise generated files')
.option('--mode', 'Specify a mode for loading environment variables', 'development')
.action(async ({ mode }) => {
const event = process.env.npm_lifecycle_event;
// TODO remove for 1.0
if (event === 'prepare') {
const pkg = JSON.parse(fs__default.readFileSync('package.json', 'utf8'));
const message =
pkg.scripts.prepare === 'svelte-kit sync'
? `\`svelte-kit sync\` now runs on "postinstall" — please remove the "prepare" script from your package.json\n`
: `\`svelte-kit sync\` now runs on "postinstall" — please remove it from your "prepare" script\n`;
console.error($.bold().red(message));
return;
}
if (event === 'postinstall' && process.env.INIT_CWD) {
process.chdir(process.env.INIT_CWD);
}
if (!fs__default.existsSync('svelte.config.js')) {
console.warn(`Missing ${path__default.resolve('svelte.config.js')} — skipping`);
return;
}
try {
const config = await load_config();
const sync = await import('./chunks/sync.js').then(function (n) { return n.f; });
sync.all(config, mode);
} catch (error) {
handle_error(error);
}
});
// TODO remove for 1.0
replace('dev');
replace('build');
replace('preview');
prog.parse(process.argv, { unknown: (arg) => `Unknown option: ${arg}` });
/** @param {string} command */
function replace(command) {
prog
.command(command)
.describe(`No longer available — use vite ${command} instead`)
.action(async () => {
const message = `\n> svelte-kit ${command} is no longer available — use vite ${command} instead`;
console.error($.bold().red(message));
const steps = [
'Install vite as a devDependency with npm/pnpm/etc',
'Create a vite.config.js with the @sveltejs/kit/vite plugin (see below)',
`Update your package.json scripts to reference \`vite ${command}\` instead of \`svelte-kit ${command}\``
];
steps.forEach((step, i) => {
console.error(` ${i + 1}. ${$.cyan(step)}`);
});
console.error(
`
${$.grey('// vite.config.js')}
import { sveltekit } from '@sveltejs/kit/vite';
/** @type {import('vite').UserConfig} */
const config = {
plugins: [sveltekit()]
};
export default config;
`.replace(/^\t{4}/gm, '')
);
process.exit(1);
});
}