create-rstack 1.0.7 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -17,13 +17,15 @@ A shared package for create-rspack, create-rsbuild, create-rspress and create-rs
17
17
  npm add create-rstack -D
18
18
  ```
19
19
 
20
- ## Example
20
+ ## Examples
21
21
 
22
- See: [create-rsbuild](https://github.com/web-infra-dev/rsbuild/tree/main/packages/create-rsbuild).
22
+ | Project | Link |
23
+ | ------- | -------------------------------------------------------------------------------------------- |
24
+ | Rsbuild | [create-rsbuild](https://github.com/web-infra-dev/rsbuild/tree/main/packages/create-rsbuild) |
25
+ | Rslib | [create-rslib](https://github.com/web-infra-dev/rslib/tree/main/packages/create-rslib) |
23
26
 
24
27
  ![image](https://github.com/user-attachments/assets/2dda3501-720c-4151-bd3e-5e038dca9e68)
25
28
 
26
-
27
29
  ## License
28
30
 
29
31
  [MIT](./LICENSE).
package/dist/index.d.ts CHANGED
@@ -8,6 +8,24 @@ export declare type Argv = {
8
8
 
9
9
  export declare function checkCancel<T>(value: unknown): T;
10
10
 
11
+ /**
12
+ * Copy files from one folder to another.
13
+ * @param from Source folder
14
+ * @param to Destination folder
15
+ * @param version - Optional. The version to update in the package.json. If not provided, version will not be updated.
16
+ * @param name - Optional. The name to update in the package.json. If not provided, name will not be updated.
17
+ * @param isMergePackageJson Merge package.json files
18
+ * @param skipFiles Files to skip
19
+ */
20
+ export declare function copyFolder({ from, to, version, packageName, isMergePackageJson, skipFiles, }: {
21
+ from: string;
22
+ to: string;
23
+ version?: string;
24
+ packageName?: string;
25
+ isMergePackageJson?: boolean;
26
+ skipFiles?: string[];
27
+ }): void;
28
+
11
29
  export declare function create({ name, root, templates, skipFiles, getTemplateName, mapESLintTemplate, }: {
12
30
  name: string;
13
31
  root: string;
@@ -19,6 +37,13 @@ export declare function create({ name, root, templates, skipFiles, getTemplateNa
19
37
 
20
38
  export declare type ESLintTemplateName = 'vanilla-js' | 'vanilla-ts' | 'react-js' | 'react-ts' | 'vue-ts' | 'vue-js' | 'svelte-js' | 'svelte-ts';
21
39
 
40
+ /**
41
+ * Merge two package.json files and keep the order of keys.
42
+ * @param targetPackage Path to the base package.json file
43
+ * @param extraPackage Path to the extra package.json file to merge
44
+ */
45
+ export declare function mergePackageJson(targetPackage: string, extraPackage: string): void;
46
+
22
47
  export declare const multiselect: <Options extends Option_2<Value>[], Value>(opts: MultiSelectOptions<Options, Value>) => Promise<symbol | Value[]>;
23
48
 
24
49
  declare interface MultiSelectOptions<Options extends Option_2<Value>[], Value> {
package/dist/index.js CHANGED
@@ -1693,7 +1693,11 @@ function sortObjectKeys(obj) {
1693
1693
  for (const key of sortedKeys)sortedObj[key] = obj[key];
1694
1694
  return sortedObj;
1695
1695
  }
1696
- function mergePackageJson(targetPackage, extraPackage) {
1696
+ /**
1697
+ * Merge two package.json files and keep the order of keys.
1698
+ * @param targetPackage Path to the base package.json file
1699
+ * @param extraPackage Path to the extra package.json file to merge
1700
+ */ function mergePackageJson(targetPackage, extraPackage) {
1697
1701
  if (!__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].existsSync(targetPackage)) return;
1698
1702
  const targetJson = JSON.parse(__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].readFileSync(targetPackage, 'utf-8'));
1699
1703
  const extraJson = JSON.parse(__WEBPACK_EXTERNAL_MODULE_node_fs__["default"].readFileSync(extraPackage, 'utf-8'));
@@ -1708,7 +1712,15 @@ function mergePackageJson(targetPackage, extraPackage) {
1708
1712
  }
1709
1713
  __WEBPACK_EXTERNAL_MODULE_node_fs__["default"].writeFileSync(targetPackage, `${JSON.stringify(mergedJson, null, 2)}\n`);
1710
1714
  }
1711
- function copyFolder({ from, to, version, packageName, isMergePackageJson, skipFiles = [] }) {
1715
+ /**
1716
+ * Copy files from one folder to another.
1717
+ * @param from Source folder
1718
+ * @param to Destination folder
1719
+ * @param version - Optional. The version to update in the package.json. If not provided, version will not be updated.
1720
+ * @param name - Optional. The name to update in the package.json. If not provided, name will not be updated.
1721
+ * @param isMergePackageJson Merge package.json files
1722
+ * @param skipFiles Files to skip
1723
+ */ function copyFolder({ from, to, version, packageName, isMergePackageJson, skipFiles = [] }) {
1712
1724
  const renameFiles = {
1713
1725
  gitignore: '.gitignore'
1714
1726
  };
@@ -1749,13 +1761,21 @@ const isStableVersion = (version)=>[
1749
1761
  'canary',
1750
1762
  'nightly'
1751
1763
  ].every((tag)=>!version.includes(tag));
1752
- const updatePackageJson = (pkgJsonPath, version, name)=>{
1764
+ /**
1765
+ * Updates the package.json file at the specified path with the provided version and name.
1766
+ *
1767
+ * @param pkgJsonPath - The file path to the package.json file.
1768
+ * @param version - Optional. The version to update in the package.json. If not provided, version will not be updated.
1769
+ * @param name - Optional. The name to update in the package.json. If not provided, name will not be updated.
1770
+ */ const updatePackageJson = (pkgJsonPath, version, name)=>{
1753
1771
  let content = __WEBPACK_EXTERNAL_MODULE_node_fs__["default"].readFileSync(pkgJsonPath, 'utf-8');
1754
- // Lock the version if it is not stable
1755
- const targetVersion = isStableVersion(version) ? `^${version}` : version;
1756
- content = content.replace(/workspace:\*/g, targetVersion);
1772
+ if ('string' == typeof version) {
1773
+ // Lock the version if it is not stable
1774
+ const targetVersion = isStableVersion(version) ? `^${version}` : version;
1775
+ content = content.replace(/workspace:\*/g, targetVersion);
1776
+ }
1757
1777
  const pkg = JSON.parse(content);
1758
1778
  if (name && '.' !== name) pkg.name = name;
1759
- __WEBPACK_EXTERNAL_MODULE_node_fs__["default"].writeFileSync(pkgJsonPath, JSON.stringify(pkg, null, 2));
1779
+ __WEBPACK_EXTERNAL_MODULE_node_fs__["default"].writeFileSync(pkgJsonPath, `${JSON.stringify(pkg, null, 2)}\n`);
1760
1780
  };
1761
- export { checkCancel, create, ae as multiselect, ie as select, te as text };
1781
+ export { checkCancel, copyFolder, create, mergePackageJson, ae as multiselect, ie as select, te as text };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-rstack",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Create a new Rstack project",
5
5
  "repository": {
6
6
  "type": "git",