Skip to content

Commit

Permalink
Add package command (#2882)
Browse files Browse the repository at this point in the history
* add npm run package command to new projects

* changeset

* print message on successful packaging
  • Loading branch information
Rich-Harris authored Nov 23, 2021
1 parent b9dd0a8 commit cc45b2c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
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

0 comments on commit cc45b2c

Please sign in to comment.