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

add svelte-kit sync #4182

Merged
merged 7 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/five-poems-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'create-svelte': patch
'@sveltejs/kit': patch
---

Add sync CLI command
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"dev": "svelte-kit dev",
"build": "svelte-kit build",
"package": "svelte-kit package",
"preview": "svelte-kit preview"
"preview": "svelte-kit preview",
"prepare": "svelte-kit sync"
benmccann marked this conversation as resolved.
Show resolved Hide resolved
},
"devDependencies": {
"@sveltejs/adapter-auto": "next",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"dev": "svelte-kit dev",
"build": "svelte-kit build",
"package": "svelte-kit package",
"preview": "svelte-kit preview"
"preview": "svelte-kit preview",
"prepare": "svelte-kit sync"
},
"devDependencies": {
"@sveltejs/adapter-auto": "workspace:*",
Expand Down
13 changes: 13 additions & 0 deletions packages/kit/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,19 @@ prog
}
});

prog
.command('sync')
.describe('Synchronise generated files')
.action(async () => {
try {
const config = await load_config();
const sync = await import('./core/sync/sync.js');
sync.all(config);
} catch (error) {
handle_error(error);
}
});

prog.parse(process.argv, { unknown: (arg) => `Unknown option: ${arg}` });

/** @param {number} port */
Expand Down
11 changes: 1 addition & 10 deletions packages/kit/src/core/build/build_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import path from 'path';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import { deep_merge } from '../../utils/object.js';
import { print_config_conflicts } from '../config/index.js';
import { create_app } from '../create_app/index.js';
import { copy_assets, get_aliases } from '../utils.js';
import { get_aliases } from '../utils.js';
import { create_build, find_deps } from './utils.js';
import { posixify } from '../../utils/filesystem.js';

Expand Down Expand Up @@ -32,14 +31,6 @@ export async function build_client({
process.env.VITE_SVELTEKIT_APP_VERSION_FILE = `${config.kit.appDir}/version.json`;
process.env.VITE_SVELTEKIT_APP_VERSION_POLL_INTERVAL = `${config.kit.version.pollInterval}`;

create_app({
config,
manifest_data,
cwd
});

copy_assets(path.join(config.kit.outDir, 'runtime'));

process.env.VITE_SVELTEKIT_AMP = config.kit.amp ? 'true' : '';

const client_out_dir = `${output_dir}/client/${config.kit.appDir}`;
Expand Down
10 changes: 3 additions & 7 deletions packages/kit/src/core/build/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import fs from 'fs';
import path from 'path';
import { mkdirp, rimraf, posixify } from '../../utils/filesystem.js';
import create_manifest_data from '../create_manifest_data/index.js';
import * as sync from '../sync/sync.js';
import { get_runtime_path, resolve_entry } from '../utils.js';
import { generate_manifest } from '../generate_manifest/index.js';
import { build_service_worker } from './build_service_worker.js';
import { build_client } from './build_client.js';
import { build_server } from './build_server.js';
import { generate_tsconfig } from '../tsconfig.js';

/**
* @param {import('types').ValidatedConfig} config
Expand All @@ -24,7 +23,7 @@ export async function build(config) {
rimraf(output_dir);
mkdirp(output_dir);

generate_tsconfig(config);
const { manifest_data } = sync.all(config);

const options = {
cwd,
Expand All @@ -35,10 +34,7 @@ export async function build(config) {
// used relative paths, I _think_ this could get fixed. Issue here:
// https://github.com/vitejs/vite/issues/2009
assets_base: `${config.kit.paths.assets || config.kit.paths.base}/${config.kit.appDir}/`,
manifest_data: create_manifest_data({
config,
cwd
}),
manifest_data,
output_dir,
client_entry_file: path.relative(cwd, `${get_runtime_path(config)}/client/start.js`),
service_worker_entry_file: resolve_entry(config.kit.files.serviceWorker),
Expand Down
263 changes: 0 additions & 263 deletions packages/kit/src/core/create_app/index.js

This file was deleted.

8 changes: 3 additions & 5 deletions packages/kit/src/core/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { svelte } from '@sveltejs/vite-plugin-svelte';
import vite from 'vite';
import { deep_merge } from '../../utils/object.js';
import { print_config_conflicts } from '../config/index.js';
import { copy_assets, get_aliases, get_runtime_path } from '../utils.js';
import { get_aliases, get_runtime_path } from '../utils.js';
import { create_plugin } from './plugin.js';
import { generate_tsconfig } from '../tsconfig.js';
import * as sync from '../sync/sync.js';

/**
* @typedef {{
Expand All @@ -20,9 +20,7 @@ import { generate_tsconfig } from '../tsconfig.js';

/** @param {Options} opts */
export async function dev({ cwd, port, host, https, config }) {
copy_assets(path.join(config.kit.outDir, 'runtime'));

generate_tsconfig(config);
sync.init(config);

const [vite_config] = deep_merge(
{
Expand Down
Loading