async findPackage(dir) { // Find the nearest package.json file within the current node_modules folder let root = path.parse(dir).root; while (dir !== root && path.basename(dir) !== "node_modules") { try { return await this.readPackage(dir); } catch (err) { // ignore } dir = path.dirname(dir); } }
filter(file) { const baseName = path.basename(file); return baseName !== 'node_modules' && baseName !== '.git' && baseName !== '.env'; }
process(src, filename /*, config, options */) { return 'module.exports = ' + JSON.stringify(path.basename(filename)) + ';'; }
it('should handle buffer path from fs.readStream', function test() { let file; try { file = fs.createReadStream(Buffer.from(paths.audio)); } catch (ex) { // Older Node.js versions do not support passing a Buffer // representation of the path to fs.createReadStream() if (ex instanceof TypeError) { Promise.resolve(); return; } } const [{ [type]: data }] = bot._formatSendData('file', file); assert.equal(data.options.filename, path.basename(paths.audio)); });
// Read all files from that path and load into modules fs.readdirSync(dir).forEach(function (file) { if (file.indexOf('.js') < 0) return; var mod = require(path.join(dir, file)); var name = path.basename(file, '.js'); loaded[name] = mod; });
function checkArgs (args, help, version) { if (args['--'] && args['--'].length >= 1 && !/^node(\.exe)?$/.test(path.basename(args['--'][0]))) { console.error('Clinic.js must be called with a `node` command line: `clinic doctor -- node script.js`\n') printHelp(help, version) process.exit(1) } }
config.cloudReq({ url: (deploymentId) => `build/deploy/${deploymentId}/upload-file`, method: 'POST', formData: { transaction: JSON.stringify(transaction), fileName: file, file: { value: fs.createReadStream(path.join(directory, file)), options: { filename: path.basename(file), contentType: 'application/octet-stream' } } }, auth })
/** * recursively traverses through all folders given from filePath and creates JSON Object; * @param {String} filePath Path to Component folder * @param {String} rootPath - name of File */ function constructComponentTree(filePath, rootPath) { // create object at current level; let result = constructSingleLevel(path.join(rootPath, filePath)); // checks if current Object has children and traverses through children to create Object; if(result && Object.keys(result.childProps).length > 0){ for(let childProp of result.childProps) { //creates new path for children components - if girootPath doesnt have an extension adds .js extension let fullPath = path.join(rootPath, childProp.path); let newRootPath = path.dirname(fullPath); let newFileName = path.basename(fullPath); let childPathSplit = newFileName.split('.'); if (childPathSplit.length === 1) newFileName += '.js'; let newFullPath = path.join(newRootPath, newFileName); //traverses through children result.children.push(constructComponentTree(newFileName, newRootPath)); } } return result; }
static formatAsset (assetPath) { return path.basename(assetPath).split('.')[0] }
function uploadPromise(url) { const name = path.basename(url); const type = mime.getType(name); const stream = fs.createReadStream(url); const {size} = fs.statSync(url); return new Promise((resolve, reject) => { cos.putObject({ Bucket: 'webchat-1251965041', Region: 'ap-beijing', Key: name, ContentType: type, Body: stream, ContentLength: size // FilePath: url }, function (err, data) { if(err) { reject(err); return; } if(data.statusCode === 200) { resolve('success'); } console.log(data); }); }) }
stripExt(url: string) { return path.basename(url, path.extname(url)); }
process(src, filename) { const assetFilename = JSON.stringify(path.basename(filename)); if (filename.match(/\.svg$/)) { // Based on how SVGR generates a component name: // https://github.com/smooth-code/svgr/blob/01b194cf967347d43d4cbe6b434404731b87cf27/packages/core/src/state.js#L6 const pascalCaseFileName = camelcase(path.parse(filename).name, { pascalCase: true, }); const componentName = `Svg${pascalCaseFileName}`; return `const React = require('react'); module.exports = { __esModule: true, default: ${assetFilename}, ReactComponent: React.forwardRef(function ${componentName}(props, ref) { return { $$typeof: Symbol.for('react.element'), type: 'svg', ref: ref, key: null, props: Object.assign({}, props, { children: ${assetFilename} }) }; }), };`; } return `module.exports = ${assetFilename};`; }
async findPackage(dir) { // Find the nearest package.json file within the current node_modules folder let root = path.parse(dir).root; while (dir !== root && path.basename(dir) !== "node_modules") { try { return await this.readPackage(dir); } catch (err) { // ignore } dir = path.dirname(dir); } }
process(src, filename) { const assetFilename = JSON.stringify(path.basename(filename)); if (filename.match(/\.svg$/)) { // Based on how SVGR generates a component name: // https://github.com/smooth-code/svgr/blob/01b194cf967347d43d4cbe6b434404731b87cf27/packages/core/src/state.js#L6 const pascalCaseFilename = camelcase(path.parse(filename).name, { pascalCase: true, }); const componentName = `Svg${pascalCaseFilename}`; return `const React = require('react'); module.exports = { __esModule: true, default: ${assetFilename}, ReactComponent: React.forwardRef(function ${componentName}(props, ref) { return { $$typeof: Symbol.for('react.element'), type: 'svg', ref: ref, key: null, props: Object.assign({}, props, { children: ${assetFilename} }) }; }), };`; } return `module.exports = ${assetFilename};`; }