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); } }
let importResolver = async function (srcId, idsToFind) { let luObjects = [] let parentFilePath = path.parse(path.resolve(srcId)).dir for (let idx = 0; idx < idsToFind.length; idx++) { let file = idsToFind[idx] if (!path.isAbsolute(file.filePath)) { file.filePath = path.resolve(parentFilePath, file.filePath) } if (file.filePath.endsWith("common.lu")) { luObjects.push(new luObject(`# common_intent${NEWLINE}- this is common utterance`, new luOptions(file.filePath, file.includeInCollate))) } else if (file.filePath.endsWith("common.qna")) { luObjects.push(new luObject(`# ? common_question${NEWLINE}\`\`\`${NEWLINE}this is common answer${NEWLINE}\`\`\``, new luOptions(file.filePath, file.includeInCollate))) } } return luObjects }
co(function * (globs, opts) { globs = $.flatten($.toArray(globs)); const files = yield this.$.expand(globs, opts); if (globs.length && !files.length) { this.emit('globs_no_match', globs, opts); } // pre-fetch each file's content const datas = yield Promise.all(files.map(f => this.$.read(f))); // update known globs this._.globs = globs; // update known files, as (mod'd) `pathObject`s this._.files = files.map((el, idx) => { const obj = parse(el); return { dir: normalize(obj.dir), data: datas[idx], base: obj.base }; }); })
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};`; }
const resolveLuFileContent = function(file, luObjects, srcId) { let parentFilePath = srcId === 'stdin' ? process.cwd() : path.parse(path.resolve(srcId)).dir // Support wild cards at the end of a relative .LU file path. // './bar/*' should look for all .lu files under the specified folder. // './bar/**' should recursively look for .lu files under sub-folders as well. if(file.filePath.endsWith('*')) { const isRecursive = file.filePath.endsWith('**') const rootFolder = file.filePath.replace(/\*/g, '') let rootPath = rootFolder; if(!path.isAbsolute(rootFolder)) { rootPath = path.resolve(parentFilePath, rootFolder); } // Get LU files in this location const luFilesToAdd = helpers.findLUFiles(rootPath, isRecursive); // add these to filesToParse for(let f = 0; f < luFilesToAdd.length; f++){ const opts = new luOptions(luFilesToAdd[f], file.includeInCollate) luObjects.push(new luObject(readLuFile(luFilesToAdd[f]), opts)) } return } if(!path.isAbsolute(file.filePath)) { file.filePath = path.resolve(parentFilePath, file.filePath) } // find matching parsed files and ensure includeInCollate is updated if needed. luObjects.push(new luObject(readLuFile(file.filePath), new luOptions(file.filePath, file.includeInCollate))) }
let root = path.parse(dir).root;
let importResolver = async function (srcId, idsToFind) { let luObjects = [] let parentFilePath = path.parse(path.resolve(srcId)).dir for (let idx = 0; idx < idsToFind.length; idx++) { let file = idsToFind[idx]
let importResolver = async function (srcId, idsToFind) { let luObjects = [] let parentFilePath = path.parse(path.resolve(srcId)).dir for (let idx = 0; idx < idsToFind.length; idx++) { let file = idsToFind[idx]
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); } }
co(function * (globs, opts) { globs = $.flatten($.toArray(globs)); const files = yield this.$.expand(globs, opts); if (globs.length && !files.length) { this.emit('globs_no_match', globs, opts); } // pre-fetch each file's content const datas = yield Promise.all(files.map(f => this.$.read(f))); // update known globs this._.globs = globs; // update known files, as (mod'd) `pathObject`s this._.files = files.map((el, idx) => { const obj = parse(el); return { dir: normalize(obj.dir), data: datas[idx], base: obj.base }; }); })
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};`; }
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};`; }
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};`; }