Commit 12296d21 authored by 谢卓城's avatar 谢卓城

新增:自动往app.json写入page

parent 3d6f8597
......@@ -11,6 +11,7 @@ const tap = require("gulp-tap");
const path = require("path");
const notify = require("gulp-notify");
const yargs = require("yargs");
const fs = require('fs');
const srcPath = "./src/**";
const distPath = "./dist/";
......@@ -206,6 +207,24 @@ const newfile = done => {
stream = stream.pipe(rename({ basename: name.toLowerCase() }));
}
if (type == "pages") {
let jsonPath = './src/app.json';
fs.readFile(jsonPath,'utf8',function (err, data) {
if(err) console.log(err);
var json = JSON.parse(data);//读取的值
json.pages.push(`${type}/${name}/${name}`);
console.log(` ${json.pages}`);
//把数据读出来,然后进行修改
var str = JSON.stringify(json,null,2);
//console.log(str);
fs.writeFile(jsonPath,str,function(err){
if(err){
console.error(err);
}
});
});
}
return stream.pipe(gulp.dest(`src/${type}/${name}/`));
};
gulp.task("new", newfile);
......
/**
* 除继承样式外, app.wxss 中的样式、组件所在页面的的样式对自定义组件无效。
* 参考文档:https://developers.weixin.qq.com/miniprogram/dev/framework/custom-component/wxml-wxss.html
* 采用 externalClasses 的方式 在组件.wxml需要的view的class加super-class,可以是多个
* 使用 <Component super-class="<#type#>" />
*/
Component({
properties: {
is: Boolean,
list: Array,
title: String // 简化的定义方式
},
externalClasses: ["super-class"],
data: {
content: "content"
},
methods: {
// 这里是一个自定义方法
tagAction(e) {
var eventOption = { content: e.currentTarget.dataset.text }; // 触发事件的选项
this.triggerEvent("tagClick", eventOption);
}
}
});
{
"component": true,
"usingComponents": {}
}
\ No newline at end of file
.container {
width: 100vw;
.text {
color: red;
}
}
\ No newline at end of file
<!--template/components/index.wxml-->
<view class="container" hover-class="none" hover-stop-propagation="false">
<text class="flex-item super-class" selectable="false" space="false" decode="false" bindtap="tagAction" data-text="{{content}}">{{content}}</text>
</view>
{
"navigationBarTitleText": "首页",
"navigationStyle": "custom",
"usingComponents": {}
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment