How to use bundleDirname method in Best

Best JavaScript code snippet using best

index.js

Source:index.js Github

copy

Full Screen

1const fs = require('fs-extra')2const path = require('path')3const axios = require('axios')4const request = require('request')5const chalk = require('chalk')6class XmCdnSDK {7 constructor(option) {8 if (!option) {9 this.logger.error('请传入正确的参数')10 }11 if (!option.env) {12 this.logger.error('请传入环境变量env参数 example:{ env:"production" }')13 }14 const {15 cdnDirName,16 bundleDirName,17 env,18 } = option19 this.env = env20 this.cdnDirName = cdnDirName21 this.bundleDirName = bundleDirName22 }23 init() {24 this.logger.info('开始上传静态文件...')25 // this.logger.info('传入的环境变量:' + this.env)26 this.fileDisplay(this.bundleDirName)27 }28 logger = {29 error: (log) => {30 throw new Error(chalk.redBright(log))31 },32 info: (log) => {33 console.log(chalk.magenta(log))34 },35 }36 setTakaTokenUrl = () => {37 if (this.env === 'qa') {38 XmCdnSDK.takaTokenUrl = XmCdnSDK.takaTokenUrl.substring(0, 8) + 'qa' + XmCdnSDK.takaTokenUrl.substring(8)39 }40 }41 fileDisplay = (bundleDirName) => {42 // 根据文件路径读取文件,返回文件列表43 fs.readdir(bundleDirName, (err, files) => this.readdirCallBack({ files, bundleDirName }))44 }45 readdirCallBack = async ({ files, bundleDirName }) => {46 await Promise.all(files.map(filename => {47 const suffix = this.getSuffix(filename)48 const isSupportFile = XmCdnSDK.supportFiles.includes(suffix)49 // 获取当前文件的绝对路径50 const filedir = path.join(bundleDirName, filename)51 // 根据文件路径获取文件信息,返回一个fs.Stats对象52 fs.stat(filedir, (eror, stats) => this.statCallBack({ stats, isSupportFile, filedir }))53 }))54 }55 statCallBack = ({ stats, isSupportFile, filedir }) => {56 const isFile = stats.isFile()// 是文件57 const isDir = stats.isDirectory()// 是文件夹58 if (isFile && isSupportFile) {59 const bizType = this.cdnDirName60 // 需要上传的文件类型61 this.getToken({62 filedir,63 bizType64 })65 }66 // 递归,如果是文件夹,就继续遍历该文件夹下面的文件67 if (isDir) {68 this.fileDisplay(filedir)69 }70 }71 getToken = async ({ filedir, bizType }) => {72 await axios.post(XmCdnSDK.takaTokenUrl, {73 bizType74 })75 .then(res => {76 const response = res.data77 const customFilePath = `/${bizType}${filedir.replace(this.bundleDirName, '').replace(/\\/g, '/')}`78 this.uploadFile({79 filedir,80 action: `${response.data.uploadDomain}/v1/file`,81 token: response.data.token,82 customFilePath83 })84 })85 .catch(error => {86 console.error(error)87 })88 }89 uploadFile = async ({ filedir, action, token, customFilePath }) => {90 const data = {91 customFilePath,92 isFullWrite: 1,93 };94 const params = {95 url: action,96 formData: {97 ...data,98 file: fs.createReadStream(filedir),99 },100 headers: {101 token,102 },103 }104 request.post(params, (err, resp, body) => {105 if (err) {106 console.warn('上传失败');107 return;108 }109 const result = JSON.parse(body);110 console.log(`${chalk.green('上传成功')} 地址是:${result.data[0].publishUrl}`);111 });112 }113 getSuffix = (url) => {114 return url.substring(url.lastIndexOf('.'), url.length)115 }116}117XmCdnSDK.takaTokenUrl = 'https://api.xinmai100.com/xinmai-admin-order/taka-token'118XmCdnSDK.supportFiles = ['.js', '.png', '.jpg', '.css', '.xlsx']...

Full Screen

Full Screen

rollup.config.js

Source:rollup.config.js Github

copy

Full Screen

1import resolve from "@rollup/plugin-node-resolve";2import commonjs from "@rollup/plugin-commonjs";3import { terser } from "rollup-plugin-terser";4import typescript from "@rollup/plugin-typescript";5import pkg from "./package.json";6const pkgName = pkg.name;7const bundleDirName = "dist";8export default {9 input: "src/index.ts",10 output: [11 {12 file: `${bundleDirName}/${pkgName}.esm.js`,13 format: "esm",14 },15 {16 file: `${bundleDirName}/${pkgName}.unpkg.js`,17 format: "iife",18 name: "TEST",19 },20 {21 file: `${bundleDirName}/${pkgName}.esm.min.js`,22 format: "esm",23 plugins: [terser()],24 },25 {26 file: `${bundleDirName}/${pkgName}.unpkg.min.js`,27 format: "iife",28 name: "TEST",29 plugins: [terser()],30 },31 ],32 plugins: [resolve(), commonjs(), typescript()],...

Full Screen

Full Screen

pipe-paths.ts

Source:pipe-paths.ts Github

copy

Full Screen

1import { join } from 'node:path'2import { ProjectPaths } from './project-paths.js'3export type PipePath = {4 name: string5 sourceFileName: string6 bundleDirName: string7 bundleFileName: string8}9export function getPipePaths(10 projectPaths: ProjectPaths,11 pipeName: string,12): PipePath {13 const bundleDirName = join(projectPaths.path, 'builds', pipeName)14 return {15 name: pipeName,16 sourceFileName: join(projectPaths.pipesPath, `${pipeName}.ts`),17 bundleDirName,18 bundleFileName: join(bundleDirName, 'bundle.js'),19 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestGlobals = require('bestglobals');2var path = require('path');3var test4 = function() {4 console.log('test4.js: ' + BestGlobals.bundleDirname);5 console.log('test4.js: ' + path.join(BestGlobals.bundleDirname, 'test4.js'));6 console.log('test4.js: ' + path.join(BestGlobals.bundleDirname, 'test4.js') === __filename);7 return path.join(BestGlobals.bundleDirname, 'test4.js') === __filename;8};9module.exports = test4;

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestGlobals = require('bestglobals');2var path = require('path');3var bg = new BestGlobals();4var path1 = bg.bundleDirname();5var path2 = path.join(path1, "test5.js");6console.log(path2);7var BestGlobals = require('bestglobals');8var bg = new BestGlobals();9var path1 = bg.bundleDirname();10console.log(path1);11var BestGlobals = require('bestglobals');12var bg = new BestGlobals();13var path1 = bg.bundleDirname();14console.log(path1);15var BestGlobals = require('bestglobals');16var bg = new BestGlobals();17var path1 = bg.bundleDirname();18console.log(path1);19var BestGlobals = require('bestglobals');20var bg = new BestGlobals();21var path1 = bg.bundleDirname();22console.log(path1);23var BestGlobals = require('bestglobals');24var bg = new BestGlobals();25var path1 = bg.bundleDirname();26console.log(path1);27var BestGlobals = require('bestglobals');28var bg = new BestGlobals();29var path1 = bg.bundleDirname();30console.log(path1);31var BestGlobals = require('bestglobals');32var bg = new BestGlobals();33var path1 = bg.bundleDirname();34console.log(path1);35var BestGlobals = require('bestglobals');36var bg = new BestGlobals();37var path1 = bg.bundleDirname();38console.log(path1);39var BestGlobals = require('bestglobals');40var bg = new BestGlobals();41var path1 = bg.bundleDirname();42console.log(path1);

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestGlobals = require('best-globals');2var path = require('path');3var assert = require('assert');4var dir = BestGlobals.bundleDirname;5var expectedDir = path.join(__dirname, 'test4');6assert.strictEqual(dir, expectedDir, 'test4.js should be in ' + expectedDir + ' but is in ' + dir);7console.log('test4.js in ' + dir);

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestGlobals = require('./BestGlobals.js');2var path = require('path');3var test4 = function() {4 var test4 = BestGlobals.bundleDirname();5 console.log('test4.js: ' + test4);6 return test4;7}8module.exports = test4;

Full Screen

Using AI Code Generation

copy

Full Screen

1var BestGlobals = require('bestglobals');2var bg = new BestGlobals();3console.log(bg.bundleDirname());4var BestGlobals = require('bestglobals');5var bg = new BestGlobals();6console.log(bg.bundlePathname());7var BestGlobals = require('bestglobals');8var bg = new BestGlobals();9console.log(bg.bundleFilename());10var BestGlobals = require('bestglobals');11var bg = new BestGlobals();12console.log(bg.bundleBasename());13var BestGlobals = require('bestglobals');14var bg = new BestGlobals();15console.log(bg.bundleExtname());16var BestGlobals = require('bestglobals');17var bg = new BestGlobals();18console.log(bg.bundleDir());19var BestGlobals = require('bestglobals');20var bg = new BestGlobals();21console.log(bg.bundleDirname());22var BestGlobals = require('bestglobals');23var bg = new BestGlobals();24console.log(bg.bundlePathname());

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Best automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful