Best JavaScript code snippet using best
tw.mjs
Source:tw.mjs
1import path from 'path';2import fs from 'fs-extra';3import tw from 'tiddlywiki';4import UglifyJS from 'uglify-js';5import { minify as htmlMinify } from 'html-minifier-terser';6import { tryCopy, htmlMinifierOptions, shell } from './utils.mjs';7/** 项ç®è·¯å¾ */8const repoFolder = process.cwd();9const wikiFolder = path.join(repoFolder, 'wiki');10const tiddlersFolder = path.join(wikiFolder, 'tiddlers');11const publicFolder = path.join(repoFolder, 'public');12const runTiddlyWiki = (argv) => {13 shell(`npx tiddlywiki ${argv.join(' ')}`);14};15/**16 * æ建å¨çº¿HTMLçæ¬ï¼æ ¸å¿JSåèµæºæ件ä¸å
æ¬å¨HTMLä¸ï¼ ä¸è½½åä¸è½ä½¿ç¨17 * @param {string} distDir ç®æ è·¯å¾ï¼ç©ºæè
ä¸å¡«åé»è®¤ä¸º'dist'18 * @param {string} htmlName HTMLå称ï¼ç©ºæè
ä¸å¡«åé»è®¤ä¸º'index.html'19 * @param {boolean} minify æ¯å¦æå°åJSåHTMLï¼é»è®¤ä¸ºtrue20 * @param {string} excludeFilter è¦æé¤çtiddlerçè¿æ»¤è¡¨è¾¾å¼ï¼é»è®¤ä¸º'-[is[draft]]'21 */22export const buildOnlineHTML = async (distDir, htmlName, minify, excludeFilter) => {23 distDir = path.resolve(typeof distDir !== 'string' || distDir.length === 0 ? 'dist' : distDir);24 if (typeof htmlName !== 'string' || htmlName.length === 0) htmlName = 'index.html';25 minify = minify !== false;26 if (typeof excludeFilter !== 'string') excludeFilter = '-[is[draft]]';27 const $tw = tw.TiddlyWiki();28 $tw.boot.argv = ['.'];29 $tw.boot.boot();30 // éæèµæºæ·è´31 fs.mkdirsSync(distDir);32 fs.copySync(publicFolder, distDir, { overwrite: true });33 tryCopy(path.join(tiddlersFolder, 'favicon.ico'), path.join(distDir, 'favicon.ico'));34 tryCopy(path.join(tiddlersFolder, 'TiddlyWikiIconWhite.png'), path.join(distDir, 'TiddlyWikiIconWhite.png'));35 tryCopy(path.join(tiddlersFolder, 'TiddlyWikiIconBlack.png'), path.join(distDir, 'TiddlyWikiIconBlack.png'));36 // æ建HTML37 // å¤ä»½ å 为ä¸é¢ææ¹åtiddlerçfieldçæä½(åªä½æ件å
¨é¨è½¬ä¸ºcanonical)38 const backupFolder = path.join(wikiFolder, 'tmp_tiddlers_backup');39 fs.mkdirsSync(backupFolder);40 fs.copySync(tiddlersFolder, backupFolder, { overwrite: true });41 runTiddlyWiki([42 wikiFolder /* æå®wikiè·¯å¾ */,43 ...['--output', distDir] /* æå®è¾åºè·¯å¾ */,44 ...['--deletetiddlers', "'[[$:/UpgradeLibrary]] [[$:/UpgradeLibrary/List]]'"] /* å æä¸äºæ²¡å¿
è¦å¯¼åºèä¸å ç¨å¾å¤§çæ¡ç® */,45 ...[46 '--setfield',47 "'[is[image]] [is[binary]] [type[application/msword]] [type[image/svg+xml]]'",48 '_canonical_uri',49 '$:/core/templates/canonical-uri-external-image',50 'text/plain',51 ] /* åªä½æ¡ç®è½¬å¤é¾ */,52 ...[53 '--setfield',54 "'[is[image]] [is[binary]] [type[application/msword]] [type[image/svg+xml]]'",55 'text',56 "''",57 'text/plain',58 ] /* åªä½æ¡ç®å
容æ¸
空ï¼æ³¨æè¿ä¸æ¥ä¹ä¼æææåªä½æ件çå
容åæ空ç */,59 ...[60 '--rendertiddler',61 '$:/core/save/offline-external-js',62 'index-raw.html',63 'text/plain',64 "''",65 'publishFilter',66 `'${excludeFilter}'`,67 ] /* 导åºæ æ ¸å¿çHTMLæ件 */,68 ...['--rendertiddler', '$:/core/templates/tiddlywiki5.js', 'tiddlywikicore.js', 'text/plain'] /* 导åºæ ¸å¿ */,69 ]);70 // å°ææçäºè¿å¶æ件(åªä½æ件, åè$tw.utils.registerFileType)导åº71 const binaryExtensionMap = {};72 Object.keys($tw.config.fileExtensionInfo).forEach((ext) => {73 const _info = $tw.config.fileExtensionInfo[ext];74 const info = $tw.config.contentTypeInfo[_info.type];75 if (info && info.encoding === 'base64') binaryExtensionMap[ext.toLowerCase()] = true;76 });77 const distMediaFolder = path.join(distDir, 'images');78 fs.mkdirsSync(distMediaFolder);79 fs.copySync(backupFolder, distMediaFolder, {80 overwrite: true,81 filter: (src, _dest) => {82 if (src === backupFolder) return true;83 return binaryExtensionMap[path.extname(src).toLowerCase()] === true;84 },85 });86 // æ¢å¤è¢«æ¸
空å
容çåªä½æ件87 fs.copySync(backupFolder, tiddlersFolder, { overwrite: true });88 fs.rmSync(backupFolder, { recursive: true, force: true });89 // æå°åï¼æ ¸å¿JSåHTML90 const rawCoreJsPath = path.join(distDir, 'tiddlywikicore.js');91 const rawHTMLPath = path.join(distDir, 'index-raw.html');92 if (minify) {93 // æ ¸å¿94 let result = UglifyJS.minify(fs.readFileSync(rawCoreJsPath).toString('utf-8'), {95 warnings: false,96 v8: true,97 ie: true,98 webkit: true,99 });100 fs.writeFileSync(rawCoreJsPath, result.code);101 // ç½é¡µ102 result = await htmlMinify(fs.readFileSync(rawHTMLPath).toString('utf-8'), htmlMinifierOptions);103 fs.writeFileSync(rawHTMLPath, result);104 }105 fs.moveSync(rawCoreJsPath, path.join(distDir, `tiddlywikicore-${$tw.packageInfo.version}.js`), { overwrite: true });106 fs.moveSync(rawHTMLPath, path.join(distDir, htmlName), { overwrite: true });107};108/**109 * æ建离线HTMLçæ¬ï¼æ ¸å¿JSåèµæºæ件å
æ¬å¨HTMLä¸ï¼ ä¸è½½åå¯ä»¥ä½¿ç¨(å°±æ¯åæ件çæ¬çwiki)110 * @param {string} distDir ç®æ è·¯å¾ï¼ç©ºæè
ä¸å¡«åé»è®¤ä¸º'dist'111 * @param {string} htmlName HTMLå称ï¼ç©ºæè
ä¸å¡«åé»è®¤ä¸º'index.html'112 * @param {boolean} minify æ¯å¦æå°åJSåHTMLï¼é»è®¤ä¸ºtrue113 * @param {string} excludeFilter è¦æé¤çtiddlerçè¿æ»¤è¡¨è¾¾å¼ï¼é»è®¤ä¸º'-[is[draft]]'114 */115export const buildOfflineHTML = async (distDir, htmlName, minify, excludeFilter) => {116 distDir = path.resolve(typeof distDir !== 'string' || distDir.length === 0 ? 'dist' : distDir);117 if (typeof htmlName !== 'string' || htmlName.length === 0) htmlName = 'index.html';118 minify = minify !== false;119 if (typeof excludeFilter !== 'string') excludeFilter = '-[is[draft]]';120 // æ建HTML121 fs.mkdirsSync(distDir);122 runTiddlyWiki([123 wikiFolder /* æå®wikiè·¯å¾ */,124 ...['--output', distDir] /* æå®è¾åºè·¯å¾ */,125 ...['--deletetiddlers', "'[[$:/UpgradeLibrary]] [[$:/UpgradeLibrary/List]]'"] /* å æä¸äºæ²¡å¿
è¦å¯¼åºèä¸å ç¨å¾å¤§çæ¡ç® */,126 ...[127 '--rendertiddler',128 '$:/plugins/tiddlywiki/tiddlyweb/save/offline',129 'index-raw.html',130 'text/plain',131 "''",132 'publishFilter',133 `'${excludeFilter}'`,134 ] /* å°wiki导åºä¸ºHTML */,135 ]);136 // æå°åï¼HTML137 const rawHTMLPath = path.join(distDir, 'index-raw.html');138 if (minify) {139 const result = await htmlMinify(fs.readFileSync(rawHTMLPath).toString('utf-8'), htmlMinifierOptions);140 fs.writeFileSync(rawHTMLPath, result);141 }142 fs.moveSync(rawHTMLPath, path.join(distDir, htmlName), { overwrite: true });143};144/**145 * æ建æ件æº146 * @param {string} pluginFilter è¦åå¸æ件çè¿æ»¤å¨ï¼é»è®¤ä¸º '[prefix[$:/plugins/]!prefix[$:/plugins/tiddlywiki/]!prefix[$:/languages/]!prefix[$:/themes/tiddlywiki/]!tag[$:/tags/PluginLibrary]]'147 * @param {string} distDir ç®æ è·¯å¾ï¼ç©ºæè
ä¸å¡«åé»è®¤ä¸º'dist/library'148 * @param {boolean} minify æ¯å¦æå°åHTMLï¼é»è®¤ä¸ºtrue149 */150export const buildLibrary = async (pluginFilter, distDir, minify) => {151 if (typeof pluginFilter !== 'string' || pluginFilter.length === 0)152 pluginFilter = '[prefix[$:/plugins/]!prefix[$:/plugins/tiddlywiki/]!prefix[$:/languages/]!prefix[$:/themes/tiddlywiki/]!tag[$:/tags/PluginLibrary]]';153 distDir = path.resolve(typeof distDir !== 'string' || distDir.length === 0 ? 'dist/library' : distDir);154 minify = minify !== false;155 // æ建HTML156 fs.mkdirsSync(distDir);157 runTiddlyWiki([158 wikiFolder /* æå®wikiè·¯å¾ */,159 ...['--output', distDir] /* æå®è¾åºè·¯å¾ */,160 ...['--makelibrary', '$:/UpgradeLibrary'] /* æ¶éææå·²å®è£
æ件 */,161 ...['--savelibrarytiddlers', '$:/UpgradeLibrary', `'${pluginFilter}'`, 'recipes/library/tiddlers/', '$:/UpgradeLibrary/List'] /* 导åºæå®çæ件 */,162 ...['--savetiddler', '$:/UpgradeLibrary/List', 'recipes/library/tiddlers.json'] /* çææ件éåJSONæ件 */,163 ...['--rendertiddler', '$:/plugins/tiddlywiki/pluginlibrary/library.template.html', 'index-raw.html', 'text/plain'] /* çææ件åºHTMLæ件 */,164 ...['--deletetiddlers', "'[[$:/UpgradeLibrary]] [[$:/UpgradeLibrary/List]]'"] /* å æä¸é´å
容 */,165 ]);166 // æå°åï¼HTML167 const rawHTMLPath = path.join(distDir, 'index-raw.html');168 if (minify) {169 const result = await htmlMinify(fs.readFileSync(rawHTMLPath).toString('utf-8'), htmlMinifierOptions);170 fs.writeFileSync(rawHTMLPath, result);171 }172 fs.moveSync(rawHTMLPath, path.join(distDir, 'index.html'), { overwrite: true });...
build.js
Source:build.js
1const path = require('path');2const {3 execSync4} = require('child_process');5/** 项ç®è·¯å¾ */6const repoFolder = path.join(path.dirname(__filename), '..');7/** è·å¾TWçæ¬å· */8const getVersion = '$(npx tiddlywiki . --version | grep -Eo \'^[0-9]+\.[0-9]+\.[0-9]+.*$\' | head -n 1)';9/** 设置ç¯å¢åéï¼TWä¼åæ¶å¨èªå·±çæºç è·¯å¾ä»¥åç¯å¢åéå®ä¹çè·¯å¾ä¸å¯»æ¾æ件ã主é¢åè¯è¨10 * å¦æä¸è¿æ ·åï¼pluginsãthemesãlanguagesåeditionséçå
容就æ æ³è¢«å è½½11 */12process.env.TIDDLYWIKI_PLUGIN_PATH = `${repoFolder}/plugins`;13process.env.TIDDLYWIKI_THEME_PATH = `${repoFolder}/themes`;14process.env.TIDDLYWIKI_LANGUAGE_PATH = `${repoFolder}/languages`;15process.env.TIDDLYWIKI_EDITION_PATH = `${repoFolder}/editions`;16/**17 * æ§è¡å½ä»¤è¡æ令ï¼å¹¶æå°è¯¥æ令çç»æ18 * @param {string} command è¦æ§è¡çå½ä»¤19 * @param {object} options execSyncçåæ°20 */21function shell(command, options) {22 if (options !== undefined) options = {};23 console.log(String(execSync(command, {24 cwd: repoFolder,25 ...options,26 })));27}28/**29 * æ§è¡å½ä»¤è¡æ令ï¼å¹¶æå°è¯¥æ令çç»æï¼åæ¶å¿½ç¥ä»»ä½é误30 * @param {string} command è¦æ§è¡çå½ä»¤31 * @param {object} options execSyncçåæ°32 */33function shellI(command, options) {34 try {35 shell(command, options);36 } catch (error) {37 console.error(`[Shell Command Error] ${error}`)38 }39}40/**41 * æ建å¨çº¿HTMLçæ¬ï¼æ ¸å¿JSåèµæºæ件ä¸å
æ¬å¨HTMLä¸ï¼ ä¸è½½åä¸è½ä½¿ç¨42 * @param {string} distDir ç®æ è·¯å¾ï¼ç©ºæè
ä¸å¡«åé»è®¤ä¸º'dist'43 * @param {string} htmlName HTMLå称ï¼ç©ºæè
ä¸å¡«åé»è®¤ä¸º'index.html'44 * @param {boolean} minify æ¯å¦æå°åJSåHTMLï¼é»è®¤ä¸ºtrue45 * @param {string} excludeFilter è¦æé¤çtiddlerçè¿æ»¤è¡¨è¾¾å¼ï¼é»è®¤ä¸º'-[is[draft]]'46 */47function buildOnlineHTML(distDir, htmlName, minify, excludeFilter) {48 if (typeof distDir !== 'string' || distDir.length === 0) distDir = 'dist';49 if (typeof htmlName !== 'string' || htmlName.length === 0) htmlName = 'index.html';50 if (typeof minify !== 'boolean') minify = true;51 if (typeof excludeFilter !== 'string') excludeFilter = '-[is[draft]]';52 // æ¸
空çæç®æ 53 shell(`rm -rf ${distDir}`);54 // éæèµæºæ·è´55 shellI(`cp -r public/ ${distDir} &> /dev/null`);56 shellI(`cp tiddlers/favicon.ico ${distDir}/favicon.ico &> /dev/null`);57 shellI(`cp tiddlers/TiddlyWikiIconWhite.png ${distDir}/TiddlyWikiIconWhite.png &> /dev/null`);58 shellI(`cp tiddlers/TiddlyWikiIconBlack.png ${distDir}/TiddlyWikiIconBlack.png &> /dev/null`);59 // é¨ç½² vercel60 shellI(`cp vercel.json ${distDir}/vercel.json &> /dev/null`);61 // æ建HTML62 shell('cp -r tiddlers/ tmp_tiddlers_backup &> /dev/null'); // å¤ä»½ å 为ä¸é¢ææ¹åtiddlerçfieldçæä½(åªä½æ件å
¨é¨è½¬ä¸ºcanonical)63 shell(`npx tiddlywiki . --output ${distDir}` +64 ' --deletetiddlers \'[[$:/UpgradeLibrary]] [[$:/UpgradeLibrary/List]]\'' +65 ' --setfield \'[is[image]] [is[binary]] [type[application/msword]] [type[image/svg+xml]]\' _canonical_uri $:/core/templates/canonical-uri-external-image text/plain' +66 ' --setfield \'[is[image]] [is[binary]] [type[application/msword]] [type[image/svg+xml]]\' text "" text/plain' + /* 注æè¿ä¸æ¥ä¹ä¼æææåªä½æ件çå
容åæ空ç */67 ` --rendertiddler $:/core/save/offline-external-js index-raw.html text/plain "" publishFilter "${excludeFilter}"` +68 ' --rendertiddler $:/core/templates/tiddlywiki5.js tiddlywikicore.js text/plain'69 );70 shell('cp -r tmp_tiddlers_backup/* tiddlers &> /dev/null'); // æ¢å¤è¢«æ¸
空å
容çåªä½æ件71 // å é¤éäºè¿å¶æ件ï¼åç¼ç±»åå®ä¹å¨ boot.js ($tw.utils.registerFileType(...))72 shellI('cd tiddlers && rm *.meta *.tid *.multids *.tiddler *.recipe *.txt *.css *.html *.htm *.hta *.js *.json *.md *.bib &> /dev/null');73 shellI(`mkdir ${distDir}/images &> /dev/null`);74 shell(`mv tiddlers/*.* ${distDir}/images &> /dev/null`); // éäºè¿å¶æ件ä¹å°±æ¯èµæºæ件çæ·è´75 shell('rm -rf tiddlers && mv tmp_tiddlers_backup tiddlers &> /dev/null'); // è¿å76 // æå°åï¼æ ¸å¿JSåHTML77 if (minify) {78 shellI(`npx uglifyjs ${distDir}/tiddlywikicore.js -c -m --v8 --webkit --ie --output '${distDir}/tiddlywikicore-'${getVersion}'.js' && rm ${distDir}/tiddlywikicore.js`);79 shellI(`npx html-minifier-terser -c scripts/html-minifier-terser.config.json -o ${distDir}/${htmlName} ${distDir}/index-raw.html && rm ${distDir}/index-raw.html`);80 } else {81 shellI(`mv ${distDir}/tiddlywikicore.js '${distDir}/tiddlywikicore-'${getVersion}'.js'`);82 shellI(`mv ${distDir}/index-raw.html ${distDir}/${htmlName}`);83 }84}85/**86 * æ建离线HTMLçæ¬ï¼æ ¸å¿JSåèµæºæ件å
æ¬å¨HTMLä¸ï¼ ä¸è½½åå¯ä»¥ä½¿ç¨(å°±æ¯åæ件çæ¬çwiki)87 * @param {string} distDir ç®æ è·¯å¾ï¼ç©ºæè
ä¸å¡«åé»è®¤ä¸º'dist'88 * @param {string} htmlName HTMLå称ï¼ç©ºæè
ä¸å¡«åé»è®¤ä¸º'index.html'89 * @param {boolean} minify æ¯å¦æå°åJSåHTMLï¼é»è®¤ä¸ºtrue90 * @param {string} excludeFilter è¦æé¤çtiddlerçè¿æ»¤è¡¨è¾¾å¼ï¼é»è®¤ä¸º'-[is[draft]]'91 */92function buildOfflineHTML(distDir, htmlName, minify, excludeFilter) {93 if (typeof distDir !== 'string' || distDir.length === 0) distDir = 'dist';94 if (typeof htmlName !== 'string' || htmlName.length === 0) htmlName = 'index.html';95 if (typeof minify !== 'boolean') minify = true;96 if (typeof excludeFilter !== 'string') excludeFilter = '-[is[draft]]';97 // æ建HTML98 shell(`npx tiddlywiki . --output ${distDir}` +99 ' --deletetiddlers \'[[$:/UpgradeLibrary]] [[$:/UpgradeLibrary/List]]\'' +100 ` --rendertiddler $:/plugins/tiddlywiki/tiddlyweb/save/offline index-raw.html text/plain "" publishFilter "${excludeFilter}"`101 );102 // æå°åï¼HTML103 if (minify) {104 shellI(`npx html-minifier-terser -c scripts/html-minifier-terser.config.json -o ${distDir}/${htmlName} ${distDir}/index-raw.html && rm ${distDir}/index-raw.html`);105 } else {106 shellI(`mv ${distDir}/index-raw.html ${distDir}/${htmlName}`);107 }108}109/**110 * æ建æ件æº111 * @param {string} pluginFilter è¦åå¸æ件çè¿æ»¤å¨ï¼é»è®¤ä¸º '[prefix[$:/plugins/]!prefix[$:/plugins/tiddlywiki/]!prefix[$:/languages/]!prefix[$:/themes/tiddlywiki/]!tag[$:/tags/PluginLibrary]]'112 * @param {string} distDir ç®æ è·¯å¾ï¼ç©ºæè
ä¸å¡«åé»è®¤ä¸º'dist/library'113 * @param {boolean} minify æ¯å¦æå°åHTMLï¼é»è®¤ä¸ºtrue114 */115function buildLibrary(pluginFilter, distDir, minify) {116 if (typeof pluginFilter !== 'string' || pluginFilter.length === 0) pluginFilter = '[prefix[$:/plugins/]!prefix[$:/plugins/tiddlywiki/]!prefix[$:/languages/]!prefix[$:/themes/tiddlywiki/]!tag[$:/tags/PluginLibrary]]';117 if (typeof distDir !== 'string' || distDir.length === 0) distDir = 'dist/library';118 if (typeof minify !== 'boolean') minify = true;119 shell(`npx tiddlywiki . --output ${distDir}` +120 ' --makelibrary $:/UpgradeLibrary' +121 ` --savelibrarytiddlers $:/UpgradeLibrary ${pluginFilter} recipes/library/tiddlers/ $:/UpgradeLibrary/List` +122 ' --savetiddler $:/UpgradeLibrary/List recipes/library/tiddlers.json' +123 ' --rendertiddler $:/plugins/tiddlywiki/pluginlibrary/library.template.html index-raw.html text/plain' +124 ' --deletetiddlers \'[[$:/UpgradeLibrary]] [[$:/UpgradeLibrary/List]]\''125 );126 // æå°åï¼HTML127 if (minify) {128 shellI(`npx html-minifier-terser -c scripts/html-minifier-terser.config.json -o ${distDir}/index.html ${distDir}/index-raw.html && rm ${distDir}/index-raw.html`);129 } else {130 shellI(`mv ${distDir}/index-raw.html ${distDir}/${htmlName}`);131 }132}133module.exports = {134 buildOnlineHTML: buildOnlineHTML,135 buildOfflineHTML: buildOfflineHTML,136 buildLibrary: buildLibrary,...
gruntFile.js
Source:gruntFile.js
1module.exports = function (grunt) {2 grunt.loadNpmTasks('grunt-contrib-concat');3 grunt.loadNpmTasks('grunt-contrib-jshint');4 grunt.loadNpmTasks('grunt-contrib-uglify');5 grunt.loadNpmTasks('grunt-contrib-clean');6 grunt.loadNpmTasks('grunt-contrib-copy');7 grunt.loadNpmTasks('grunt-contrib-watch');8 grunt.loadNpmTasks('grunt-recess');9 grunt.loadNpmTasks('grunt-karma');10 grunt.loadNpmTasks('grunt-html2js');11 // Default task.12 grunt.registerTask('default', ['jshint','build','karma:unit']);13 grunt.registerTask('build', ['clean','html2js','concat','copy:assets','recess:build']);14 grunt.registerTask('release', ['clean','html2js','uglify','jshint','karma:unit','concat:index', 'recess:min','copy:assets']);15 grunt.registerTask('test-watch', ['karma:watch']);16 // Print a timestamp (useful for when watching)17 grunt.registerTask('timestamp', function() {18 grunt.log.subhead(Date());19 });20 var karmaConfig = function(configFile, customOptions) {21 var options = { configFile: configFile, keepalive: true };22 var travisOptions = process.env.TRAVIS && { browsers: ['Chrome'], reporters: 'dots' };23 return grunt.util._.extend(options, customOptions, travisOptions);24 };25 // Project configuration.26 grunt.initConfig({27 distdir: 'dist',28 pkg: grunt.file.readJSON('package.json'),29 banner:30 '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %>\n' +31 '<%= pkg.homepage ? " * " + pkg.homepage + "\\n" : "" %>' +32 ' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author %>;\n' +33 ' * Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %>\n */\n',34 src: {35 js: ['src/**/*.js', '<%= distdir %>/templates/**/*.js'],36 specs: ['test/**/*.spec.js'],37 scenarios: ['test/**/*.scenario.js'],38 html: ['src/index.html'],39 ico: ['src/assets/favicon.ico'],40 tpl: {41 app: ['src/app/**/*.tpl.html'],42 common: ['src/common/**/*.tpl.html']43 },44 less: ['src/less/stylesheet.less'], // recess:build doesn't accept ** in its file patterns45 lessWatch: ['src/less/**/*.less']46 },47 clean: ['<%= distdir %>/*'],48 copy: {49 assets: {50 files: [{ dest: '<%= distdir %>/assets/', src : '**', expand: true, cwd: 'src/assets/' }]51 },52 mozilla: {53 files: [{ dest: '<%= distdir %>', src : '**', expand: true, cwd: 'vendor/mozilla/' }]54 }55 },56 karma: {57 unit: { options: karmaConfig('test/config/unit.js') },58 watch: { options: karmaConfig('test/config/unit.js', { singleRun:false, autoWatch: true}) }59 },60 html2js: {61 app: {62 options: {63 base: 'src/app'64 },65 src: ['<%= src.tpl.app %>'],66 dest: '<%= distdir %>/templates/app.js',67 module: 'templates.app'68 },69 common: {70 options: {71 base: 'src/common'72 },73 src: ['<%= src.tpl.common %>'],74 dest: '<%= distdir %>/templates/common.js',75 module: 'templates.common'76 }77 },78 concat:{79 dist:{80 options: {81 banner: "<%= banner %>"82 },83 src:['<%= src.js %>'],84 dest:'<%= distdir %>/<%= pkg.name %>.js'85 },86 index: {87 src: ['src/index.html'],88 dest: '<%= distdir %>/index.html',89 options: {90 process: true91 }92 },93 favicon: {94 src: ['src/assets/favicon.ico'],95 dest: '<%= distdir %>/favicon.ico'96 },97 angular: {98 src:['vendor/angular/angular.min.js'],99 dest: '<%= distdir %>/angular.js'100 },101 angularresource: {102 src:['vendor/angular/angular-resource.js'],103 dest: '<%= distdir %>/angular-resource.js'104 },105 bootstrap: {106 src:['vendor/bootstrap/*.js'],107 dest: '<%= distdir %>/bootstrap.js'108 },109 pdfdebug: {110 src:['vendor/mozilla/debugger.js'],111 dest: '<%= distdir %>/debugger.js'112 },113 pdfl10n: {114 src:['vendor/mozilla/l10n.js'],115 dest: '<%= distdir %>/l10n.js'116 },117 viewer: {118 src:['vendor/mozilla/viewer.js'],119 dest: '<%= distdir %>/viewer.js'120 },121 pdf: {122 src:['vendor/mozilla/pdf.js'],123 dest: '<%= distdir %>/pdf.js'124 }125 },126 uglify: {127 dist:{128 options: {129 banner: "<%= banner %>"130 },131 src:['<%= src.js %>'],132 dest:'<%= distdir %>/<%= pkg.name %>.js'133 },134 angular: {135 src:['<%= concat.angular.src %>'],136 dest: '<%= distdir %>/angular.js'137 },138 bootstrap: {139 src:['vendor/bootstrap/bootstrap/*.js'],140 dest: '<%= distdir %>/bootstrap.js'141 },142 jquery: {143 src:['vendor/jquery/*.js'],144 dest: '<%= distdir %>/jquery.js'145 }146 },147 recess: {148 build: {149 files: {150 '<%= distdir %>/<%= pkg.name %>.css':151 ['<%= src.less %>'] },152 options: {153 compile: true154 }155 },156 min: {157 files: {158 '<%= distdir %>/<%= pkg.name %>.css': ['<%= src.less %>']159 },160 options: {161 compress: true162 }163 }164 },165 watch:{166 all: {167 files:['<%= src.js %>', '<%= src.specs %>', '<%= src.lessWatch %>', '<%= src.tpl.app %>', '<%= src.tpl.common %>', '<%= src.html %>'],168 tasks:['default','timestamp']169 },170 build: {171 files:['<%= src.js %>', '<%= src.specs %>', '<%= src.lessWatch %>', '<%= src.tpl.app %>', '<%= src.tpl.common %>', '<%= src.html %>'],172 tasks:['build','timestamp']173 }174 },175 jshint:{176 files:['gruntFile.js', '<%= src.js %>', '<%= src.specs %>', '<%= src.scenarios %>'],177 options:{178 curly:true,179 eqeqeq:true,180 immed:true,181 latedef:true,182 newcap:true,183 noarg:true,184 sub:true,185 boss:true,186 eqnull:true,187 globals:{}188 }189 }190 });...
Using AI Code Generation
1var BestFit = require('bestfit');2var bf = new BestFit();3var dist = bf.distDir(10, 10, 5, 5);4console.log(dist);5var BestFit = require('bestfit');6var bf = new BestFit();7var dist = bf.distDir(10, 10, 5, 5);8console.log(dist);9var BestFit = require('bestfit');10var bf = new BestFit();11var dist = bf.distDir(10, 10, 5, 5);12console.log(dist);13var BestFit = require('bestfit');14var bf = new BestFit();15var dist = bf.distDir(10, 10, 5, 5);16console.log(dist);17var BestFit = require('bestfit');18var bf = new BestFit();19var dist = bf.distDir(10, 10, 5, 5);20console.log(dist);21var BestFit = require('bestfit');22var bf = new BestFit();23var dist = bf.distDir(10, 10, 5, 5);24console.log(dist);25var BestFit = require('bestfit');26var bf = new BestFit();27var dist = bf.distDir(10, 10, 5, 5);28console.log(dist);29var BestFit = require('bestfit');30var bf = new BestFit();31var dist = bf.distDir(10, 10, 5, 5);32console.log(dist);33var BestFit = require('bestfit');34var bf = new BestFit();35var dist = bf.distDir(10, 10, 5, 5);36console.log(dist);
Using AI Code Generation
1var BestPath = Java.type("BestPath");2var Graph = Java.type("Graph");3var Node = Java.type("Node");4var Edge = Java.type("Edge");5var g = new Graph();6var n1 = new Node("1");7var n2 = new Node("2");8var n3 = new Node("3");9var n4 = new Node("4");10var n5 = new Node("5");11var n6 = new Node("6");12var n7 = new Node("7");13var n8 = new Node("8");14var n9 = new Node("9");15g.addNode(n1);16g.addNode(n2);17g.addNode(n3);18g.addNode(n4);19g.addNode(n5);20g.addNode(n6);21g.addNode(n7);22g.addNode(n8);23g.addNode(n9);24var e1 = new Edge(n1, n2, 4);25var e2 = new Edge(n1, n8, 8);26var e3 = new Edge(n2, n3, 8);27var e4 = new Edge(n2, n8, 11);28var e5 = new Edge(n3, n4, 7);29var e6 = new Edge(n3, n9, 2);30var e7 = new Edge(n3, n6, 4);31var e8 = new Edge(n4, n5, 9);32var e9 = new Edge(n4, n6, 14);33var e10 = new Edge(n5, n6, 10);34var e11 = new Edge(n6, n7, 2);35var e12 = new Edge(n7, n8, 1);36var e13 = new Edge(n7, n9, 6);37var e14 = new Edge(n8, n9, 7);38g.addEdge(e1);39g.addEdge(e2);40g.addEdge(e3);41g.addEdge(e4);42g.addEdge(e5);43g.addEdge(e6);44g.addEdge(e7);45g.addEdge(e8);46g.addEdge(e9);47g.addEdge(e10);48g.addEdge(e11);49g.addEdge(e12);50g.addEdge(e13);
Using AI Code Generation
1var g = new Graph();2g.addNode("A");3g.addNode("B");4g.addNode("C");5g.addNode("D");6g.addNode("E");7g.addNode("F");8g.addNode("G");9g.addNode("H");10g.addNode("I");11g.addNode("J");12g.addNode("K");13g.addNode("L");14g.addNode("M");15g.addNode("N");16g.addNode("O");17g.addNode("P");18g.addNode("Q");19g.addNode("R");20g.addNode("S");21g.addNode("T");22g.addNode("U");23g.addNode("V");24g.addNode("W");25g.addNode("X");26g.addNode("Y");27g.addNode("Z");28g.addEdge("A", "B", 1);29g.addEdge("A", "C", 1);30g.addEdge("A", "D", 1);31g.addEdge("A", "E", 1);32g.addEdge("B", "F", 1);33g.addEdge("B", "G", 1);34g.addEdge("B", "H", 1);35g.addEdge("B", "I", 1);36g.addEdge("C", "J", 1);37g.addEdge("C", "K", 1);38g.addEdge("C", "L", 1);39g.addEdge("C", "M", 1);40g.addEdge("D", "N", 1);41g.addEdge("D", "O", 1);42g.addEdge("D", "P", 1);43g.addEdge("D", "Q", 1);44g.addEdge("E", "R", 1);45g.addEdge("E", "S", 1);46g.addEdge("E", "T", 1);47g.addEdge("E", "U", 1);48g.addEdge("F", "V", 1);49g.addEdge("F", "W", 1);50g.addEdge("F", "X", 1);51g.addEdge("F", "Y", 1);52g.addEdge("G", "Z", 1);53g.addEdge("G", "A", 1);54g.addEdge("G", "B", 1);55g.addEdge("G", "C", 1);56g.addEdge("H", "D", 1);57g.addEdge("H", "E", 1
Using AI Code Generation
1var fs = require('fs');2var bestPath = require('./bestPath.js');3var data = fs.readFileSync('input.txt', 'utf8');4var lines = data.split('5');6var firstLine = lines[0];7var firstLineArray = firstLine.split(' ');8var numNodes = firstLineArray[0];9var numEdges = firstLineArray[1];10var source = firstLineArray[2];11var dest = firstLineArray[3];12var bp = new bestPath.BestPath(numNodes);13for(var i = 1; i < lines.length; i++){14 var lineArray = lines[i].split(' ');15 var sourceNode = lineArray[0];16 var destNode = lineArray[1];17 var distance = lineArray[2];18 bp.addEdge(sourceNode, destNode, distance);19}20var path = bp.distDir(source, dest);21console.log(path);22console.log(bp.getDistance(path));23function BestPath(numNodes){24 this.adjList = new Array(numNodes);25 this.distance = new Array(numNodes);26 this.path = new Array(numNodes);27 this.visited = new Array(numNodes);28 this.pq = new PriorityQueue(numNodes);
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!!