Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
resourceName = inputPath;
inputPath = '';
}
}
// console.log('argv.folder=' + argv.folder + ' inputPath=' + inputPath + ' resourceName=' + resourceName);
var folderPath = !argv.folder || argv.folder === '/' || !inputPath ? [] : inputPath.split(path.sep);
if (folderName) {
folderPath.push(folderName);
}
console.log(' - target folder: ' + (resourceFolder ? (resourceLabel + ' > ' + resourceName) : 'Documents') + ' > ' + folderPath.join(' > '));
var rootParentFolderLabel = resourceFolder ? resourceName : 'Home folder';
// get all files to upload
var folderContent = [];
dir.paths(srcPath, function (err, paths) {
if (err) {
console.log(err);
return reject();
} else {
// the top level folder
if (folderName) {
folderContent.push({
fileFolder: '',
files: []
});
}
// get all sub folders including empty ones
var subdirs = paths.dirs;
for (var i = 0; i < subdirs.length; i++) {
var subdir = subdirs[i];
subdir = subdir.substring(srcPath.length + 1);
compile(options, (err, result) => {
if (err) {
return fs.remove(options.publishPath, () => cb(err));
}
result.oc.date = "";
result.oc.files.template.version = "";
nodeDir.paths(options.publishPath, (err2, res2) => {
const files = _.chain(res2.files)
.map(filePath => {
const source = fs.readFileSync(filePath, "UTF8");
return {
source: !filePath.match(/\.png$/)
? source.replace(/"date":\d+/, "")
: "img-binary",
path: path.relative(__dirname, filePath)
};
})
.sortBy(["path", "source"])
.value();
fs.remove(options.publishPath, () => cb(err, { result, files }));
});
});
};
function recurse () {
if (i < 1) {
var endTime = moment()
var runTime = endTime.diff(startTime)
return nodeDir.paths(options.blobStoreRoot, (err, paths) => {
if (err) { return reject(err) }
var result = {
'blobStoreRoot': options.blobStoreRoot,
'idType': options.idType,
'dirDepth': options.dirDepth,
'dirWidth': options.dirWidth,
'runTimeMilliseconds': runTime,
'totalDirectories': paths.dirs.length,
'totalFiles': paths.files.length,
'totalBytes': readTotal
}
return resolve(result)
})
}
var readStream = crispyStream.createReadStream(input)
function checkIsBlock(dirPath, cb) {
var hasFiles, hasSubDirs, directAncestorFiles = [],
isBlock = false;
dir.paths(dirPath, function(err, paths) {
if (err) return cb(false);
hasFiles = paths.files.length > 0;
hasSubDirs = paths.dirs.length > 0;
if (hasFiles) {
if (!hasSubDirs) {
directAncestorFiles = paths.files;
} else {
directAncestorFiles = _.reduce(paths.files, function(result, file, key) {
var test = file.replace(dirPath + path.sep, '').split(path.sep);
if (test.length === 1) result.push(file);
return result;
}, []);
}
}
return new Promise(function (resolve, reject) {
dir.paths(srcPath, function (err, paths) {
if (err) {
console.log(err);
return resolve({
err: 'err'
});
} else {
try {
if (paths.files.length === 0 && paths.dirs.length === 0) {
console.log('ERROR: no file nor folder under ' + srcPath);
return resolve({
err: 'err'
});
}
var buildDir = serverUtils.getBuildFolder(projectDir);
if (!fs.existsSync(buildDir)) {
const copyDir = function(params, cb){
const staticPath = path.join(params.componentPath, params.staticDir),
exists = fs.existsSync(staticPath),
isDir = exists && fs.lstatSync(staticPath).isDirectory();
if(!exists){
return cb(format(strings.errors.cli.FOLDER_NOT_FOUND, staticPath));
} else if(!isDir){
return cb(format(strings.errors.cli.FOLDER_IS_NOT_A_FOLDER, staticPath));
} else {
nodeDir.paths(staticPath, (err, res) => {
_.forEach(res.files, (filePath) => {
const fileName = path.basename(filePath),
fileExt = path.extname(filePath).toLowerCase(),
fileRelativePath = path.relative(staticPath, path.dirname(filePath)),
fileDestinationPath = path.join(params.publishPath, params.staticDir, fileRelativePath),
fileDestination = path.join(fileDestinationPath, fileName);
fs.ensureDirSync(fileDestinationPath);
if(params.minify && params.ocOptions.minify !== false && (fileExt === '.js' || fileExt === '.css')){
const fileContent = fs.readFileSync(filePath).toString(),
minified = minifyFile(fileExt, fileContent);
fs.writeFileSync(fileDestination, minified);
} else {
const putDir = (dirInput, dirOutput, callback) => {
nodeDir.paths(dirInput, (err, paths) => {
async.each(
paths.files,
(file, cb) => {
const relativeFile = file.substr(dirInput.length),
url = (dirOutput + relativeFile).replace(/\\/g, '/');
putFile(file, url, relativeFile === '/server.js', cb);
},
callback
);
});
};
function copyDirectory(options, directoryName, callback) {
const directoryPath = path.join(options.componentPath, directoryName);
const directoryExists = fs.existsSync(directoryPath);
const isDirectory =
directoryExists && fs.lstatSync(directoryPath).isDirectory();
if (!directoryExists) {
return callback(strings.errors.folderNotFound(directoryPath));
}
if (!isDirectory) {
return callback(strings.errors.folderNotValid(directoryPath));
}
nodeDir.paths(directoryPath, (err, res) => {
_.forEach(res.files, filePath => {
const fileName = path.basename(filePath);
const fileExtension = path.extname(filePath).toLowerCase();
const fileRelativePath = path.relative(
directoryPath,
path.dirname(filePath)
);
const fileDestinationPath = path.join(
options.publishPath,
directoryName,
fileRelativePath
);
fs.ensureDirSync(fileDestinationPath);
const fileDestination = path.join(fileDestinationPath, fileName);
if (
options.minify &&
var onEachSource = function(source,onComplete){
if(!fs.lstatSync(source).isDirectory()){
allSources.push(source);
onComplete();
return;
}
dir.paths(source, function(err, paths) {
if (err) throw err;
for (var i = 0; i < paths.files.length; i++) {
allSources.push(paths.files[i]);
}
onComplete();
});
};