Open xgqfrms-GitHub opened 7 years ago
fs.readdir(path[, options], callback)
https://nodejs.org/api/fs.html#fs_fs_readdir_path_options_callback
fs.lstatSync(path)
https://nodejs.org/docs/latest/api/fs.html#fs_fs_lstatsync_path
Class: fs.Stats
https://nodejs.org/docs/latest/api/fs.html#fs_class_fs_stats
const fs = require('fs');
let fsTest = () => {
fs.readFile('./views/**/**/*.ejs', 'utf8', (err, data) => {
if (err) throw err;
console.log(data);
});
}
let buildTree = (startPath) => {
fs.readdir(startPath, 'utf8', (err, entries) => {
if(err){
throw err;
}else{
console.log(entries);
}
});
}
/*
buildTree('views');
buildTree('views/');
buildTree('./views/');
*/
buildTree('views');
// process.cwd()
fs.rename('/tmp/hello', '/tmp/world', (err) => {
if (err) throw err;
fs.stat('/tmp/world', (err, stats) => {
if (err) throw err;
console.log(`stats: ${JSON.stringify(stats)}`);
});
});
// 大多数fs函数可以省略回调参数。
// 如果这样做,则使用默认回调来重新发送错误。要获取跟踪到原来的调用站点,请设置NODE_DEBUG环境变量:
/*
$ cat script.js
function bad() {
require('fs').readFile('/');
}
bad();
$ env NODE_DEBUG=fs node script.js
fs.js:88
throw backtrace;
^
Error: EISDIR: illegal operation on a directory, read
<stack trace.>
*/
// fs函数支持通过和接收路径作为字符串和缓冲区。
// 后者旨在使使用允许非UTF-8文件名的文件系统成为可能。
// 对于大多数典型的用途,使用缓冲区作为缓冲区是不必要的,因为字符串API会自动转换为UTF-8和UTF-8。
// 请注意,某些文件系统(如NTFS和HFS +)文件名将始终以UTF-8编码。在这样的文件系统上,将非UTF-8编码的缓冲区传递给fs函数将无法正常工作。
const fs = require('fs');
function buildTree(startPath) {
fs.readdir(startPath, (err, entries) => {
console.log(entries);
entries.forEach((file) => {
const path = `${startPath}/${file}`;
if (fs.lstatSync(path).isDirectory()) {
buildTree(path);
}
});
});
}
buildTree('/home/jim/Desktop/theme');
https://gist.github.com/xgqfrms-GitHub/0396d6eb4e541e6ff426ea869ec3a420
document.body.clientHeight
& document.body.scrollHeight;
document.body.scrollHeight;
// 1233
document.body.clientHeight;
//1233
let sidebarHeight = () => {
let sb = $('.sidebar-container');
let hight = document.body.clientHeight;
$( document ).ready(function() {
sb[0].style.height = `calc(${hight} - 90px)`;
});
}
async
)let sidebarHeight = () => {
let sb = $('.sidebar-container');
let hight = document.body.clientHeight;
$( document ).ready(function() {
sb[0].style.height = hight + 'px';
});
}
listener: () => {
$('#good_search').on('click', () => {
let startDate = $('#start_time').val(),
endDate = $('#end_time').val();
let date1 = new Date(startDate),
time1 = date1.getTime();
let date2 = new Date(endDate),
time2 = date2.getTime();
if (startDate === "" || endDate === "") {
Modal.setAlert('输入的时间不可为空!');
return false;
}else if (time1 > time2) {
Modal.setAlert('输入的开始时间不可大于结束时间!');
return false;
} else {
HCTable.test();
tableApi.ajax.reload();
setTimeout(function(){
sidebarHeight();
}, 100);
}
});
}
radiogroup
(Mozilla 私有技术)XUL (XML User-interface Language) XML用户交互语言
https://developer.mozilla.org/zh-CN/docs/Mozilla/Tech/XUL/radiogroup
https://developer.mozilla.org/zh-CN/docs/Mozilla/Tech/XUL/Tutorial/Input_Controls
https://developer.mozilla.org/zh-CN/docs/Mozilla/Tech/XUL/Tutorial
<radiogroup>
<radio id="orange" label="Red"/>
<radio id="violet" label="Green" selected="true"/>
<radio id="yellow" label="Blue"/>
</radiogroup>
input
https://developer.mozilla.org/zh-CN/docs/Web/Guide/HTML/HTML5
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input
<label for="">销售类型:</label>
正常
<input type="radio" value="0" data-radio="data-radio" name="saleType" data-info="正常" data-good="saleType" checked>
赠品
<input type="radio" value="1" data-radio="data-radio" name="saleType" data-info="赠品" data-good="saleType">
<input type="checkbox">
https://developer.mozilla.org/en-US/docs/Web/CSS/:checked
https://developer.mozilla.org/zh-CN/docs/Web/HTML/Element/Input/checkbox
CSS Pseudo-class
:invalid
& :valid
https://developer.mozilla.org/zh-CN/docs/Web/CSS/:valid
https://developer.mozilla.org/zh-CN/docs/Web/CSS/:invalid
:required
https://developer.mozilla.org/zh-CN/docs/Web/CSS/:required
:optional
<form id="form1">
<input type="radio" name="sex" value="男" />男
<input type="radio" name="sex" value="女" />女
<br />
<input type="radio" name="list" value="十分满意" />十分满意
<input type="radio" name="list" value="满意" />满意
<input type="radio" name="list" value="不满意" />不满意
<input type="radio" name="list" value="非常差" />非常差
<br />
<input type="submit" value="submit" id="btnSubmit" />
</form>
Identifying Files to Process
识别要处理的文件const fs = require('fs');
const Path = require('path');
function processFile(path) {
console.log(path);
}
function buildTree(startPath) {
fs.readdir(startPath, (err, entries) => {
entries.forEach((file) => {
const path = Path.join(startPath, file);
if (fs.lstatSync(path).isDirectory()) {
buildTree(path);
} else if (file.match(/\.php$/)) {
processFile(path);
}
});
});
}
buildTree('/home/jim/Desktop/theme');
Searching for Text within a File
搜索文件中的文本function processFile(path) {
const text = fs.readFileSync(path, 'utf8');
text.split(/\r?\n/).forEach((line) => {
if (line.match('http:\/\/')) {
console.log(line.replace(/^\s+/, ''));
console.log(`${path}\n`);
}
});
}
http://2ality.com/2011/12/nodejs-shell-scripting.html
https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options
https://nodejs.org/api/fs.html#fs_fs_readfilesync_file_options
webpack 2
https://www.sitepoint.com/beginners-guide-to-webpack-2-and-module-bundling/
https://www.youtube.com/watch?v=WQue1AN93YU
https://github.com/sitepoint-editors/webpack-demo https://github.com/markbrown4/webpack-demo
https://www.sitepoint.com/quick-tip-multiple-versions-node-nvm/
shell-scripts-javascript
https://www.sitepoint.com/shell-scripts-javascript/
https://www.howtogeek.com/181911/htg-explains-what-exactly-is-a-mixed-content-warning/
https://www.sitepoint.com/scaffolding-tool-caporal-js/