touchui-create
Advanced tools
Comparing version 0.0.7 to 0.0.8
{ | ||
"name": "touchui-create", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "touchui-create", | ||
@@ -5,0 +5,0 @@ "main": "main.js", |
@@ -5,4 +5,4 @@ var textfile = require('textfile') | ||
var page = { | ||
create(workSpace, pageDirname, pageName, title, callback) { | ||
var pagePath = path.join(pageDirname, pageName) | ||
create(workSpace, pageDirname, pageName, title, callback, mkdir) { | ||
var pagePath = mkdir ? pageDirname : path.join(pageDirname, pageName) | ||
function cb(...other) { | ||
@@ -23,44 +23,77 @@ if(typeof callback === 'function') { | ||
} | ||
// 创建json文件 | ||
var jsonFilePath = path.join(pagePath, pageName + '.json') | ||
var jsonData = {} | ||
if(title) { | ||
jsonData.navigationBarTitleText = title | ||
} | ||
jsonData = JSON.stringify(jsonData, null, 2) + '\n' | ||
textfile.write(path.join(pagePath, pageName + '.json'), jsonData, 'string', (err, filePath) => { | ||
fs.access(jsonData, err => { | ||
if(err) { | ||
cb(err) | ||
if(title) { | ||
jsonData.navigationBarTitleText = title | ||
} | ||
jsonData = JSON.stringify(jsonData, null, 2) + '\n' | ||
textfile.write(jsonFilePath, jsonData, 'string', (err, filePath) => { | ||
if(err) { | ||
cb(err) | ||
} else { | ||
end('json', filePath) | ||
} | ||
}) | ||
} else { | ||
end('json', filePath) | ||
end('json', jsonFilePath) | ||
} | ||
}) | ||
textfile.read(path.join(__dirname, 'template.js'), 'string', str => { | ||
str = str.replace('template', pageName) | ||
textfile.write(path.join(pagePath, pageName + '.js'), str, 'string', (err, filePath) => { | ||
if(err) { | ||
cb(err) | ||
} else { | ||
end('js', filePath) | ||
} | ||
}) | ||
// 创建js文件 | ||
var jsFilePath = path.join(pagePath, pageName + '.js') | ||
fs.access(jsFilePath, err => { | ||
if(err) { | ||
textfile.read(path.join(__dirname, 'template.js'), 'string', str => { | ||
str = str.replace('template', pageName) | ||
textfile.write(jsFilePath, str, 'string', (err, filePath) => { | ||
if(err) { | ||
cb(err) | ||
} else { | ||
end('js', filePath) | ||
} | ||
}) | ||
}) | ||
} else { | ||
end('js', jsFilePath) | ||
} | ||
}) | ||
textfile.read(path.join(__dirname, 'template.less'), 'string', str => { | ||
str = str.replace('template', pageName) | ||
textfile.write(path.join(pagePath, pageName + '.less'), str, 'string', (err, filePath) => { | ||
if(err) { | ||
cb(err) | ||
} else { | ||
end('less', filePath) | ||
} | ||
}) | ||
// 创建less文件 | ||
var lessFilePath = path.join(pagePath, pageName + '.less') | ||
fs.access(lessFilePath, err => { | ||
if(err) { | ||
textfile.read(path.join(__dirname, 'template.less'), 'string', str => { | ||
str = str.replace('template', pageName) | ||
textfile.write(lessFilePath, str, 'string', (err, filePath) => { | ||
if(err) { | ||
cb(err) | ||
} else { | ||
end('less', filePath) | ||
} | ||
}) | ||
}) | ||
} else { | ||
end('less', lessFilePath) | ||
} | ||
}) | ||
textfile.read(path.join(__dirname, 'template.ui'), 'string', str => { | ||
str = str.replace('template', pageName) | ||
textfile.write(path.join(pagePath, pageName + '.ui'), str, 'string', (err, filePath) => { | ||
if(err) { | ||
cb(err) | ||
} else { | ||
end('ui', filePath) | ||
} | ||
}) | ||
// 创建ui文件 | ||
var uiFilePath = path.join(pagePath, pageName + '.ui') | ||
fs.access(uiFilePath, err => { | ||
if(err) { | ||
textfile.read(path.join(__dirname, 'template.ui'), 'string', str => { | ||
str = str.replace('template', pageName) | ||
textfile.write(uiFilePath, str, 'string', (err, filePath) => { | ||
if(err) { | ||
cb(err) | ||
} else { | ||
end('ui', filePath) | ||
} | ||
}) | ||
}) | ||
} else { | ||
end('ui', uiFilePath) | ||
} | ||
}) | ||
// 更新app.json | ||
textfile.read(path.join(workSpace, 'app.json'), 'json', data => { | ||
@@ -89,27 +122,32 @@ var pages | ||
} | ||
fs.mkdir(pagePath, (err) => { | ||
if(err) { | ||
if(err.code === 'EEXIST') { | ||
fs.readdir(pagePath, (err, files) => { | ||
if(err) { | ||
cb(err) | ||
} else { | ||
if(!files || !files.length) { | ||
write() | ||
if(mkdir) { | ||
fs.mkdir(pagePath, (err) => { | ||
if(err) { | ||
if(err.code === 'EEXIST') { | ||
fs.readdir(pagePath, (err, files) => { | ||
if(err) { | ||
cb(err) | ||
} else { | ||
cb({ | ||
message: 'file exist' | ||
}) | ||
if(!files || !files.length) { | ||
write() | ||
} else { | ||
cb({ | ||
message: 'file exist' | ||
}) | ||
} | ||
} | ||
} | ||
}) | ||
}) | ||
} else { | ||
cb(err) | ||
} | ||
} else { | ||
cb(err) | ||
write() | ||
} | ||
} else { | ||
write() | ||
} | ||
}) | ||
}) | ||
} else { | ||
write() | ||
} | ||
} | ||
} | ||
module.exports = page.create |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6581
169