@widget-js/cli 1.2.2 → 1.2.4

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.
@@ -0,0 +1,6 @@
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
5
+ </profile>
6
+ </component>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="JpaBuddyIdeaProjectConfig">
4
+ <option name="renamerInitialized" value="true" />
5
+ </component>
6
+ </project>
package/.idea/misc.xml CHANGED
@@ -1,6 +1,8 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectRootManager">
4
- <output url="file://$PROJECT_DIR$/out" />
5
- </component>
1
+ <project version="4">
2
+ <component name="ProjectRootManager">
3
+ <output url="file://$PROJECT_DIR$/out" />
4
+ </component>
5
+ <component name="ProjectType">
6
+ <option name="id" value="jpab" />
7
+ </component>
6
8
  </project>
@@ -7,6 +7,7 @@ var widgetPackages = {
7
7
  "@widget-js/core": "",
8
8
  "@widget-js/vue3": "",
9
9
  "@widget-js/cli": "",
10
+ "@widget-js/utils": "",
10
11
  "@widget-js/vite-plugin-widget": ""
11
12
  };
12
13
  function exit(code = 0) {
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-3GPAHQ6O.js";
7
7
  import {
8
8
  exit
9
- } from "./chunk-KAH4IVEE.js";
9
+ } from "./chunk-IJH6LXRT.js";
10
10
 
11
11
  // src/createWidget.ts
12
12
  import path from "path";
@@ -165,7 +165,6 @@ async function createWidget() {
165
165
  const widgetViewFile = path.resolve(widgetDir, `${name}WidgetView.vue`);
166
166
  const widgetRoutesFile = path.resolve(widgetDir, `${name}WidgetRoutes.ts`);
167
167
  EJSUtils.renderToFile("WidgetDefine.ejs", widgetDefineFile, "typescript", renderOptions);
168
- EJSUtils.renderToFile("Widget.ejs", widgetFile, "vue", renderOptions);
169
168
  EJSUtils.renderToFile("WidgetView.ejs", widgetViewFile, "vue", renderOptions);
170
169
  EJSUtils.renderToFile("WidgetRoutes.ejs", widgetRoutesFile, "typescript", renderOptions);
171
170
  if (configurable) {
@@ -2,7 +2,7 @@ import {
2
2
  Utils,
3
3
  getPackagePath,
4
4
  widgetPackages
5
- } from "./chunk-KAH4IVEE.js";
5
+ } from "./chunk-IJH6LXRT.js";
6
6
 
7
7
  // src/dependencies/remoteDependencies.ts
8
8
  import ora from "ora";
package/lib/index.js CHANGED
@@ -11,22 +11,22 @@ var cliPackage = JSON.parse(fs.readFileSync(packageJsonPath).toString());
11
11
  console.log(gradient.pastel.multiline(figlet.textSync("widget-cli", { horizontalLayout: "full" })));
12
12
  program.version(`@widget-js/cli ${cliPackage.version}`).usage("<command> [options]");
13
13
  program.command("create").description("Create new widget").action(async () => {
14
- const createWidget = await import("./createWidget-QSHTD2M7.js");
14
+ const createWidget = await import("./createWidget-UCZL7NIF.js");
15
15
  await createWidget.default();
16
16
  });
17
17
  var dependenciesOption = new Option("-t, --type <type>").choices(["remote", "local"]);
18
18
  program.command("dependencies").description("Set @widget-js dependencies to local(workspace:*) or remote(^1.0.0 etc)").addOption(dependenciesOption).action(async (options) => {
19
- let dependencies = await import("./dependencies-UDW4LKDQ.js");
19
+ let dependencies = await import("./dependencies-MRJDJJ6Q.js");
20
20
  await dependencies.default(options);
21
21
  });
22
22
  program.command("init").description("Initialize widget-js project").action(async () => {
23
- const init = await import("./init-SS2RG3IV.js");
23
+ const init = await import("./init-2NOIC3PQ.js");
24
24
  await init.init();
25
25
  });
26
26
  var typeOption = new Option("-t, --type <type>").choices(["ftp", "oss"]);
27
27
  var fileOption = new Option("-f, --file <file>");
28
28
  program.command("release").description("\u901A\u8FC7FTP/OSS\u53D1\u5E03\u6587\u4EF6\uFF0C\u4EC5\u5185\u90E8\u4F7F\u7528").addOption(typeOption).addOption(fileOption).action(async (options, command) => {
29
- let release = await import("./release-VEU3T5KK.js");
29
+ let release = await import("./release-NJG7IUNP.js");
30
30
  await release.default(options);
31
31
  });
32
32
  program.parse(process.argv);
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-3GPAHQ6O.js";
7
7
  import {
8
8
  Utils
9
- } from "./chunk-KAH4IVEE.js";
9
+ } from "./chunk-IJH6LXRT.js";
10
10
 
