4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
${errorStr}`; 125 | // return { htmlOpenString }; 126 | } 127 | const currentDir = path.dirname(__path); 128 | let absolutePath = path.resolve(currentDir, meta.src); 129 | const srcFile = resolveFile(absolutePath); 130 | if (meta.language) { 131 | srcFile.language = meta.language; 132 | } 133 | 134 | if (!srcFile) { 135 | let errorStr = `NotFound: file not found\n\t${meta.src}`; 136 | throw new Error(errorStr); 137 | // attrsStr += ` codeStr="${encodeURIComponent(errorStr)}"`; 138 | // htmlOpenString += ` ${attrsStr}>
${errorStr}`; 139 | } else { 140 | const metaFiles = Array.isArray(meta.file) ? meta.file : [meta.file].filter(Boolean); 141 | 142 | const files = [srcFile, ...metaFiles.map((p) => resolveFile(path.resolve(currentDir, p)))] 143 | .filter((f, i, a) => { 144 | // console.log('filter', f); 145 | if (!f) return false; 146 | return a.findIndex((f2) => f2.filePath === f.filePath) === i; 147 | }) 148 | .map((f) => ({ ...f, name: path.relative(currentDir, f.filePath) })); 149 | // todo const localName = 'Demo' + md5(srcFile.filePath); 150 | const localName = `Demo${++count}`; 151 | const varName = `files${count}`; 152 | addVariableDeclaration(hoistedTags, varName, JSON.stringify(files)); 153 | const filesAttr = ` :files="${varName}"`; 154 | attrsStr += filesAttr; 155 | 156 | let useIframeMode = meta.iframe || absolutePath.endsWith('.html'); 157 | if (useIframeMode) { 158 | // const isSymbolicLink = fs.lstatSync(absolutePath).isSymbolicLink() 159 | attrsStr += ` iframe`; 160 | demos[localName] = { title: meta.title, entry: absolutePath }; 161 | fs.writeFileSync(path.resolve(process.cwd(), 'node_modules/demos.json'), JSON.stringify(demos, null, 2)); 162 | htmlOpenString += ` ${attrsStr}>