Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* Read stage
*/
// Read from excel. Get head and data
let inputData = []
try {
let tmpFilePath = path.join(os.tmpdir(), 'vue-i18n-xlsx', path.basename(projectPath), path.basename(filePath))
if (!global._cacheCleared) {
try {
fs.unlinkSync(tmpFilePath)
} catch (e) {
// noop
} finally {
global._cacheCleared = true
}
}
inputData = Excel.parse(tmpFilePath)[0].data
} catch (e) {
try {
inputData = Excel.parse(filePath)[0].data
} catch (e) {
Warn(chalk.yellow(
chalk.bgYellow.black(' WARN '),
'Excel file not exist'
))
mkdirsSync(path.dirname(filePath))
fs.writeFileSync(filePath, Excel.build([{name: path.basename(filePath, '.xlsx'), data: null}]))
}
}
Log(chalk('> ',
'Length of i18n before reading from project:',
chalk.cyan(inputData.length)
))
module.exports = function (excelPath, jsPath, projectPath) {
///////// START /////////
let startTime = Date.now()
// File path must end with .xlsx
excelPath = excelPath.endsWith('.xlsx') ? excelPath : excelPath + '.xlsx'
// Read from excel
let inputData = []
try {
inputData = Excel.parse(excelPath)[0].data
} catch (e) {
Warn(chalk.yellow(
chalk.bgYellow.black(' WARN '),
'Excel file not exist'
))
return
}
// Generate json
let head = inputData[0]
let data = {}
for (let i = 1; i < inputData.length; i++) {
let row = inputData[i]
for (let j = 1; j < head.length; j++) {
let col = row[j]
let lang = data[head[j]] = data[head[j]] || {}
lang[row[0]] = col || ''
let inputData = []
try {
let tmpFilePath = path.join(os.tmpdir(), 'vue-i18n-xlsx', path.basename(projectPath), path.basename(filePath))
if (!global._cacheCleared) {
try {
fs.unlinkSync(tmpFilePath)
} catch (e) {
// noop
} finally {
global._cacheCleared = true
}
}
inputData = Excel.parse(tmpFilePath)[0].data
} catch (e) {
try {
inputData = Excel.parse(filePath)[0].data
} catch (e) {
Warn(chalk.yellow(
chalk.bgYellow.black(' WARN '),
'Excel file not exist'
))
mkdirsSync(path.dirname(filePath))
fs.writeFileSync(filePath, Excel.build([{name: path.basename(filePath, '.xlsx'), data: null}]))
}
}
Log(chalk('> ',
'Length of i18n before reading from project:',
chalk.cyan(inputData.length)
))
// zh keys
let i18ns = inputData.map(row => row[0]).filter(col => col !== 'index')
const i18nReg = /\$t\(['"`](.*?)['"`](?:\s*,.*?)?\)/
const XLSX = require('node-xlsx').default;
const path = require('path');
const _ = require('lodash');
const fs = require('fs');
const ObjectID = require('mongodb').ObjectID;
const gardenSheet = XLSX.parse(path.join(__dirname, './garden.xlsx'));
const herbariumnSheet = XLSX.parse(path.join(__dirname, './herbarium.xlsx'));
let amount = process.env.JSON_PARSE_AMOUNT || 999999999;
exports.setAmount = function setAmount(_amount) {
amount = _amount;
}
function encodeRFC5987ValueChars(str) {
return encodeURI(str).
replace(/['()]/g, escape)
}
function escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}
function getScinameKey(sciname) {
const scinameSplit = sciname.split(' ');
return `${scinameSplit[0]} ${scinameSplit[1]}`;
const XLSX = require('node-xlsx').default;
const path = require('path');
const _ = require('lodash');
const fs = require('fs');
const ObjectID = require('mongodb').ObjectID;
const gardenSheet = XLSX.parse(path.join(__dirname, './garden.xlsx'));
const herbariumnSheet = XLSX.parse(path.join(__dirname, './herbarium.xlsx'));
let amount = process.env.JSON_PARSE_AMOUNT || 999999999;
exports.setAmount = function setAmount(_amount) {
amount = _amount;
}
function encodeRFC5987ValueChars(str) {
return encodeURI(str).
replace(/['()]/g, escape)
}
function escapeRegExp(str) {
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
}
function getScinameKey(sciname) {
const scinameSplit = sciname.split(' ');
const XLSX = require('node-xlsx').default;
const path = require('path');
const keystone = require('keystone');
const _ = require('lodash');
const Plant = keystone.list('Plant');
const PlantCategory = keystone.list('Category');
const Location = keystone.list('Location');
const herbariumSheet = XLSX.parse(path.join(__dirname, '../../seed/Herbarium.xlsx'));
function letterToColumns(input) {
return input.charCodeAt(0) - 65;
}
const herbs = herbariumSheet[0]
.data
.filter((item, i) => i > 0 && item[letterToColumns('E')])
.filter(item => item[letterToColumns('F')])
.map(columns => ({
cuid: columns[letterToColumns('A')],
localName: columns[letterToColumns('F')],
otherName: columns[letterToColumns('G')] ? columns[letterToColumns('G')].split(';') : [],
duplicateAmount: columns[letterToColumns('H')],
scientificName: columns[letterToColumns('E')],
function loadXML(xmlPath) {
let userData = xlsx.parse(xmlPath);
let outData = [];
userData.forEach(item => {
outData = item.data;
outData.shift();
return false;
});
outData = outData.filter(item => item.length > 0);
return outData;
}
async function readSheets(filePath) {
const rawFileContent = await readFile(filePath)
const fileContent = filePath.endsWith('.gz') ? await gunzip(rawFileContent) : rawFileContent
return xlsx.parse(fileContent, {cellDates: true})
}
const XLSX = require('node-xlsx').default;
const path = require('path');
const keystone = require('keystone');
const _ = require('lodash');
const Plant = keystone.list('Plant');
const PlantCategory = keystone.list('Category');
const Location = keystone.list('Location');
const gardenSheet = XLSX.parse(path.join(__dirname, '../../seed/Garden.xls'));
function letterToColumns(input) {
return input.charCodeAt(0) - 65;
}
const gardens = gardenSheet[0]
.data
.filter((item, i) => i > 0 && item[letterToColumns('E')])
.map((columns) => {
const anatomy = [];
if (columns[letterToColumns('Q')]) {
anatomy.push(columns[letterToColumns('Q')]);
}
if (columns[letterToColumns('P')]) {
anatomy.push(columns[letterToColumns('P')]);