11
11
  // src/init/init.ts
12
12
  import path from "path";
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-3GPAHQ6O.js";
4
4
  import {
5
5
  Utils
6
- } from "./chunk-KAH4IVEE.js";
6
+ } from "./chunk-IJH6LXRT.js";
7
7
 
8
8
  // src/release/release.ts
9
9
  import fs4 from "fs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widget-js/cli",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "main": "lib/index.js",
5
5
  "author": "Neo Fu",
6
6
  "license": "MIT",
@@ -62,7 +62,7 @@
62
62
  "vitest": "^0.34.6",
63
63
  "webpack": "^5.75.0",
64
64
  "webpack-cli": "^5.0.0",
65
- "@widget-js/core": "0.10.14"
65
+ "@widget-js/core": "0.10.19"
66
66
  },
67
67
  "scripts": {
68
68
  "build": "rimraf ./lib/ && tsup-node src/index.ts --format esm",
@@ -193,7 +193,7 @@ export default async function createWidget() {
193
193
  const widgetRoutesFile = path.resolve(widgetDir, `${name}WidgetRoutes.ts`)
194
194
 
195
195
  EJSUtils.renderToFile('WidgetDefine.ejs', widgetDefineFile, 'typescript', renderOptions)
196
- EJSUtils.renderToFile('Widget.ejs', widgetFile, 'vue', renderOptions)
196
+ // EJSUtils.renderToFile('Widget.ejs', widgetFile, 'vue', renderOptions)
197
197
  EJSUtils.renderToFile('WidgetView.ejs', widgetViewFile, 'vue', renderOptions)
198
198
  EJSUtils.renderToFile('WidgetRoutes.ejs', widgetRoutesFile, 'typescript', renderOptions)
199
199
  if (configurable) {
@@ -1,140 +1,140 @@
1
- import path from 'path'
2
- import fs from 'fs'
3
- import SSHConfig from '@widget-js/ssh-config'
4
- import os from 'os'
5
- import Client from 'ssh2-sftp-client'
6
- import consola from 'consola'
7
- import inquirer from 'inquirer'
8
- import ora from 'ora'
9
- import * as process from 'process'
10
- import {Utils} from '../utils'
11
- import {minimatch} from 'minimatch'
12
-
13
- interface PasswordAnswer {
14
- password: string
15
- }
16
-
17
- async function checkParentDir(ftpClient: Client, file: string, onMkdir: (dir: string) => void) {
18
- let dir = path.dirname(file)
19
- const dirExists = await ftpClient.exists(dir)
20
- if (!dirExists) {
21
- onMkdir(dir)
22
- await ftpClient.mkdir(dir, true)
23
- }
24
- }
25
-
26
- async function runSSH(sshConfig: Record<string, string | string[]>, releaseConfig: ReleaseConfig) {
27
- consola.info('run ssh:', sshConfig)
28
- const answer = await inquirer.prompt<PasswordAnswer>([
29
- {type: 'password', name: 'password', mask: '*', message: 'Enter key pair password'},
30
- ])
31
-
32
- let ftpClient = new Client()
33
- const port = sshConfig['Port']
34
- const key = fs.readFileSync(path.resolve(os.homedir(), '.ssh/id_rsa'))
35
- const spinner = ora('Connecting')
36
- try {
37
- spinner.start()
38
- await ftpClient.connect({
39
- host: sshConfig['HostName'] as string,
40
- port: port ? parseInt(port as string) : 22,
41
- username: sshConfig['User'] as string,
42
- passphrase: answer.password,
43
- privateKey: key,
44
- })
45
- releaseConfig.fileMap.sort((it1, it2) => (it1.order ?? 0) - (it2.order ?? 0))
46
- // upload files
47
- for (let item of releaseConfig.fileMap) {
48
- if (typeof item.src == 'string') {
49
- if (item.remoteCopy) {
50
- await checkParentDir(ftpClient, item.dest, dir => {
51
- spinner.warn(`Create Dir: ${dir}`)
52
- })
53
- let destExists = await ftpClient.exists(item.dest)
54
- if (destExists) {
55
- spinner.warn(`Delete exists file:${item.dest}`)
56
- await ftpClient.delete(item.dest)
57
- }
58
- spinner.info(`Copying File: ${item.src} -> ${item.dest}`)
59
- await ftpClient.rcopy(item.src, item.dest)
60
- } else {
61
- const localFile = path.resolve(process.cwd(), item.src as string)
62
- if (!item.remoteCopy && !fs.existsSync(localFile)) {
63
- spinner.warn(`Skip not exists file:${localFile}`)
64
- continue
65
- }
66
- if (fs.lstatSync(localFile).isDirectory()) {
67
- spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`)
68
- await ftpClient.uploadDir(localFile, item.dest, {
69
- filter: (filePath: string, isDirectory: boolean):boolean => {
70
- if (item.ignorePattern && !isDirectory) {
71
- let fileName = path.basename(filePath)
72
- if (minimatch(fileName, item.ignorePattern)) {
73
- spinner.warn(`Skip file:${filePath}`)
74
- return false
75
- }
76
- }
77
- return true;
78
- },
79
- })
80
- } else {
81
- await checkParentDir(ftpClient, item.dest, dir => {
82
- spinner.succeed(`Create Dir: ${dir}`)
83
- })
84
-
85
- spinner.info(`Uploading File: ${localFile} -> ${item.dest}`)
86
- await ftpClient.put(localFile, item.dest)
87
- }
88
- }
89
- } else {
90
- await ftpClient.put(Buffer.from(JSON.stringify(item.src), 'utf-8'), item.dest)
91
- }
92
- }
93
- spinner.succeed('Files uploaded!')
94
- await ftpClient.end()
95
- } catch (e) {
96
- spinner.fail(`Connection error:${e}`)
97
- await ftpClient.end()
98
- }
99
- }
100
-
101
- export async function ftpUpload(releaseFile: string = 'release.json') {
102
- // 读取
103
- const releaseJsonFilePath = path.join(process.cwd(), releaseFile)
104
- const packageVersion = Utils.getPackageVersion()
105
- consola.info('Package Version:', packageVersion)
106
-
107
- let releaseJson = fs.readFileSync(releaseJsonFilePath).toString().replaceAll('${version}', packageVersion)
108
- const releaseConfig = JSON.parse(releaseJson) as ReleaseConfig
109
- const sshConfigFile = path.resolve(os.homedir(), '.ssh/config')
110
- consola.info('SSH Config File Path:', sshConfigFile)
111
- const sshConfigs = SSHConfig.parse(fs.readFileSync(sshConfigFile).toString())
112
- for (let host of releaseConfig.ftpConfig.host) {
113
- let sshConfig = sshConfigs.compute(host)
114
- if (!sshConfig) {
115
- consola.error(`SSH config ${releaseConfig.ftpConfig.host} not found`)
116
- return
117
- }
118
- await runSSH(sshConfig, releaseConfig)
119
- }
120
- }
121
-
122
- export interface FileMapConfig {
123
- src: string | object
124
- dest: string
125
- remoteCopy: boolean
126
- order: number
127
- /**
128
- * 支持glob、正则表达式
129
- */
130
- ignorePattern?: string
131
- }
132
-
133
- export interface ReleaseConfig {
134
- fileMap: FileMapConfig[]
135
- ftpConfig: FTPConfig
136
- }
137
-
138
- export interface FTPConfig {
139
- host: string[]
140
- }
1
+ import path from 'path'
2
+ import fs from 'fs'
3
+ import SSHConfig from '@widget-js/ssh-config'
4
+ import os from 'os'
5
+ import Client from 'ssh2-sftp-client'
6
+ import consola from 'consola'
7
+ import inquirer from 'inquirer'
8
+ import ora from 'ora'
9
+ import * as process from 'process'
10
+ import {Utils} from '../utils'
11
+ import {minimatch} from 'minimatch'
12
+
13
+ interface PasswordAnswer {
14
+ password: string
15
+ }
16
+
17
+ async function checkParentDir(ftpClient: Client, file: string, onMkdir: (dir: string) => void) {
18
+ let dir = path.dirname(file)
19
+ const dirExists = await ftpClient.exists(dir)
20
+ if (!dirExists) {
21
+ onMkdir(dir)
22
+ await ftpClient.mkdir(dir, true)
23
+ }
24
+ }
25
+
26
+ async function runSSH(sshConfig: Record<string, string | string[]>, releaseConfig: ReleaseConfig) {
27
+ consola.info('run ssh:', sshConfig)
28
+ const answer = await inquirer.prompt<PasswordAnswer>([
29
+ {type: 'password', name: 'password', mask: '*', message: 'Enter key pair password'},
30
+ ])
31
+
32
+ let ftpClient = new Client()
33
+ const port = sshConfig['Port']
34
+ const key = fs.readFileSync(path.resolve(os.homedir(), '.ssh/id_rsa'))
35
+ const spinner = ora('Connecting')
36
+ try {
37
+ spinner.start()
38
+ await ftpClient.connect({
39
+ host: sshConfig['HostName'] as string,
40
+ port: port ? parseInt(port as string) : 22,
41
+ username: sshConfig['User'] as string,
42
+ passphrase: answer.password,
43
+ privateKey: key,
44
+ })
45
+ releaseConfig.fileMap.sort((it1, it2) => (it1.order ?? 0) - (it2.order ?? 0))
46
+ // upload files
47
+ for (let item of releaseConfig.fileMap) {
48
+ if (typeof item.src == 'string') {
49
+ if (item.remoteCopy) {
50
+ await checkParentDir(ftpClient, item.dest, dir => {
51
+ spinner.warn(`Create Dir: ${dir}`)
52
+ })
53
+ let destExists = await ftpClient.exists(item.dest)
54
+ if (destExists) {
55
+ spinner.warn(`Delete exists file:${item.dest}`)
56
+ await ftpClient.delete(item.dest)
57
+ }
58
+ spinner.info(`Copying File: ${item.src} -> ${item.dest}`)
59
+ await ftpClient.rcopy(item.src, item.dest)
60
+ } else {
61
+ const localFile = path.resolve(process.cwd(), item.src as string)
62
+ if (!item.remoteCopy && !fs.existsSync(localFile)) {
63
+ spinner.warn(`Skip not exists file:${localFile}`)
64
+ continue
65
+ }
66
+ if (fs.lstatSync(localFile).isDirectory()) {
67
+ spinner.info(`Uploading Dir: ${localFile} -> ${item.dest}`)
68
+ await ftpClient.uploadDir(localFile, item.dest, {
69
+ filter: (filePath: string, isDirectory: boolean):boolean => {
70
+ if (item.ignorePattern && !isDirectory) {
71
+ let fileName = path.basename(filePath)
72
+ if (minimatch(fileName, item.ignorePattern)) {
73
+ spinner.warn(`Skip file:${filePath}`)
74
+ return false
75
+ }
76
+ }
77
+ return true;
78
+ },
79
+ })
80
+ } else {
81
+ await checkParentDir(ftpClient, item.dest, dir => {
82
+ spinner.succeed(`Create Dir: ${dir}`)
83
+ })
84
+
85
+ spinner.info(`Uploading File: ${localFile} -> ${item.dest}`)
86
+ await ftpClient.put(localFile, item.dest)
87
+ }
88
+ }
89
+ } else {
90
+ await ftpClient.put(Buffer.from(JSON.stringify(item.src), 'utf-8'), item.dest)
91
+ }
92
+ }
93
+ spinner.succeed('Files uploaded!')
94
+ await ftpClient.end()
95
+ } catch (e) {
96
+ spinner.fail(`Connection error:${e}`)
97
+ await ftpClient.end()
98
+ }
99
+ }
100
+
101
+ export async function ftpUpload(releaseFile: string = 'release.json') {
102
+ // 读取
103
+ const releaseJsonFilePath = path.join(process.cwd(), releaseFile)
104
+ const packageVersion = Utils.getPackageVersion()
105
+ consola.info('Package Version:', packageVersion)
106
+
107
+ let releaseJson = fs.readFileSync(releaseJsonFilePath).toString().replaceAll('${version}', packageVersion)
108
+ const releaseConfig = JSON.parse(releaseJson) as ReleaseConfig
109
+ const sshConfigFile = path.resolve(os.homedir(), '.ssh/config')
110
+ consola.info('SSH Config File Path:', sshConfigFile)
111
+ const sshConfigs = SSHConfig.parse(fs.readFileSync(sshConfigFile).toString())
112
+ for (let host of releaseConfig.ftpConfig.host) {
113
+ let sshConfig = sshConfigs.compute(host)
114
+ if (!sshConfig) {
115
+ consola.error(`SSH config ${releaseConfig.ftpConfig.host} not found`)
116
+ return
117
+ }
118
+ await runSSH(sshConfig, releaseConfig)
119
+ }
120
+ }
121
+
122
+ export interface FileMapConfig {
123
+ src: string | object
124
+ dest: string
125
+ remoteCopy: boolean
126
+ order: number
127
+ /**
128
+ * 支持glob、正则表达式
129
+ */
130
+ ignorePattern?: string
131
+ }
132
+
133
+ export interface ReleaseConfig {
134
+ fileMap: FileMapConfig[]
135
+ ftpConfig: FTPConfig
136
+ }
137
+
138
+ export interface FTPConfig {
139
+ host: string[]
140
+ }
package/src/utils.ts CHANGED
@@ -4,7 +4,7 @@ import fs from "fs";
4
4
  import packageJson from "package-json";
5
5
 
6
6
  export const widgetPackages: { [key: string]: string } = {
7
- "@widget-js/core": "", "@widget-js/vue3": "", "@widget-js/cli": "", "@widget-js/vite-plugin-widget": ""
7
+ "@widget-js/core": "", "@widget-js/vue3": "", "@widget-js/cli": "","@widget-js/utils": "", "@widget-js/vite-plugin-widget": ""
8
8
  };
9
9
  export default function exit(code: number = 0) {
10
10
  if (exports.exitProcess) {
@@ -1,12 +1,12 @@
1
1
  <template>
2
- <!-- TODO:组件页面,这里编写组件业务逻辑-->
3
- <<%= paramCaseName %>-widget></<%= paramCaseName %>-widget>
2
+ <widget-wrapper>
3
+ <!-- TODO:组件页面,这里编写组件业务逻辑-->
4
+ </widget-wrapper>
4
5
  </template>
5
6
 
6
7
  <script lang="ts" setup>
7
8
  import {WidgetData} from "@widget-js/core";
8
- import <%= name %>Widget from "./<%= name %>Widget.vue"
9
- import {useWidget} from "@widget-js/vue3";
9
+ import {useWidget,WidgetWrapper} from "@widget-js/vue3";
10
10
 
11
11
  const {widgetData, widgetParams} = useWidget(WidgetData);
12
12
  </script>
@@ -1,64 +0,0 @@
1
- <component name="ProjectCodeStyleConfiguration">
2
- <code_scheme name="Project" version="173">
3
- <HTMLCodeStyleSettings>
4
- <option name="HTML_SPACE_INSIDE_EMPTY_TAG" value="true" />
5
- <option name="HTML_ENFORCE_QUOTES" value="true" />
6
- </HTMLCodeStyleSettings>
7
- <JSCodeStyleSettings version="0">
8
- <option name="FORCE_SEMICOLON_STYLE" value="true" />
9
- <option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
10
- <option name="FORCE_QUOTE_STYlE" value="true" />
11
- <option name="ENFORCE_TRAILING_COMMA" value="Remove" />
12
- <option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
13
- <option name="SPACES_WITHIN_IMPORTS" value="true" />
14
- </JSCodeStyleSettings>
15
- <JetCodeStyleSettings>
16
- <option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
17
- </JetCodeStyleSettings>
18
- <TypeScriptCodeStyleSettings version="0">
19
- <option name="FORCE_SEMICOLON_STYLE" value="true" />
20
- <option name="SPACE_BEFORE_FUNCTION_LEFT_PARENTH" value="false" />
21
- <option name="FORCE_QUOTE_STYlE" value="true" />
22
- <option name="ENFORCE_TRAILING_COMMA" value="Remove" />
23
- <option name="SPACES_WITHIN_OBJECT_LITERAL_BRACES" value="true" />
24
- <option name="SPACES_WITHIN_IMPORTS" value="true" />
25
- </TypeScriptCodeStyleSettings>
26
- <VueCodeStyleSettings>
27
- <option name="INTERPOLATION_NEW_LINE_AFTER_START_DELIMITER" value="false" />
28
- <option name="INTERPOLATION_NEW_LINE_BEFORE_END_DELIMITER" value="false" />
29
- </VueCodeStyleSettings>
30
- <codeStyleSettings language="HTML">
31
- <option name="SOFT_MARGINS" value="80" />
32
- <indentOptions>
33
- <option name="INDENT_SIZE" value="2" />
34
- <option name="CONTINUATION_INDENT_SIZE" value="2" />
35
- <option name="TAB_SIZE" value="2" />
36
- </indentOptions>
37
- </codeStyleSettings>
38
- <codeStyleSettings language="JavaScript">
39
- <option name="SOFT_MARGINS" value="80" />
40
- <indentOptions>
41
- <option name="INDENT_SIZE" value="2" />
42
- <option name="CONTINUATION_INDENT_SIZE" value="2" />
43
- <option name="TAB_SIZE" value="2" />
44
- </indentOptions>
45
- </codeStyleSettings>
46
- <codeStyleSettings language="TypeScript">
47
- <option name="SOFT_MARGINS" value="80" />
48
- <indentOptions>
49
- <option name="INDENT_SIZE" value="2" />
50
- <option name="CONTINUATION_INDENT_SIZE" value="2" />
51
- <option name="TAB_SIZE" value="2" />
52
- </indentOptions>
53
- </codeStyleSettings>
54
- <codeStyleSettings language="Vue">
55
- <option name="SOFT_MARGINS" value="80" />
56
- <indentOptions>
57
- <option name="CONTINUATION_INDENT_SIZE" value="2" />
58
- </indentOptions>
59
- </codeStyleSettings>
60
- <codeStyleSettings language="kotlin">
61
- <option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
62
- </codeStyleSettings>
63
- </code_scheme>
64
- </component>
@@ -1,5 +0,0 @@
1
- <component name="ProjectCodeStyleConfiguration">
2
- <state>
3
- <option name="USE_PER_PROJECT_SETTINGS" value="true" />
4
- </state>
5
- </component>
@@ -1,11 +0,0 @@
1
- <template>
2
- <!-- TODO 这里只写组件内容,不做自定义数据、业务处理 -->
3
- </template>
4
-
5
- <script lang="ts" setup>
6
-
7
- </script>
8
-
9
- <style scoped>
10
-
11
- </style>