aiot-toolkit 1.1.5-beta.2 → 1.2.0-alpha.1
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/bin/index.js +11 -0
- package/lib/commands/ai.js +2 -0
- package/lib/commands/init.js +1 -1
- package/package.json +11 -9
package/bin/index.js
CHANGED
|
@@ -28,6 +28,14 @@ checkVersion()
|
|
|
28
28
|
|
|
29
29
|
program.version(require('../package').version, '-v, --version').usage('<command> [options]')
|
|
30
30
|
|
|
31
|
+
program
|
|
32
|
+
.command('ai')
|
|
33
|
+
.description('Quick App Smart Programming Assistant.')
|
|
34
|
+
.action((name, options) => {
|
|
35
|
+
const ai = require('../src/commands/ai')
|
|
36
|
+
ai()
|
|
37
|
+
})
|
|
38
|
+
|
|
31
39
|
program
|
|
32
40
|
.command('init <app-name>')
|
|
33
41
|
.option('--dsl <name>', 'init project by specific dsl template, eg: vue')
|
|
@@ -93,6 +101,7 @@ program
|
|
|
93
101
|
validateBuildNameFormat
|
|
94
102
|
)
|
|
95
103
|
.option('--enable-protobuf', 'use protobuf gen binary.bin file')
|
|
104
|
+
.option('--enable-laboratory', 'enable features in the experiment')
|
|
96
105
|
.action(options => {
|
|
97
106
|
// 必备参数:当开发者不传递该参数时,要解析为默认
|
|
98
107
|
const signModeTmp = options.disableSign && compileOptionsMeta.signModeEnum.NULL
|
|
@@ -136,6 +145,7 @@ program
|
|
|
136
145
|
.option('--enable-ops-wrap', 'inject performance log in code')
|
|
137
146
|
.option('--disable-build-rpk', 'disable build rpk')
|
|
138
147
|
.option('--enable-protobuf', 'use protobuf gen binary.bin file')
|
|
148
|
+
.option('--enable-laboratory', 'enable features in the experiment')
|
|
139
149
|
.option(
|
|
140
150
|
'--build-name-format <build-name-format>',
|
|
141
151
|
'custom output rpk file name',
|
|
@@ -225,6 +235,7 @@ program
|
|
|
225
235
|
.option('--enable-protobuf', 'use protobuf gen binary.bin file')
|
|
226
236
|
.option('--enable-image-bin', 'translate image to bin')
|
|
227
237
|
.option('--enable-image-png8', 'translate image to png8')
|
|
238
|
+
.option('--enable-laboratory', 'enable features in the experiment')
|
|
228
239
|
.option(
|
|
229
240
|
'--split-chunks-mode <value>',
|
|
230
241
|
'extract js module to single files',
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";const ora=require("ora"),chalk=require("chalk"),inquirer=require("inquirer"),axios=require("axios"),fs=require("fs"),fsExtra=require("fs-extra"),path=require("path"),DIFY_API_BASE_URL="https://mify-be.pt.xiaomi.com",API_PATH="/api/v1/chat-messages",API_KEY="app-MS7p2SLhiTHDBgR7HqkxNGSh",headers={Authorization:`Bearer ${API_KEY}`,"Content-Type":"application/json"},mockData={project_name:"Calculator",package_name:"com.example.calculator",page_content:"<template>",manifest:{package:"com.example.calculator",name:"Calculator",versionName:"1.0.0",versionCode:1,minPlatformVersion:1070,icon:"/Common/logo.png",features:[],permissions:[],config:{logLevel:"debug",designWidth:750},router:{entry:"Calculator",pages:{Calculator:{component:"index"}}},display:{titleBarBackgroundColor:"#202020",titleBarTextColor:"#ffffff",menu:!0,pages:{Calculator:{titleBarText:"计算器",menu:!1}}}}};async function postData(e){const a={inputs:{},response_mode:"blocking",conversation_id:"",user:"lewis",query:e};try{const e=await axios.post(`${DIFY_API_BASE_URL+API_PATH}`,a,{headers:headers});return writeAnswerToFile(e.data.answer,"/home/lvxin/work/gerrit/aiot-toolkit/answer.log"),cleanJSON(e.data.answer)}catch(e){console.error("POST Error:",e.response?e.response.data:e.message)}}const sleep=e=>new Promise((a=>setTimeout(a,e)));function writeAnswerToFile(e,a){fs.writeFile(a,e,{flag:"a"},(e=>{}))}function cleanJSON(e){try{let a=JSON.parse(e),n=a.page_content.replace(/\\n/g,"\n").replace(/\\"/g,'"').replace(/\\t/g,"\t"),t=JSON.parse(a.manifest.replace(/\\"/g,'"'));return{project_name:a.project_name,package_name:a.package_name,page_content:n,manifest:t}}catch(e){return console.error("\nError parsing JSON:",e),null}}function replacePage(e,a,n){const t=path.join(process.cwd(),n),r=path.join(t,"src",n,"index.ux"),o=path.join(t,"src","manifest.json");fs.mkdirSync(path.dirname(r),{recursive:!0}),fs.mkdirSync(path.dirname(o),{recursive:!0}),fs.writeFileSync(r,a);const i=JSON.stringify(e,null,2);fs.writeFileSync(o,i)}async function ai(){const e=`\n${chalk.bold.green("快应用智能编程助手\n")}\n${chalk.cyan("您好!我是快应用智能编程助手,专注于为您创建高质量的快应用项目文件。\n")}\n${chalk.yellow("您可以试试这样说:")}\n${chalk.magenta(" 做一个天气快应用")}\n${chalk.magenta(" 做一个计算器手表快应用")}\n${chalk.magenta(" 做一个滴答清单手环快应用")}\n `;console.log(e);const a=await inquirer.prompt({type:"input",name:"prompt",message:"请输入您的需求:",prefix:"",validate:e=>e.length>0||"请输入您的需求!"});let n=1;const t=ora({text:chalk.cyan(`\n生成中... ${chalk.green(n)}s \n`),spinner:"dots"});t.start(),setInterval((()=>{t.text=chalk.cyan(`\n生成中... ${chalk.green(n++)}s`)}),1e3);const r=await postData(a.prompt);if(!r)return t.fail(chalk.red("生成失败,请重新生成!")),ai();const{project_name:o,package_name:i,page_content:c,manifest:s}=r;console.log(`${chalk.yellow("\n项目名称:")+o}`),console.log(`${chalk.yellow("包名:")+i}\n`);const l=Array.isArray(s.deviceTypeList)&&s.deviceTypeList.length>0?s.deviceTypeList[0]:"phone",p=require("../../lib/commands/init");await p(o),replacePage(s,c,o),t.succeed(chalk.green("\n恭喜!您的快应用项目已经创建成功!\n"));const m=path.join(process.cwd(),o);inquirer.prompt([{type:"confirm",name:"preview",message:"请问是否进行预览?",prefix:"",default:!0}]).then((e=>{if(e.preview){if("watch"===l){const e="/home/lvxin/work/test/ai-quickapp/velasim";fsExtra.copySync(e,path.join(m,"node_modules/@aiot-toolkit/velasim"));const{compile:a}=require("../../lib/commands/compile");return void a("native","dev",!0,{cwd:m,openNuttx:!0})}const{launchServer:e}=require("@aiot-toolkit/server"),{compile:a}=require("../../lib/commands/compile");e({watch:!0,cwd:m,openBrowser:!0}),a("native","dev",!0,{cwd:m})}else console.log(`${chalk.green("\n您可以使用以下命令进行开发预览调试:")}`),console.log(`${chalk.cyan(" npm run start")}`),console.log(`${chalk.cyan(" npm run build")}`),console.log(`${chalk.cyan(" npm run watch")}`)}))}module.exports=ai;
|
|
2
|
+
//# sourceMappingURL=ai.js.map
|
package/lib/commands/init.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var _path=_interopRequireDefault(require("path")),_fsExtra=_interopRequireDefault(require("fs-extra")),_glob=_interopRequireDefault(require("glob")),
|
|
1
|
+
"use strict";var _path=_interopRequireDefault(require("path")),_fsExtra=_interopRequireDefault(require("fs-extra")),_glob=_interopRequireDefault(require("glob")),_chalk=_interopRequireDefault(require("chalk")),_sharedUtils=require("@aiot-toolkit/shared-utils"),_template=_interopRequireDefault(require("@aiot-toolkit/dsl-xvm/lib/template")),_template2=_interopRequireDefault(require("@aiot-toolkit/dsl-vue/lib/template")),_utils=require("@aiot-toolkit/compiler/lib/utils");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const allSupportedDeviceArray=["phone","tv","car","watch","tv-h5"],allSupportedDevicesString=allSupportedDeviceArray.join(",");async function generate(e,t){""===e&&(e="HelloWorld");const a={type:"input",name:e,message:"Init your project",default:e},l=_path.default.join(process.cwd(),a.name);try{await createProject(a.name,l,t)}catch(a){_sharedUtils.colorconsole.error(a.message),a.message.match(/Please pick a new name/)&&await generate(e,t)}}async function createProject(e,t,a={}){if(_fsExtra.default.existsSync(t))throw new Error(`"${t}" exists! Please pick a new name.`);if(!(0,_sharedUtils.mkdirsSync)(t))throw new Error('failed to created folder "'+t+'"!.');const{dsl:l,deviceType:i,templateType:r,web:o,minaH5:n,minaTv:s}=a;let p="";if(r&&!i)throw new Error("there is no deviceType specified");p=(0,_utils.hyphenedToCamelCase)(`${i}-${r}`);let u=["phone"];if(s&&(u=["tv-quickapp"]),n&&(u=["tv-h5"]),i&&i.length>0){const e=i.split(",");let t=new Set,a=new Set;e.map((e=>{e=e.toLowerCase();allSupportedDeviceArray.includes(e)||a.add(e),t.add(e)})),u=Array.from(t),a.size>0&&(_sharedUtils.colorconsole.warn(`These device types have not been officially supported by Quickapp: "${Array.from(a).join(",")}"`),_sharedUtils.colorconsole.warn(`Now Quickapp officially supports device types: "${allSupportedDevicesString}"`))}let c=null,d=null;switch(l){case"vue":c=_template2.default.app.demo,d=_template2.default.app.deviceJsonTemplate;break;default:c=o?_template.default.app.webDemo:n?_template.default.app.minaH5Demo:s?_template.default.app.minaTvDemo:p&&_template.default.app[p]?_template.default.app[p]:u.includes("watch")?_template.default.app.velaDemo:_template.default.app.demo,d=_template.default.app.deviceJsonTemplate}const f=_path.default.resolve(__dirname,c);await copyFiles(t,f,{_gitignore:".gitignore"});const m={appName:e,toolkitVersion:require("../../package.json").version};(n?["package.json","manifest.json"]:["src/manifest.json","package.json"]).map((e=>_path.default.join(t,e))).forEach((e=>{let t=_fsExtra.default.readFileSync(e,"utf-8");if(t=(0,_sharedUtils.renderString)(t,m),e.includes("manifest.json")){let e=JSON.parse(t.toString());e.deviceTypeList=u,e.minAPILevel=1,t=JSON.stringify(e,null,2)}_fsExtra.default.writeFileSync(e,t)})),n||u.map((e=>{const a=`config-${e}.json`,l=_path.default.join(d,a);let i="{}";_fsExtra.default.existsSync(l)&&(i=_fsExtra.default.readFileSync(l,"utf-8")),_fsExtra.default.writeFileSync(_path.default.join(t,`src/config-${e}.json`),i)}))}function copyFiles(e,t,a){const l=_path.default.join(t,"**/{*,.*}"),i=_glob.default.sync(l,{nodir:!0,dot:!0}).map((l=>new Promise((i=>{const r=_path.default.relative(t,l),o=_path.default.join(e,a[r]||r);_fsExtra.default.existsSync(o)?i(_chalk.default.yellow(`${(0,_sharedUtils.relateCwd)(o)} already existed.`)):(i(),_fsExtra.default.copySync(l,o))}))));return Promise.all(i).then((e=>{}))}module.exports=generate;
|
|
2
2
|
//# sourceMappingURL=init.js.map
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aiot-toolkit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0-alpha.1",
|
|
4
4
|
"description": "A command line toolkit for developing Aiot Quick Apps.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=8.0.0"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@aiot-toolkit/compiler": "1.
|
|
10
|
-
"@aiot-toolkit/debugger": "1.
|
|
11
|
-
"@aiot-toolkit/dsl-vue": "1.
|
|
12
|
-
"@aiot-toolkit/dsl-xvm": "1.
|
|
13
|
-
"@aiot-toolkit/packager": "1.
|
|
14
|
-
"@aiot-toolkit/server": "1.
|
|
15
|
-
"@aiot-toolkit/shared-utils": "1.
|
|
9
|
+
"@aiot-toolkit/compiler": "1.2.0-alpha.1",
|
|
10
|
+
"@aiot-toolkit/debugger": "1.2.0-alpha.1",
|
|
11
|
+
"@aiot-toolkit/dsl-vue": "1.2.0-alpha.1",
|
|
12
|
+
"@aiot-toolkit/dsl-xvm": "1.2.0-alpha.1",
|
|
13
|
+
"@aiot-toolkit/packager": "1.2.0-alpha.1",
|
|
14
|
+
"@aiot-toolkit/server": "1.2.0-alpha.1",
|
|
15
|
+
"@aiot-toolkit/shared-utils": "1.2.0-alpha.1",
|
|
16
16
|
"@babel/core": "^7.9.6",
|
|
17
17
|
"@babel/plugin-syntax-jsx": "^7.8.3",
|
|
18
18
|
"@babel/preset-env": "^7.9.6",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"adb-commander": "^0.1.9",
|
|
22
22
|
"ajv": "^6.12.6",
|
|
23
23
|
"ajv-errors": "^1.0.1",
|
|
24
|
+
"axios": "^1.8.1",
|
|
24
25
|
"babel-loader": "^8.3.0",
|
|
25
26
|
"chalk": "^2.3.0",
|
|
26
27
|
"commander": "~2.14.1",
|
|
@@ -28,6 +29,7 @@
|
|
|
28
29
|
"inquirer": "^6.5.2",
|
|
29
30
|
"jszip": "^3.4.0",
|
|
30
31
|
"lodash": "^4.17.21",
|
|
32
|
+
"ora": "^5.4.1",
|
|
31
33
|
"request": "^2.88.2",
|
|
32
34
|
"semver": "^5.7.1",
|
|
33
35
|
"socket.io": "^2.3.0",
|
|
@@ -52,5 +54,5 @@
|
|
|
52
54
|
"supertest": "^3.3.0",
|
|
53
55
|
"webpack-cli": "^4.3.0"
|
|
54
56
|
},
|
|
55
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "243f20a3c232a5f86c41aa4deb9a620922461010"
|
|
56
58
|
}
|