Best JavaScript code snippet using fast-check-monorepo
base-node-script.js
Source:base-node-script.js
1globalThis.fs = require('fs');2globalThis.path = require('path');3globalThis.https = require('https');4globalThis.http = require('http');5globalThis.BASE_WINDOW = '/mnt/c/Users';6globalThis.BASE_HOMEDIR_LINUX = require('os').homedir();7globalThis.BASE_BASH_SYLE = path.join(BASE_HOMEDIR_LINUX, '.bash_syle');8/**9 * config used for the editors10 * @type {Object}11 *if you need to override these with your local settings, use the following12 export FONT_SIZE=15;13 export FONT_FAMILY='Fira Code'14 export TAB_SIZE=215 */16let fontSize = parseInt(process.env.FONT_SIZE);17if (!fontSize || fontSize <= 10) {18 fontSize = 10;19}20const fontFamily = process.env.FONT_FAMILY || 'Fira Code';21let tabSize = parseInt(process.env.TAB_SIZE);22if (!tabSize || tabSize <= 2) {23 tabSize = 2;24}25globalThis.EDITOR_CONFIGS = {26 fontSize,27 fontFamily,28 tabSize,29 maxLineSize: 140,30 ignoredFiles: [31 '*.rej',32 '*.class',33 '*.db',34 '*.dll',35 '*.doc',36 '*.docx',37 '*.dylib',38 '*.exe',39 '*.idb',40 '*.jar',41 '*.js.map',42 '*.lib',43 '*.min.js',44 '*.mp3',45 '*.ncb',46 '*.o',47 '*.obj',48 '*.ogg',49 '*.pdb',50 '*.pdf',51 '*.pid',52 '*.pid.lock',53 '*.psd',54 '*.pyc',55 '*.pyo',56 '*.sdf',57 '*.seed',58 '*.sln',59 '*.so',60 '*.sqlite',61 '*.suo',62 '*.swf',63 '*.swp',64 '*.woff',65 '*.woff2',66 '*.zip',67 '.DS_Store',68 '.eslintcache',69 'yarn.lock',70 'package-lock.json',71 ],72 ignoredFolders: [73 '.cache',74 '.ebextensions',75 '.generated',76 '.git',77 '.gradle',78 '.hg',79 '.idea',80 '.sass-cache',81 '.svn',82 'bower_components',83 'build',84 'CVS',85 'dist',86 'node_modules',87 'tmp',88 'webpack-dist',89 ],90};91/**92 * The host config is located here:93 * host name => host ip94 * @type {Array}95 */96globalThis.HOME_HOST_NAMES = [];97// os flags98Object.keys(process.env)99 .filter((envKey) => envKey.indexOf('is_os_') === 0)100 .forEach((envKey) => (globalThis[envKey] = parseInt(process.env[envKey] || '0') > 0));101// setting up the path for the extra tweaks102globalThis.BASE_SY_CUSTOM_TWEAKS_DIR =103 is_os_window === true ? path.join(getWindowUserBaseDir(), '...sy', '_extra') : path.join(globalThis.BASE_HOMEDIR_LINUX, '_extra');104globalThis.DEBUG_WRITE_TO_DIR = (process.env.DEBUG_WRITE_TO_DIR || '').toLowerCase().trim();105const repoName = 'synle/bashrc';106const repoBranch = 'master';107globalThis.REPO_PREFIX_URL = `https://raw.githubusercontent.com/${repoName}/${repoBranch}/`;108const isTestScriptMode = parseInt(process.env.TEST_SCRIPT_MODE) === 1;109//////////////////////////////////////////////////////110// begin common111function _getFilePath(aDir) {112 let pathToUse = aDir;113 if (globalThis.DEBUG_WRITE_TO_DIR.length > 0) {114 const fileName = aDir115 .replace(/[\/\\\(\)]/g, '_')116 .replace(/ /g, '_')117 .replace(/_\./g, '.')118 .replace(/__+/g, '_');119 pathToUse = path.join(globalThis.DEBUG_WRITE_TO_DIR, fileName);120 console.log('<< Debug File Path: ', pathToUse);121 }122 return pathToUse;123}124function findDirList(srcDir, targetMatch, returnFirstMatch) {125 try {126 const dirFiles = fs127 .readdirSync(srcDir, {128 withFileTypes: true,129 })130 .filter((dirent) => dirent.isDirectory())131 .map((dirent) => dirent.name)132 .filter((d) => d.match(targetMatch))133 .map((d) => path.join(srcDir, d));134 if (returnFirstMatch) {135 return dirFiles[0];136 }137 return dirFiles;138 } catch (err) {139 if (returnFirstMatch) {140 return null;141 }142 return [];143 }144}145function findDirSingle(srcDir, targetMatch) {146 return findDirList(srcDir, targetMatch, true);147}148/**149 * find and return the first dir that matches the prop150 * @param {array} findProps must contains "src" and "match"151 * @return {string} the path of the first dir and undefined otherwise152 */153function findFirstDirFromList(findProps) {154 for (const findProp of findProps) {155 const [src, match] = findProp;156 const matchedDir = findDirSingle(src, match);157 if (matchedDir) {158 return matchedDir;159 }160 }161 return undefined;162}163function writeText(aDir, text, override = true, suppressError = false) {164 const pathToUse = _getFilePath(aDir);165 const newContent = text;166 const oldContent = readText(pathToUse);167 if (oldContent.trim() === newContent.trim() || override !== true) {168 // if content don't change, then don't save169 // if override is set to false, then don't override170 if (suppressError !== true) {171 console.log(consoleLogColor3(' << Skipped [NotModified]'), consoleLogColor4(pathToUse));172 }173 } else {174 fs.writeFileSync(pathToUse, newContent);175 }176}177function backupText(aDir, text) {178 const pathToUse = aDir;179 const oldText = readText(pathToUse);180 if (oldText !== text) {181 // back it up182 const backupPathToUse = pathToUse + '.' + Date.now();183 writeText(pathToUse, text);184 writeText(backupPathToUse, text);185 console.log(consoleLogColor3(' << Backup Created'), consoleLogColor4(backupPathToUse));186 } else {187 console.log(consoleLogColor3(' << Backup Skipped [NotModified]'), consoleLogColor4(pathToUse));188 }189}190function writeJson(aDir, json) {191 writeText(aDir, JSON.stringify(json, null, 2));192}193function appendText(aDir, text) {194 const oldText = readText(aDir);195 writeText(aDir, oldText + '\n' + text);196}197function replaceTextLineByLine(aDir, replacements, makeAdditionalBackup = false) {198 const oldText = readText(aDir);199 const newText = oldText200 .split('\n')201 .map((line) => {202 let newLine = line;203 for (const [matchRegex, replaceWith] of replacements) {204 newLine = newLine.replace(matchRegex, replaceWith);205 }206 return newLine;207 })208 .join('\n');209 // make backups210 writeText(`${aDir}.bak`, oldText, false);211 if (makeAdditionalBackup === true) {212 writeText(`${aDir}.bak.${Date.now()}`, oldText);213 }214 // save with newText215 writeText(aDir, newText);216}217function writeJsonWithMerge(aDir, json) {218 let oldJson = {};219 try {220 oldJson = readJson(aDir);221 } catch (e) {}222 writeJson(aDir, Object.assign(oldJson, json));223}224function readJson(aDir) {225 return parseJsonWithComments(fs.readFileSync(aDir, { encoding: 'utf8', flag: 'r' }));226}227function readText(aDir) {228 try {229 return fs.readFileSync(aDir, { encoding: 'utf8', flag: 'r' }).trim();230 } catch (err) {231 return '';232 }233}234function parseJsonWithComments(oldText) {235 oldText = (oldText || '').trim();236 if (!oldText) {237 process.exit();238 }239 return eval(`var ___temp = ${oldText}; ___temp;`);240}241function clone(obj) {242 return JSON.parse(JSON.stringify(obj));243}244function getWindowUserBaseDir() {245 return findDirSingle(BASE_WINDOW, /(leng)|(sy[ ]*le)/i);246}247/**248 * @param {String} applicationName Optional - the application name to be appended to the base path249 * if present, we will attempt to make a new directory there250 * @return {String} the full path to the application binary which can be used to install or download...251 */252async function getWindowsApplicationBinaryDir(applicationName) {253 let targetPath = findDirSingle('/mnt', /[d]/) || findDirSingle('/mnt', /[c]/);254 if (fs.existsSync(targetPath)) {255 // push this binary into d drive256 targetPath = path.join(targetPath, 'Applications');257 } else {258 // else use the extra folder259 targetPath = path.join(BASE_SY_CUSTOM_TWEAKS_DIR, 'windows');260 }261 if (applicationName) {262 targetPath = path.join(targetPath, applicationName);263 await mkdir(targetPath);264 }265 return targetPath;266}267/**268 * @return {String} the path for app roaming dir for windows269 */270function getWindowAppDataRoamingUserPath() {271 return path.join(getWindowUserBaseDir(), 'AppData/Roaming');272}273/**274 * @return {String} the path for app data local dir in windows275 */276function getWindowAppDataLocalUserPath() {277 return path.join(getWindowUserBaseDir(), 'AppData/Local');278}279function getOsxApplicationSupportCodeUserPath() {280 return path.join(process.env.HOME, 'Library/Application Support');281}282function updateTextBlock(resultTextContent, configKey, configValue, commentPrefix, isPrepend) {283 configValue = configValue.trim();284 const regex = new RegExp(`(\\n)*(${commentPrefix} ${configKey})(\\n)[\\S\\s]+(${commentPrefix} END ${configKey})(\\n)*`);285 if (resultTextContent.match(regex)) {286 resultTextContent = resultTextContent287 .replace(288 regex,289 `290${commentPrefix} ${configKey}291${configValue}292${commentPrefix} END ${configKey}293`,294 )295 .trim();296 } else if (isPrepend === false) {297 // append298 // this means it's not there, let's add it299 resultTextContent = `300${resultTextContent}301${commentPrefix} ${configKey}302${configValue}303${commentPrefix} END ${configKey}304`;305 } else {306 // prepend307 resultTextContent = `308${commentPrefix} ${configKey}309${configValue}310${commentPrefix} END ${configKey}311${resultTextContent}312`;313 }314 return cleanupExtraWhitespaces(resultTextContent);315}316function appendTextBlock(resultTextContent, configKey, configValue, commentPrefix = '#') {317 return updateTextBlock(resultTextContent, configKey, configValue, commentPrefix, false);318}319function prependTextBlock(resultTextContent, configKey, configValue, commentPrefix = '#') {320 return updateTextBlock(resultTextContent, configKey, configValue, commentPrefix, true);321}322function cleanupExtraWhitespaces(s) {323 return s.replace(/[\r\n][\r\n][\n]+/g, '\n\n').trim();324}325function convertTextToList(text) {326 return text327 .split('\n')328 .map((s) => s.trim())329 .filter((s) => !!s && !s.match(/^\s*\/\/\/*/) && !s.match(/^\s*#+/) && !s.match(/^\s*[*]+/));330}331function convertTextToHosts(text) {332 return text333 .split('\n')334 .map((s) => s.replace(/^[0-9]+.[0-9]+.[0-9]+.[0-9]+[ ]*/, '').trim())335 .filter((s) => s.length > 0 && s.match(/^[0-9a-zA-Z-.]+/) && s.match(/^[0-9a-zA-Z-.]+/)[0] === s);336}337function trimLeftSpaces(text, spaceToTrim) {338 try {339 const lines = text.split('\n');340 if (spaceToTrim === undefined) {341 // if not present, we will attempt to look at the space to trim automatically342 // look for the first non empty line343 const firstLine = lines.filter((line) => line.trim())[0];344 spaceToTrim = firstLine.match(/^[ ]+/g)[0].length;345 }346 return lines347 .map((line) => {348 let myLeftSpaces = 0;349 try {350 myLeftSpaces = line.match(/^[ ]+/g)[0].length;351 } catch (err) {}352 return line.substr(Math.min(spaceToTrim, myLeftSpaces));353 })354 .join('\n');355 } catch (err) {356 return text;357 }358}359function calculatePercentage(count, total) {360 return ((count * 100) / total).toFixed(2);361}362function getRootDomainFrom(url) {363 const lastDotIndex = url.lastIndexOf('.');364 const partialUrl = url.substr(0, lastDotIndex);365 const secondLastDotIdx = partialUrl.lastIndexOf('.') || 0;366 return url.substr(secondLastDotIdx + 1);367}368function mkdir(targetPath) {369 return execBashSilent(`mkdir -p "${targetPath}"`);370}371// api utils372function downloadFile(url, destination) {373 url = getFullUrl(url);374 return new Promise((resolve, reject) => {375 if (fs.existsSync(destination)) {376 console.log(consoleLogColor3(' << Skipped [NotModified]'), consoleLogColor4(destination));377 return resolve(false);378 }379 var file = fs.createWriteStream(destination);380 https381 .get(url, function (response) {382 response.pipe(file);383 file.on('finish', () => resolve(true));384 })385 .on('error', reject);386 });387}388async function downloadFilesFromMainRepo(findHandler, destinationBaseDir) {389 const files = await listRepoDir();390 const filesToDownload = files.filter((s) => s.includes('binaries/') && !s.toLowerCase().includes('.md')).filter(findHandler);391 const promises = [];392 for (const file of filesToDownload) {393 promises.push(394 new Promise(async (resolve) => {395 const destinationFile = path.join(destinationBaseDir, path.basename(file));396 try {397 const url = file;398 const downloaded = await downloadFile(url, destinationFile);399 if (downloaded === true) {400 console.log(consoleLogColor3(' >> Downloaded'), consoleLogColor4(destinationFile));401 }402 } catch (err) {403 console.log(consoleLogColor3(' >> Error Downloading'), consoleLogColor4(file));404 }405 resolve();406 }),407 );408 }409 return files;410}411async function listRepoDir() {412 const url = `https://api.github.com/repos/${repoName}/git/trees/${repoBranch}?recursive=1&cacheBust=${Date.now()}`;413 try {414 const json = await fetchUrlAsJson(url);415 return json.tree.map((file) => file.path);416 } catch (err) {417 console.log(' >> Error getting the file list');418 return [];419 }420}421async function getSoftwareScriptFiles(returnAllScripts = false, useLocalFileListInstead = false) {422 let files;423 if (useLocalFileListInstead === true || isTestScriptMode === true) {424 // fetch from exec bash425 files = (await execBash('find .')).split('\n').map((s) => s.replace('./software/scripts/', 'software/scripts/'));426 } else {427 // fetch from APIS428 files = await listRepoDir();429 }430 // clean up the files431 files = files432 .filter((f) => !!f.match('software/scripts/') && !f.endsWith('.config.js'))433 .filter((f) => {434 const EXTENSIONS_TO_USE = [`.js`, `.sh`];435 for (const extension of EXTENSIONS_TO_USE) {436 if (f.endsWith(extension)) {437 return true;438 }439 }440 return false;441 });442 //this is a special flags used to return all the script for index building443 if (returnAllScripts) {444 return files;445 }446 const firstFiles = convertTextToList(`447 software/scripts/_bash-rc-bootstrap.js448 software/scripts/_nvm-binary.js449 software/scripts/_nvm-symlink.sh.js450 `);451 // this is a list of file to do last452 // NOTE because the update ssh causes the change in host file453 // therefore it needs to be done last454 const lastFiles = convertTextToList(`455 software/scripts/bash-syle-content.js456 software/scripts/etc-hosts.su.js457 software/scripts/vs-code-extensions.sh.js458 `);459 if (is_os_window) {460 firstFiles.push('software/scripts/windows/mkdir.js');461 }462 let softwareFiles = files463 .filter(464 (f) => !!f.match('software/scripts/') && (f.includes('.js') || f.includes('.sh')) && !f.includes('config.js') && !f.includes('.json'),465 )466 .filter((f) => firstFiles.indexOf(f) === -1 && lastFiles.indexOf(f) === -1)467 .sort();468 softwareFiles = [...new Set([...firstFiles, ...softwareFiles, ...lastFiles])];469 return softwareFiles.filter((file) => {470 const scriptFinderConfigs = [471 {472 key: 'is_os_arch_linux',473 allowed_path: 'software/scripts/arch-linux',474 whitelist: `475 // common476 software/scripts/_bash-rc-bootstrap.js477 software/scripts/git.js478 software/scripts/vim-configurations.js479 software/scripts/vim-vundle.sh480 software/scripts/bash-inputrc.js481 software/scripts/bash-syle-content.js482 software/scripts/bash-autocomplete.js483 // specifics484 software/scripts/fonts.js485 software/scripts/_nvm-binary.js486 software/scripts/_nvm-symlink.sh.js487 software/scripts/kde-konsole-profile.js488 software/scripts/diff-so-fancy.sh489 software/scripts/sublime-text-configurations.js490 software/scripts/sublime-text-keybindings.js491 `,492 },493 {494 key: 'is_os_android_termux',495 allowed_path: 'software/scripts/android-termux',496 whitelist: `497 software/scripts/vim-configurations.js498 software/scripts/vim-vundle.sh499 software/scripts/tmux.js500 `,501 },502 {503 key: 'is_os_chromeos',504 allowed_path: 'software/scripts/chrome-os',505 whitelist: `506 // common507 software/scripts/_bash-rc-bootstrap.js508 software/scripts/git.js509 software/scripts/vim-configurations.js510 software/scripts/vim-vundle.sh511 software/scripts/bash-inputrc.js512 software/scripts/bash-syle-content.js513 software/scripts/bash-autocomplete.js514 // specifics515 software/scripts/tmux.js516 software/scripts/sublime-text-configurations.js517 software/scripts/sublime-text-keybindings.js518 `,519 },520 ];521 const pathsToIgnore = [522 [is_os_arch_linux, 'software/scripts/arch-linux'],523 [is_os_android_termux, 'software/scripts/android-termux'],524 [is_os_window, 'software/scripts/windows'],525 [is_os_darwin_mac, 'software/scripts/mac'],526 ]527 .map(([valid, pathToCheck]) => (!valid ? pathToCheck : ''))528 .filter((s) => !!s);529 for (const scriptFinderConfig of scriptFinderConfigs) {530 const isscriptFinderConfigApplicable = global[scriptFinderConfig.key];531 if (isscriptFinderConfigApplicable) {532 // it'sone of the configs, we should use it533 if (file.includes(scriptFinderConfig.allowed_path)) {534 return true;535 }536 // when run in an android termux env, only run script in that folder537 const whitelistedScripts = convertTextToList(scriptFinderConfig.whitelist);538 if (whitelistedScripts.indexOf(file) >= 0) {539 return true;540 }541 return false;542 }543 }544 // handle it differently545 for (const pathToIgnore of pathsToIgnore) {546 if (file.includes(pathToIgnore)) {547 return false;548 }549 }550 return true;551 });552}553function getFullUrl(url) {554 if (url.indexOf('http') !== 0) {555 url = `${REPO_PREFIX_URL}${url}`;556 }557 return url;558}559async function fetchUrlAsString(url) {560 if (isTestScriptMode && !url.includes('http')) {561 const file = url;562 return execBash(`cat ${file}`);563 }564 // fetch as real url565 try {566 url = getFullUrl(url);567 return execBash(`curl -s ${url}`);568 } catch (err) {569 return new Promise((resolve) => {570 require('https').get(url, (res) => {571 let rawData = '';572 res.on('data', (chunk) => (rawData += chunk)).on('end', () => resolve(rawData));573 });574 });575 }576}577function gitClone(repo, pwd) {578 return execBashSilent(`git clone --depth 1 -b master "${repo}" "${pwd}" &>/dev/null`);579}580async function fetchUrlAsJson(url) {581 const json = await fetchUrlAsString(url);582 return parseJsonWithComments(json);583}584function execBash(cmd, options) {585 return new Promise((resolve) => {586 const { execSync } = require('child_process');587 const stdout = execSync(cmd, {588 ...(options || {}),589 encoding: 'utf8',590 maxBuffer: 50 * 1024 * 1024,591 }).toString();592 resolve(stdout);593 });594}595function execBashSilent(cmd, options) {596 return new Promise((resolve) => {597 const { exec } = require('child_process');598 options = options || {};599 exec(cmd, options || {}, (error, stdout, stderr) => {600 resolve(stdout);601 });602 });603}604// console print and colors605const CONSOLE_COLORS = [606 null, // 0 index is not used607 '32m', // green608 '33m', // yellow609 '36m', // cyan610 '2m', // dim silver611];612function echo(str) {613 return `echo '''${str}'''`;614}615function echoColor(str, color) {616 return `echo -e $'\\e[${color}${str}\\e[m'`;617}618function consoleLogColor(str, color) {619 return `\x1b[${color}${str}\x1b[0m`;620}621for (let idx = 0; idx < CONSOLE_COLORS.length; idx++) {622 const color = CONSOLE_COLORS[idx];623 if (color) {624 global['echoColor' + idx] = (str) => echoColor(str, color);625 global['consoleLogColor' + idx] = (str) => consoleLogColor(str, color);626 }627}628// script utils629function processScriptFile(file) {630 let scriptToUse;631 const url = getFullUrl(`${file}?${Date.now()}`);632 function _generateScript(file, url) {633 if (file.includes('.js')) {634 return `${_generateStartScript()} && ${_generateRawScript(file, url)}`;635 }636 return `${_generateRawScript(file, url)}`;637 }638 function _generateRawScript(file, url) {639 if (isTestScriptMode) {640 return `cat ${file}`;641 }642 return `curl -s ${url}`;643 }644 function _generateStartScript() {645 const startScriptFilePath = 'software/base-node-script.js';646 const startScriptUrl = getFullUrl(`${startScriptFilePath}?${Date.now()}`);647 return _generateRawScript(startScriptFilePath, startScriptUrl);648 }649 function _generatePipeOutput(file, url) {650 if (file.includes('.su.sh.js')) {651 return `node | bash`;652 }653 if (file.includes('.su.js')) {654 return `sudo -E node`; // -E means preserve the env variable655 }656 if (file.includes('.sh.js')) {657 return `node | bash`;658 }659 if (file.includes('.js')) {660 return `node`;661 }662 if (file.includes('.su.sh')) {663 return `sudo -E bash`; // -E means preserve the env variable664 }665 if (file.includes('.sh')) {666 return `bash`;667 }668 }669 scriptToUse = _generateScript(file, url);670 const pipeOutput = _generatePipeOutput(file, url);671 console.log(`{ ${scriptToUse} ;} | ${pipeOutput}`);672}673function printOsFlags() {674 if (process.env.SHOULD_PRINT_OS_FLAGS !== 'false') {675 console.log(`676 node -e """677 console.log(''.padStart(90, '='));678 console.log('>> OS Flags'.padEnd(88, ' '));679 console.log(''.padStart(90, '='));680 Object.keys(process.env)681 .filter(envKey => envKey.indexOf('is_os_') === 0)682 .forEach(envKey => console.log(envKey.padEnd(20, ' ') + ':', process.env[envKey] === '1' ? 'Yes': 'No'))683 console.log(''.padStart(90, '='));684 """685 `);686 }687}688//////////////////////////////////////////////////////689(async function () {690 // getting the ip address mapping691 try {692 globalThis.HOME_HOST_NAMES = await fetchUrlAsJson(`software/metadata/ip-address.config.hostnamesFlattened`);693 } catch (err) {694 globalThis.HOME_HOST_NAMES = [];695 }696 // create the sy tweak folder697 const pathsToCreateDir = [698 path.join(globalThis.BASE_SY_CUSTOM_TWEAKS_DIR, 'mac'),699 path.join(globalThis.BASE_SY_CUSTOM_TWEAKS_DIR, 'windows'),700 ];701 for (const aPath of pathsToCreateDir) {702 try {703 await mkdir(aPath);704 } catch (err) {}705 }706 // for debugging707 if (process.env.DEBUG) {708 process709 .on('unhandledRejection', (reason, p) => {710 console.error(reason, 'Unhandled Rejection at Promise', p);711 })712 .on('uncaughtException', (err) => {713 console.error(err, 'Uncaught Exception thrown');714 process.exit(1);715 });716 }717 // start script718 try {719 doInit && (await doInit());720 } catch (err) {}721 try {722 doWork && (await doWork());723 } catch (err) {724 console.log('<< Error', err);725 }...
sublime-text-keybindings.js
Source:sublime-text-keybindings.js
1async function _getPathSublimeText() {2 try {3 if (is_os_window) {4 return findDirSingle(getWindowAppDataRoamingUserPath(), /Sublime[ ]*Text/i);5 }6 if (is_os_darwin_mac) {7 return findDirSingle(getOsxApplicationSupportCodeUserPath(), /Sublime[ ]*Text/i);8 }9 if (is_os_arch_linux) {10 // for sublime installed using Discover in arch linux11 return path.join(process.env.HOME, '.var/app/com.sublimetext.three/config/sublime-text-3');12 }13 // for debian or chrome os debian linux14 return findDirSingle(globalThis.BASE_HOMEDIR_LINUX + '/.config', /Sublime[ ]*Text/i);15 } catch (err) {16 console.log(' >> Failed to get the path for Sublime Text', url, err);17 }18 return null;19}20let OS_KEY;21let COMMON_KEY_BINDINGS;22let WINDOWS_ONLY_KEY_BINDINGS;23let MAC_ONLY_KEY_BINDINGS;24const WINDOWS_OS_KEY = 'alt'; // alt for modern mode25const MAC_OSX_KEY = 'super';26const LINUX_OS_KEY = 'alt';27function _formatKey(keybindings, osKeyToUse) {28 osKeyToUse = osKeyToUse || OS_KEY;29 keybindings = clone(keybindings);30 for (const keybinding of keybindings) {31 keybinding.keys = []32 .concat(keybinding.keys || [])33 .concat(keybinding.key || [])34 .map((s) => s.replace('OS_KEY', osKeyToUse));35 delete keybinding.key;36 }37 return keybindings;38}39async function doInit() {40 if (is_os_darwin_mac) {41 OS_KEY = MAC_OSX_KEY;42 } else if (is_os_window) {43 OS_KEY = WINDOWS_OS_KEY;44 } else {45 OS_KEY = LINUX_OS_KEY;46 }47 WINDOWS_ONLY_KEY_BINDINGS = parseJsonWithComments(await fetchUrlAsString('software/scripts/sublime-text-keybindings.windows.json')) || [];48 LINUX_ONLY_KEYBINDING = parseJsonWithComments(await fetchUrlAsString('software/scripts/sublime-text-keybindings.linux.json')) || [];49 MAC_ONLY_KEY_BINDINGS = parseJsonWithComments(await fetchUrlAsString('software/scripts/sublime-text-keybindings.mac.json')) || [];50 // begin COMMON_KEY_BINDINGS51 COMMON_KEY_BINDINGS = [52 { keys: ['OS_KEY+shift+;'], command: 'alignment' },53 {54 key: 'f5',55 command: 'refresh_folder_list',56 },57 {58 key: 'OS_KEY+r',59 command: 'show_overlay',60 args: {61 overlay: 'goto',62 text: '@',63 },64 },65 {66 key: 'OS_KEY+;',67 command: 'show_overlay',68 args: {69 overlay: 'goto',70 text: ':',71 },72 },73 {74 key: 'OS_KEY+m',75 command: 'move_to',76 args: { to: 'brackets' },77 },78 {79 key: 'OS_KEY+o',80 command: 'prompt_open_file',81 },82 {83 key: 'OS_KEY+\\',84 command: 'toggle_side_bar',85 },86 {87 key: 'OS_KEY+enter',88 command: 'goto_definition',89 },90 {91 key: 'shift+enter',92 command: 'quick_goto_variable',93 },94 {95 key: 'OS_KEY+t',96 command: 'new_file',97 },98 {99 key: 'OS_KEY+shift+k',100 command: 'find_all_under',101 },102 { keys: ['OS_KEY+h'], command: 'show_panel', args: { panel: 'replace', reverse: false } },103 {104 key: 'OS_KEY+f',105 command: 'show_panel',106 args: {107 panel: 'find',108 reverse: false,109 },110 },111 {112 key: 'OS_KEY+shift+f',113 command: 'show_panel',114 args: {115 panel: 'find_in_files',116 },117 },118 // splits119 // split navigation120 // { key: "OS_KEY+ctrl+left", command: "focus_neighboring_group" },121 // { key: "OS_KEY+ctrl+right", command: "focus_neighboring_group" },122 // { key: "OS_KEY+ctrl+up", command: "focus_neighboring_group" },123 // { key: "OS_KEY+ctrl+down", command: "focus_neighboring_group" },124 // {125 // key: ['OS_KEY+b', 'OS_KEY+w'],126 // command: 'set_layout',127 // args: {128 // cols: [0.0, 1.0],129 // rows: [0.0, 1.0],130 // cells: [[0, 0, 1, 1]],131 // },132 // },133 // {134 // key: ['OS_KEY+b', 'OS_KEY+'],135 // command: 'set_layout',136 // args: {137 // cols: [0.0, 0.5, 1.0],138 // rows: [0.0, 1.0],139 // cells: [140 // [0, 0, 1, 1],141 // [1, 0, 2, 1],142 // ],143 // },144 // },145 // {146 // key: ['OS_KEY+b', "OS_KEY+'"],147 // command: 'set_layout',148 // args: {149 // cols: [0.0, 1.0],150 // rows: [0.0, 0.5, 1.0],151 // cells: [152 // [0, 0, 1, 1],153 // [0, 1, 1, 2],154 // ],155 // },156 // },157 { key: ['OS_KEY+1'], command: 'select_by_index', args: { index: 0 } },158 { key: ['OS_KEY+2'], command: 'select_by_index', args: { index: 1 } },159 { key: ['OS_KEY+3'], command: 'select_by_index', args: { index: 2 } },160 { key: ['OS_KEY+4'], command: 'select_by_index', args: { index: 3 } },161 { key: ['OS_KEY+5'], command: 'select_by_index', args: { index: 4 } },162 { key: ['OS_KEY+6'], command: 'select_by_index', args: { index: 5 } },163 { key: ['OS_KEY+7'], command: 'select_by_index', args: { index: 6 } },164 { key: ['OS_KEY+8'], command: 'select_by_index', args: { index: 7 } },165 { key: ['OS_KEY+9'], command: 'select_by_index', args: { index: 8 } },166 ];167 // end COMMON_KEY_BINDINGS168}169async function doWork() {170 let targetPath = await _getPathSublimeText();171 console.log(` >> Setting up Sublime Text Keybindings:`, consoleLogColor4(targetPath));172 if (DEBUG_WRITE_TO_DIR) {173 console.log(consoleLogColor1(' >> DEBUG Mode: write to file'));174 // non -mac keybinding175 writeJson('sublime-text-keybindings-windows', _formatKey([...COMMON_KEY_BINDINGS, ...WINDOWS_ONLY_KEY_BINDINGS], WINDOWS_OS_KEY));176 writeJson('sublime-text-keybindings-linux', _formatKey([...COMMON_KEY_BINDINGS, ...LINUX_ONLY_KEYBINDING], LINUX_OS_KEY));177 writeJson('sublime-text-keybindings-macosx', _formatKey([...COMMON_KEY_BINDINGS, ...MAC_ONLY_KEY_BINDINGS], MAC_OSX_KEY));178 return process.exit();179 }180 if (!fs.existsSync(targetPath)) {181 console.log(consoleLogColor1(' >> Skipped : Not Found'));182 return process.exit();183 }184 // windows only key bindings185 const winKeymapPath = path.join(targetPath, 'Packages/User/Default (Windows).sublime-keymap');186 console.log(' >> Windows', winKeymapPath);187 writeJson(winKeymapPath, _formatKey([...COMMON_KEY_BINDINGS, ...WINDOWS_ONLY_KEY_BINDINGS]));188 // linux only key bindings189 const linuxKeymapPath = path.join(targetPath, 'Packages/User/Default (Linux).sublime-keymap');190 console.log(' >> Linux', linuxKeymapPath);191 writeJson(linuxKeymapPath, _formatKey([...COMMON_KEY_BINDINGS, ...LINUX_ONLY_KEYBINDING]));192 // mac only key bindings193 const osxKeymapPath = path.join(targetPath, 'Packages/User/Default (OSX).sublime-keymap');194 console.log(' >> OSX', osxKeymapPath);195 writeJson(osxKeymapPath, _formatKey([...COMMON_KEY_BINDINGS, ...MAC_ONLY_KEY_BINDINGS]));...
script-list.config.js
Source:script-list.config.js
1async function doWork() {2 const softwareFiles = (await getSoftwareScriptFiles(true, true)).sort();3 const files = [];4 for (let i = 0; i < softwareFiles.length; i++) {5 let file = softwareFiles[i];6 // add the prefix if needed7 if (!file.includes('software/scripts/')) {8 file = `software/scripts/${file}`;9 }10 if (!file.match(/\.json/) && !file.match(/\.config/)) {11 files.push(file);12 }13 }14 const targetPath = process.env.SCRIPT_INDEX_CONFIG_FILE || './software/metadata/script-list.config';15 writeText(targetPath, files.join('\n'));...
Using AI Code Generation
1const { j } = require('fast-check');2console.log(j);3const { j } = require('fast-check');4console.log(j);5const { j } = require('fast-check');6console.log(j);7const { j } = require('fast-check');8console.log(j);9const { j } = require('fast-check');10console.log(j);11const { j } = require('fast-check');12console.log(j);13const { j } = require('fast-check');14console.log(j);15const { j } = require('fast-check');16console.log(j);17const { j } = require('fast-check');18console.log(j);19const { j } = require('fast-check');20console.log(j);21const { j } = require('fast-check');22console.log(j);23const { j } = require('fast-check');24console.log(j);25const { j } = require('fast-check');26console.log(j);27const { j } = require('fast-check');28console.log(j);29const { j } = require('fast-check');30console.log(j);
Using AI Code Generation
1const j = require('fast-check');2console.log(j);3const j = require('fast-check');4console.log(j);5const j = require('fast-check');6console.log(j);7const j = require('fast-check');8console.log(j);9const j = require('fast-check');10console.log(j);11const j = require('fast-check');12console.log(j);13const j = require('fast-check');14console.log(j);15const j = require('fast-check');16console.log(j);17const j = require('fast-check');18console.log(j);19const j = require('fast-check');20console.log(j);21const j = require('fast-check');22console.log(j);23const j = require('fast-check');24console.log(j);25const j = require('fast-check');26console.log(j);27const j = require('fast-check');28console.log(j);29const j = require('fast-check');30console.log(j);31const j = require('fast-check');32console.log(j);
Using AI Code Generation
1const j = require('fast-check-monorepo/j');2console.log(j(3));3const j = require('fast-check-monorepo/j');4console.log(j(4));5const j = require('fast-check-monorepo/j');6console.log(j(5));7const j = require('fast-check-monorepo/j');8console.log(j(6));9const j = require('fast-check-monorepo/j');10console.log(j(7));11const j = require('fast-check-monorepo/j');12console.log(j(8));13const j = require('fast-check-monorepo/j');14console.log(j(9));15const j = require('fast-check-monorepo/j');16console.log(j(10));17const j = require('fast-check-monorepo/j');18console.log(j(11));19const j = require('fast-check-monorepo/j');20console.log(j(12));21const j = require('fast-check-monorepo/j');22console.log(j(13));23const j = require('fast-check-monorepo/j');24console.log(j(14));25const j = require('fast-check-monorepo/j');26console.log(j(15));
Using AI Code Generation
1const j = require('fast-check-monorepo');2console.log(j(10));3const j = require('fast-check-monorepo');4console.log(j(10));5const j = require('fast-check-monorepo');6console.log(j(10));7const j = require('fast-check-monorepo');8console.log(j(10));9const j = require('fast-check-monorepo');10console.log(j(10));11const j = require('fast-check-monorepo');12console.log(j(10));13const j = require('fast-check-monorepo');14console.log(j(10));15const j = require('fast-check-monorepo');16console.log(j(10));17const j = require('fast-check-monorepo');18console.log(j(10));19const j = require('fast-check-monorepo');20console.log(j(10));21const j = require('fast-check-monorepo');22console.log(j(10));23const j = require('fast-check-monorepo');24console.log(j(10));25const j = require('fast-check-monorepo');26console.log(j(10));27const j = require('fast-check-monorepo');28console.log(j(10));
Using AI Code Generation
1const j = require('fast-check-monorepo').j;2const fc = require('fast-check');3const assert = require('assert');4fc.assert(5 fc.property(fc.integer(), fc.integer(), (a, b) => {6 const sum = j(a, b);7 assert(sum === a + b);8 })9);10const j = require('fast-check-monorepo').j;11const fc = require('fast-check');12const assert = require('assert');13fc.assert(14 fc.property(fc.integer(), fc.integer(), (a, b) => {15 const sum = j(a, b);16 assert(sum === a + b);17 })18);19const j = require('fast-check-monorepo').j;20const fc = require('fast-check');21const assert = require('assert');22fc.assert(23 fc.property(fc.integer(), fc.integer(), (a, b) => {24 const sum = j(a, b);25 assert(sum === a + b);26 })27);28const j = require('fast-check-monorepo').j;29const fc = require('fast-check');30const assert = require('assert');31fc.assert(32 fc.property(fc.integer(), fc.integer(), (a, b) => {33 const sum = j(a, b);34 assert(sum === a + b);35 })36);37const j = require('fast-check-monorepo').j;38const fc = require('fast-check');39const assert = require('assert');40fc.assert(41 fc.property(fc.integer(), fc.integer(), (a, b) => {42 const sum = j(a, b);43 assert(sum === a + b);44 })45);46const j = require('fast-check-monorepo').j;47const fc = require('fast-check');48const assert = require('assert');49fc.assert(50 fc.property(fc.integer(), fc.integer(), (a, b) => {
Using AI Code Generation
1const j = require('fast-check').j;2console.log(j(1, 2, 3));3const j = require('fast-check').j;4console.log(j(1, 2, 3));5const j = require('fast-check').j;6console.log(j(1, 2, 3));7const j = require('fast-check').j;8console.log(j(1, 2, 3));9const j = require('fast-check').j;10console.log(j(1, 2, 3));11const j = require('fast-check').j;12console.log(j(1, 2, 3));13const j = require('fast-check').j;14console.log(j(1, 2, 3));15const j = require('fast-check').j;16console.log(j(1, 2, 3));17const j = require('fast-check').j;18console.log(j(1, 2, 3));19const j = require('fast-check').j;20console.log(j(1, 2, 3));21const j = require('fast-check').j;22console.log(j(1, 2, 3));23const j = require('fast-check').j;24console.log(j(1, 2, 3));
Using AI Code Generation
1const j = require('fast-check-monorepo/j');2const jResult = j(1, 2);3console.log(jResult);4const k = require('fast-check-monorepo/k');5const kResult = k(1, 2);6console.log(kResult);7const l = require('fast-check-monorepo/l');8const lResult = l(1, 2);9console.log(lResult);10const m = require('fast-check-monorepo/m');11const mResult = m(1, 2);12console.log(mResult);13const n = require('fast-check-monorepo/n');14const nResult = n(1, 2);15console.log(nResult);16const o = require('fast-check-monorepo/o');17const oResult = o(1, 2);18console.log(oResult);19const p = require('fast-check-monorepo/p');20const pResult = p(1, 2);21console.log(pResult);22const q = require('fast-check-monorepo/q');23const qResult = q(1, 2);24console.log(qResult);25const r = require('fast-check-monorepo/r');26const rResult = r(1, 2);27console.log(rResult);28const s = require('fast-check-monorepo/s');29const sResult = s(1, 2);30console.log(sResult);31const t = require('fast-check-monorepo/t');32const tResult = t(
Using AI Code Generation
1const fc = require('fast-check');2const j = require('fast-check-monorepo').j;3const { tuple } = require('fast-check');4const { jsc } = require('jsverify');5const { assert } = require('chai');6describe('j', () => {7 it('should work', () => {8 fc.assert(9 fc.property(fc.integer(), fc.integer(), (a, b) => {10 assert.strictEqual(j(a, b), a + b);11 })12 );13 });14});15const fc = require('fast-check');16const jsc = require('fast-check-monorepo').jsc;17const { tuple } = require('fast-check');18const { jsc } = require('jsverify');19const { assert } = require('chai');20describe('jsc', () => {21 it('should work', () => {22 jsc.assert(23 jsc.forall(jsc.integer, jsc.integer, (a, b) => {24 return a + b === jsc.utils.sum(a, b);25 })26 );27 });28});29const fc = require('fast-check');30const jsc = require('jsverify');31const { tuple } = require('fast-check');32const { jsc } = require('jsverify');33const { assert } = require('chai');34describe('jsc', () => {35 it('should work', () => {36 jsc.assert(37 jsc.forall(jsc.integer, jsc.integer, (a, b) => {38 return a + b === jsc.utils.sum(a, b);39 })40 );41 });42});43const fc = require('fast-check');44const jsc = require('fast-check').jsc;45const { tuple } = require('fast-check');46const { jsc } = require('jsverify');47const { assert } = require('chai');48describe('jsc', () => {49 it('should work', ()
Using AI Code Generation
1const j = require('fast-check-monorepo/lib/jestCheck');2describe('test3', () => {3 j.it('test3', () => {4 j.assert(j.property(j.nat, (n) => n >= 0));5 });6});7const j = require('fast-check-monorepo/lib/jestCheck');8describe('test4', () => {9 j.it('test4', () => {10 j.assert(j.property(j.nat, (n) => n >= 0));11 });12});13const j = require('fast-check-monorepo/lib/jestCheck');14describe('test5', () => {15 j.it('test5', () => {16 j.assert(j.property(j.nat, (n) => n >= 0));17 });18});19const j = require('fast-check-monorepo/lib/jestCheck');20describe('test6', () => {21 j.it('test6', () => {22 j.assert(j.property(j.nat, (n) => n >= 0));23 });24});25const j = require('fast-check-monorepo/lib/jestCheck');26describe('test7', () => {27 j.it('test7', () => {28 j.assert(j.property(j.nat, (n) => n >= 0));29 });30});31const j = require('fast-check-monorepo/lib/jestCheck');32describe('test8', () => {33 j.it('test8', () => {34 j.assert(j.property(j.nat, (n) => n >= 0));35 });36});37const j = require('fast-check-monorepo/lib/jestCheck');38describe('test9', () => {39 j.it('test9', () => {40 j.assert(j.property(j.nat, (n) => n >= 0));41 });42});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!