@weapp-core/init 0.0.2-alpha.1 → 0.0.2-alpha.2

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/dist/index.cjs CHANGED
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
33
  initConfig: () => initConfig,
34
+ initViteConfigFile: () => initViteConfigFile,
34
35
  updatePackageJson: () => updatePackageJson,
35
36
  updateProjectConfig: () => updateProjectConfig
36
37
  });
@@ -39,7 +40,7 @@ var import_node_path = __toESM(require("path"), 1);
39
40
  var import_fs_extra = __toESM(require("fs-extra"), 1);
40
41
  var import_shared = require("@weapp-core/shared");
41
42
  function updateProjectConfig(options) {
42
- const { root, dest } = options;
43
+ const { root, dest, cb, write = true } = options;
43
44
  const projectConfigFilename = "project.config.json";
44
45
  const projectConfigPath = import_node_path.default.resolve(root, projectConfigFilename);
45
46
  if (import_fs_extra.default.existsSync(projectConfigPath)) {
@@ -48,6 +49,11 @@ function updateProjectConfig(options) {
48
49
  (0, import_shared.set)(projectConfig, "miniprogramRoot", "dist/");
49
50
  (0, import_shared.set)(projectConfig, "srcMiniprogramRoot", "dist/");
50
51
  (0, import_shared.set)(projectConfig, "setting.packNpmManually", true);
52
+ cb?.(
53
+ (...args) => {
54
+ (0, import_shared.set)(projectConfig, ...args);
55
+ }
56
+ );
51
57
  if (Array.isArray((0, import_shared.get)(projectConfig, "setting.packNpmRelationList"))) {
52
58
  const x = projectConfig.setting.packNpmRelationList.find(
53
59
  (x2) => x2.packageJsonPath === "./package.json" && x2.miniprogramNpmDistDir === "./dist"
@@ -66,10 +72,13 @@ function updateProjectConfig(options) {
66
72
  }
67
73
  ]);
68
74
  }
69
- import_fs_extra.default.outputJSONSync(dest ?? projectConfigPath, projectConfig, {
70
- spaces: 2
71
- });
75
+ if (write) {
76
+ import_fs_extra.default.outputJSONSync(dest ?? projectConfigPath, projectConfig, {
77
+ spaces: 2
78
+ });
79
+ }
72
80
  console.log(`\u2728 \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
81
+ return projectConfig;
73
82
  } catch {
74
83
  console.warn(`\u2728 \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u5931\u8D25!`);
75
84
  }
@@ -78,7 +87,7 @@ function updateProjectConfig(options) {
78
87
  }
79
88
  }
80
89
  function updatePackageJson(options) {
81
- const { root, dest, command } = options;
90
+ const { root, dest, command, cb, write = true } = options;
82
91
  const packageJsonFilename = "package.json";
83
92
  const packageJsonPath = import_node_path.default.resolve(root, packageJsonFilename);
84
93
  if (import_fs_extra.default.existsSync(packageJsonPath)) {
@@ -86,21 +95,48 @@ function updatePackageJson(options) {
86
95
  const packageJson = import_fs_extra.default.readJSONSync(packageJsonPath);
87
96
  (0, import_shared.set)(packageJson, "scripts.dev", `${command} dev`);
88
97
  (0, import_shared.set)(packageJson, "scripts.build", `${command} build`);
89
- import_fs_extra.default.outputJSONSync(dest ?? packageJsonPath, packageJson, {
90
- spaces: 2
91
- });
98
+ if (command === "weapp-vite") {
99
+ (0, import_shared.set)(packageJson, "scripts.open", `${command} open`);
100
+ }
101
+ cb?.(
102
+ (...args) => {
103
+ (0, import_shared.set)(packageJson, ...args);
104
+ }
105
+ );
106
+ if (write) {
107
+ import_fs_extra.default.outputJSONSync(dest ?? packageJsonPath, packageJson, {
108
+ spaces: 2
109
+ });
110
+ }
111
+ return packageJson;
92
112
  } catch {
93
113
  }
94
114
  }
95
115
  }
116
+ function initViteConfigFile(options) {
117
+ const { root, write = true } = options;
118
+ const viteConfigFile = import_node_path.default.resolve(root, "vite.config.ts");
119
+ const code = `import { defineConfig } from 'weapp-vite/config'
120
+
121
+ export default defineConfig({})
122
+ `;
123
+ if (write) {
124
+ import_fs_extra.default.outputFileSync(viteConfigFile, code, "utf8");
125
+ }
126
+ return code;
127
+ }
96
128
  function initConfig(options) {
97
129
  const { root, command } = options;
98
130
  updateProjectConfig({ root });
99
131
  updatePackageJson({ root, command });
132
+ if (command === "weapp-vite") {
133
+ initViteConfigFile({ root });
134
+ }
100
135
  }
101
136
  // Annotate the CommonJS export names for ESM import in node:
102
137
  0 && (module.exports = {
103
138
  initConfig,
139
+ initViteConfigFile,
104
140
  updatePackageJson,
105
141
  updateProjectConfig
106
142
  });
package/dist/index.d.cts CHANGED
@@ -1,15 +1,37 @@
1
- declare function updateProjectConfig(options: {
2
- root: string;
3
- dest?: string;
4
- }): void;
5
- declare function updatePackageJson(options: {
1
+ import { set } from '@weapp-core/shared';
2
+
3
+ interface SetMethod {
4
+ (path: set.InputType, value: any, options?: set.Options): void;
5
+ }
6
+ interface SharedUpdateOptions {
6
7
  root: string;
7
8
  dest?: string;
8
- command?: string;
9
- }): void;
9
+ write?: boolean;
10
+ cb?: (set: SetMethod) => void;
11
+ }
12
+ interface UpdateProjectConfigOptions extends SharedUpdateOptions {
13
+ }
14
+ interface UpdatePackageJsonOptions extends SharedUpdateOptions {
15
+ command?: 'weapp-vite';
16
+ }
17
+ declare function updateProjectConfig(options: UpdateProjectConfigOptions): {
18
+ miniprogramRoot?: string | undefined;
19
+ srcMiniprogramRoot?: string | undefined;
20
+ setting: {
21
+ packNpmManually: boolean;
22
+ packNpmRelationList: {
23
+ packageJsonPath: string;
24
+ miniprogramNpmDistDir: string;
25
+ }[];
26
+ };
27
+ } | undefined;
28
+ declare function updatePackageJson(options: UpdatePackageJsonOptions): {
29
+ scripts: Record<string, string>;
30
+ } | undefined;
31
+ declare function initViteConfigFile(options: SharedUpdateOptions): string;
10
32
  declare function initConfig(options: {
11
33
  root: string;
12
- command?: string;
34
+ command?: 'weapp-vite';
13
35
  }): void;
14
36
 
15
- export { initConfig, updatePackageJson, updateProjectConfig };
37
+ export { type SetMethod, type SharedUpdateOptions, type UpdatePackageJsonOptions, type UpdateProjectConfigOptions, initConfig, initViteConfigFile, updatePackageJson, updateProjectConfig };
package/dist/index.d.ts CHANGED
@@ -1,15 +1,37 @@
1
- declare function updateProjectConfig(options: {
2
- root: string;
3
- dest?: string;
4
- }): void;
5
- declare function updatePackageJson(options: {
1
+ import { set } from '@weapp-core/shared';
2
+
3
+ interface SetMethod {
4
+ (path: set.InputType, value: any, options?: set.Options): void;
5
+ }
6
+ interface SharedUpdateOptions {
6
7
  root: string;
7
8
  dest?: string;
8
- command?: string;
9
- }): void;
9
+ write?: boolean;
10
+ cb?: (set: SetMethod) => void;
11
+ }
12
+ interface UpdateProjectConfigOptions extends SharedUpdateOptions {
13
+ }
14
+ interface UpdatePackageJsonOptions extends SharedUpdateOptions {
15
+ command?: 'weapp-vite';
16
+ }
17
+ declare function updateProjectConfig(options: UpdateProjectConfigOptions): {
18
+ miniprogramRoot?: string | undefined;
19
+ srcMiniprogramRoot?: string | undefined;
20
+ setting: {
21
+ packNpmManually: boolean;
22
+ packNpmRelationList: {
23
+ packageJsonPath: string;
24
+ miniprogramNpmDistDir: string;
25
+ }[];
26
+ };
27
+ } | undefined;
28
+ declare function updatePackageJson(options: UpdatePackageJsonOptions): {
29
+ scripts: Record<string, string>;
30
+ } | undefined;
31
+ declare function initViteConfigFile(options: SharedUpdateOptions): string;
10
32
  declare function initConfig(options: {
11
33
  root: string;
12
- command?: string;
34
+ command?: 'weapp-vite';
13
35
  }): void;
14
36
 
15
- export { initConfig, updatePackageJson, updateProjectConfig };
37
+ export { type SetMethod, type SharedUpdateOptions, type UpdatePackageJsonOptions, type UpdateProjectConfigOptions, initConfig, initViteConfigFile, updatePackageJson, updateProjectConfig };
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import path from "node:path";
3
3
  import fs from "fs-extra";
4
4
  import { get, set } from "@weapp-core/shared";
5
5
  function updateProjectConfig(options) {
6
- const { root, dest } = options;
6
+ const { root, dest, cb, write = true } = options;
7
7
  const projectConfigFilename = "project.config.json";
8
8
  const projectConfigPath = path.resolve(root, projectConfigFilename);
9
9
  if (fs.existsSync(projectConfigPath)) {
@@ -12,6 +12,11 @@ function updateProjectConfig(options) {
12
12
  set(projectConfig, "miniprogramRoot", "dist/");
13
13
  set(projectConfig, "srcMiniprogramRoot", "dist/");
14
14
  set(projectConfig, "setting.packNpmManually", true);
15
+ cb?.(
16
+ (...args) => {
17
+ set(projectConfig, ...args);
18
+ }
19
+ );
15
20
  if (Array.isArray(get(projectConfig, "setting.packNpmRelationList"))) {
16
21
  const x = projectConfig.setting.packNpmRelationList.find(
17
22
  (x2) => x2.packageJsonPath === "./package.json" && x2.miniprogramNpmDistDir === "./dist"
@@ -30,10 +35,13 @@ function updateProjectConfig(options) {
30
35
  }
31
36
  ]);
32
37
  }
33
- fs.outputJSONSync(dest ?? projectConfigPath, projectConfig, {
34
- spaces: 2
35
- });
38
+ if (write) {
39
+ fs.outputJSONSync(dest ?? projectConfigPath, projectConfig, {
40
+ spaces: 2
41
+ });
42
+ }
36
43
  console.log(`\u2728 \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u6210\u529F!`);
44
+ return projectConfig;
37
45
  } catch {
38
46
  console.warn(`\u2728 \u8BBE\u7F6E ${projectConfigFilename} \u914D\u7F6E\u6587\u4EF6\u5931\u8D25!`);
39
47
  }
@@ -42,7 +50,7 @@ function updateProjectConfig(options) {
42
50
  }
43
51
  }
44
52
  function updatePackageJson(options) {
45
- const { root, dest, command } = options;
53
+ const { root, dest, command, cb, write = true } = options;
46
54
  const packageJsonFilename = "package.json";
47
55
  const packageJsonPath = path.resolve(root, packageJsonFilename);
48
56
  if (fs.existsSync(packageJsonPath)) {
@@ -50,20 +58,47 @@ function updatePackageJson(options) {
50
58
  const packageJson = fs.readJSONSync(packageJsonPath);
51
59
  set(packageJson, "scripts.dev", `${command} dev`);
52
60
  set(packageJson, "scripts.build", `${command} build`);
53
- fs.outputJSONSync(dest ?? packageJsonPath, packageJson, {
54
- spaces: 2
55
- });
61
+ if (command === "weapp-vite") {
62
+ set(packageJson, "scripts.open", `${command} open`);
63
+ }
64
+ cb?.(
65
+ (...args) => {
66
+ set(packageJson, ...args);
67
+ }
68
+ );
69
+ if (write) {
70
+ fs.outputJSONSync(dest ?? packageJsonPath, packageJson, {
71
+ spaces: 2
72
+ });
73
+ }
74
+ return packageJson;
56
75
  } catch {
57
76
  }
58
77
  }
59
78
  }
79
+ function initViteConfigFile(options) {
80
+ const { root, write = true } = options;
81
+ const viteConfigFile = path.resolve(root, "vite.config.ts");
82
+ const code = `import { defineConfig } from 'weapp-vite/config'
83
+
84
+ export default defineConfig({})
85
+ `;
86
+ if (write) {
87
+ fs.outputFileSync(viteConfigFile, code, "utf8");
88
+ }
89
+ return code;
90
+ }
60
91
  function initConfig(options) {
61
92
  const { root, command } = options;
62
93
  updateProjectConfig({ root });
63
94
  updatePackageJson({ root, command });
95
+ if (command === "weapp-vite") {
96
+ initViteConfigFile({ root });
97
+ }
64
98
  }
65
99
  export {
66
100
  initConfig,
101
+ initViteConfigFile,
67
102
  updatePackageJson,
68
103
  updateProjectConfig
69
104
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@weapp-core/init",
3
3
  "type": "module",
4
- "version": "0.0.2-alpha.1",
4
+ "version": "0.0.2-alpha.2",
5
5
  "description": "@weapp-core/init",
6
6
  "author": "",
7
7
  "license": "ISC",
@@ -22,7 +22,7 @@
22
22
  ],
23
23
  "dependencies": {
24
24
  "fs-extra": "^11.2.0",
25
- "@weapp-core/shared": "^0.0.2-alpha.1"
25
+ "@weapp-core/shared": "^0.0.2-alpha.2"
26
26
  },
27
27
  "scripts": {
28
28
  "dev": "tsup --watch --sourcemap",