Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function deleteFolderRecursive(filepath: string) {
if (fs.existsSync(filepath)) {
fs.readdirSync(filepath).forEach((file, index) => {
const curPath = pathJoin(filepath, file);
if (fs.lstatSync(curPath).isDirectory()) { // recurse
exports.deleteFolderRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(filepath);
}
}
describe('locales', function() {
const locales = path.resolve(__dirname, '../src/_locales');
const keys = [
'extName', 'extDescription', 'title', 'security', 'reload', 'failure'
];
fs.readdirSync(locales).forEach(locale => {
it(locale, function() {
const file = fs.readFileSync(path.resolve(locales, locale, 'messages.json'));
const json = JSON.parse(file);
keys.forEach(key => {
assert(typeof json[key].message === 'string');
});
});
});
});
const srcDir = path.join("..", "..", "src", packageName);
if (!fs.existsSync(srcDir)) {
console.error(`Error: Source directory ${srcDir} for package ${packageName} does not exist.`);
process.exit(1);
}
try {
const pkg = JSON.parse(fs.readFileSync("package.in.json", "utf8"));
const coreVersion = pkg["dependencies"]["quicktype-core"];
console.log(`Building ${packageName}, using quicktype-core ${coreVersion}`);
if (!fs.existsSync("src")) {
run("mkdir", ["src"]);
}
for (const fn of fs.readdirSync(srcDir).filter(fn => endsWith(fn, ".ts"))) {
const dstPath = path.join("src", fn);
copyFile(path.join(srcDir, fn), dstPath);
mapFile(dstPath, dstPath, content =>
replaceAll(content, '} from "../quicktype-core', '} from "quicktype-core')
);
}
copyFile(path.join(srcDir, "tsconfig.json"), "./");
writePackage(pkg, "file:../quicktype-core");
run("npm", ["install"]);
if (publish) {
writePackage(pkg, coreVersion);
run("npm", ["publish"]);
}
} catch (e) {
console.error(e);
const { readdirSync, readFileSync, writeFileSync } = require('fs')
const fm = require('front-matter')
const files = readdirSync('./_posts/')
async function main() {
let allSpeakers = []
for (let file in files) {
let speakerList
const split = files[file].split('.')
const fileEnding = split[split.length - 1]
if (fileEnding !== 'md') continue
const raw = readFileSync('./_posts/' + files[file], 'utf8')
const content = fm(raw)
if (typeof content.attributes.speakers !== 'undefined') {
console.log(content.attributes.speakers)
speakerList = {
src: files[file],
return getObjects(host, ssl).then(OBJECTS => {
const objs = fs.readdirSync(dir);
debug(`configs of these objects are found: ${objs}`);
const firstClassObjs = objs.filter(
obj => _.includes(OBJECTS, obj) && !_.includes(SON_OBJECTS, obj)
);
const secondClassObjs = objs.filter(
obj =>
(_.includes(OBJECTS, obj) && _.includes(SON_OBJECTS, obj)) ||
TARGET_REGEX.test(obj)
);
return Promise.map(firstClassObjs, core).then(() =>
Promise.map(secondClassObjs, core)
);
});
};
const enumR = (base) => {
const list = fs.readdirSync(base)
for (const f of list) {
if (f === '.' || f === '..') {continue}
const fullpath = path.join(base, f)
let st = null
try {
st = fs.statSync(fullpath)
} catch (e) {
st = null
}
if (st == null) {continue}
if (st.isDirectory()) {
enumR(fullpath)
continue
}
if (maskRE.test(f)) {result.push(fullpath)}
}
function LookupSaveRevisions( public_path, save_name ) {
var result = [ ];
var directoryName = helpers.JoinPath( "./documents/", public_path, save_name );
if ( helpers.IsDirectory( directoryName ) ) {
var potentialSaves = fs.readdirSync( directoryName.replace( /\//g, libpath.sep ) );
for ( var index = 0; index < potentialSaves.length; index++ ) {
if ( potentialSaves[ index ].match( /^saveState_\d+\.vwf\.json$/ ) ) {
result.push( parseInt( potentialSaves[ index ].slice( 10, potentialSaves[ index ].length - 9 ) ) );
}
}
}
return result;
}
function scanDir(folder, root, result) {
result = result || [];
if (!root) {
root = folder;
folder = '/';
}
const newRoot = path.join(root, folder);
const files = fs.readdirSync(newRoot);
files.forEach(f => {
const stat = fs.statSync(path.join(newRoot, f));
if (stat.isDirectory()) {
scanDir(path.join(folder, f), root, result);
} else if (f.match(/\.md$/)) {
result.push(path.join(folder, f).replace(/\\/g, '/'));
}
});
return result;
}
function getEntry() {
var jsDir = path.resolve(srcDir, 'dist/js');
var names = fs.readdirSync(jsDir);
var map = {};
names.forEach(function(name) {
var m = name.match(/(.+)\.js$/);
var entry = m ? m[1] : '';
var entryPath = entry ? path.resolve(jsDir, name) : '';
if (entry) map[entry] = entryPath;
});
//自定义额外加载包,不会合并在页面对应js中
map['lib'] = ['react'];
return map;
}
var pages = fs.readdirSync(srcDir);
pages.forEach(function(filename) {
var m = filename.match(/(.+)\.html$/);
if (m) {
var conf = {
template: path.resolve(srcDir, filename),
inject: true, //允许插件修改哪些内容,包括head与body
hash: true, //为静态资源生成hash值
minify: { //压缩HTML文件
removeComments: true, //移除HTML中的注释
collapseWhitespace: false //删除空白符与换行符
},
filename: filename
};
if (m[1] in config.entry) {
conf.chunks = ['vendors', m[1]];
constructor(path: string, parent?: FileSystemObject) {
super(path, parent);
this.items = FS
.readdirSync(this.path)
.map(path => {
let stats = FS.statSync(path);
if (stats.isFile()) {
return new FileObject(path, this);
} else {
return new FolderObject(path, this);
}
});
}
}