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 package command #2882

Merged
merged 3 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/sour-taxis-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-svelte': patch
---

Add an npm run package command to templates
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"scripts": {
"dev": "svelte-kit dev",
"build": "svelte-kit build",
"package": "svelte-kit package",
"preview": "svelte-kit preview"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"scripts": {
"dev": "svelte-kit dev",
"build": "svelte-kit build",
"package": "svelte-kit package",
"preview": "svelte-kit preview"
},
"devDependencies": {
Expand Down
16 changes: 11 additions & 5 deletions packages/kit/src/packaging/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as fs from 'fs';
import * as path from 'path';
import { createRequire } from 'module';

import colors from 'kleur';
import { preprocess } from 'svelte/compiler';

import { mkdirp, rimraf, walk } from '../utils/filesystem.js';

const essential_files = ['README', 'LICENSE', 'CHANGELOG', '.gitignore', '.npmignore'];
Expand Down Expand Up @@ -132,14 +131,14 @@ export async function make_package(config, cwd = process.cwd()) {
console.warn(
'Cannot generate a "svelte" entry point because ' +
'the "." entry in "exports" is not a string. ' +
'If you set it by hand, please also set one of the options as a "svelte" entry point'
'If you set it by hand, please also set one of the options as a "svelte" entry point\n'
);
}
} else {
console.warn(
'Cannot generate a "svelte" entry point because ' +
'the "." entry in "exports" is missing. ' +
'Please specify one or set a "svelte" entry point yourself'
'Please specify one or set a "svelte" entry point yourself\n'
);
}
}
Expand All @@ -157,13 +156,20 @@ export async function make_package(config, cwd = process.cwd()) {
const package_path = path.join(abs_package_dir, pathname);
if (!fs.existsSync(package_path)) fs.copyFileSync(full_path, package_path);
}

const from = path.relative(cwd, config.kit.files.lib);
const to = path.relative(cwd, config.kit.package.dir);
console.log(colors.bold().green(`${from} -> ${to}`));
console.log(`Successfully built '${pkg.name}' package. To publish it to npm:`);
console.log(colors.bold().cyan(` cd ${to}`));
console.log(colors.bold().cyan(' npm publish\n'));
}

/**
* Resolves the `$lib` alias.
*
* TODO: make this more generic to also handle other aliases the user could have defined
* via `kit.vite.resolve.alias`. Also investage how to do this in a more robust way
* via `kit.vite.resolve.alias`. Also investigate how to do this in a more robust way
* (right now regex string replacement is used).
* For more discussion see https://github.com/sveltejs/kit/pull/2453
*
Expand Down