Skip to content

Commit

Permalink
add svelte-kit sync (#4182)
Browse files Browse the repository at this point in the history
* move copy_assets, generate_tsconfig, create_app etc into new sync module

* move some code around

* add sync CLI command

* tidy up

* add prepare script to templates

* add sync CLI command

* Update packages/kit/src/core/sync/copy_assets.js

Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>

Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
  • Loading branch information
Rich-Harris and benmccann authored Mar 3, 2022
1 parent bcd5f4d commit 255e0d2
Show file tree
Hide file tree
Showing 105 changed files with 356 additions and 324 deletions.
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"
},
"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

0 comments on commit 255e0d2

Please sign in to comment.