Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e1ebbf67d8 | |||
| 201be2179e | |||
| acf0978d76 | |||
|
|
6c238508e2 |
6
.github/workflows/docker-publish.yml
vendored
6
.github/workflows/docker-publish.yml
vendored
@@ -1,8 +1,8 @@
|
|||||||
name: Docker CI
|
name: Docker CI
|
||||||
|
|
||||||
on:
|
on:
|
||||||
release:
|
push:
|
||||||
types: [created]
|
branches: [main]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
docker:
|
docker:
|
||||||
@@ -20,4 +20,4 @@ jobs:
|
|||||||
|
|
||||||
- name: Build and Push from Makefile
|
- name: Build and Push from Makefile
|
||||||
run: |
|
run: |
|
||||||
make build
|
make build publish
|
||||||
|
|||||||
13
.github/workflows/npm-publish.yml
vendored
13
.github/workflows/npm-publish.yml
vendored
@@ -25,16 +25,3 @@ jobs:
|
|||||||
- run: npm publish
|
- run: npm publish
|
||||||
env:
|
env:
|
||||||
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|
||||||
|
|
||||||
publish-gpr:
|
|
||||||
needs: build
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- uses: actions/setup-node@v1
|
|
||||||
with:
|
|
||||||
node-version: 14
|
|
||||||
registry-url: https://npm.pkg.github.com/
|
|
||||||
- run: npm publish
|
|
||||||
env:
|
|
||||||
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
|
||||||
|
|||||||
6
Makefile
6
Makefile
@@ -1,4 +1,4 @@
|
|||||||
DOCKER_IMAGE=cubetiq/node-excel2json
|
DOCKER_IMAGE=cubetiq/excel2json
|
||||||
|
|
||||||
build:
|
build:
|
||||||
@echo "Building docker image..."
|
@echo "Building docker image..."
|
||||||
@@ -8,4 +8,8 @@ run:
|
|||||||
@echo "Running container..."
|
@echo "Running container..."
|
||||||
docker run --rm -t ${DOCKER_IMAGE}
|
docker run --rm -t ${DOCKER_IMAGE}
|
||||||
|
|
||||||
|
publish:
|
||||||
|
@echo "Pubishing docker image..."
|
||||||
|
docker push ${DOCKER_IMAGE}
|
||||||
|
|
||||||
.PHONY: build
|
.PHONY: build
|
||||||
|
|||||||
@@ -1,18 +1 @@
|
|||||||
{
|
{}
|
||||||
"data": [
|
|
||||||
{
|
|
||||||
"dataIndex": "Name",
|
|
||||||
"label": "Name"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"dataIndex": "Age",
|
|
||||||
"label": "Age"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"configs": {
|
|
||||||
"outputPath": "./data/outputs/exported",
|
|
||||||
"outputName": "my_exported_data",
|
|
||||||
"sheetName": "Sheet1",
|
|
||||||
"saveToOutput": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,8 +8,7 @@ function _internalExport(props = {}) {
|
|||||||
console.log("Name =>", NAME, "\n");
|
console.log("Name =>", NAME, "\n");
|
||||||
|
|
||||||
// load from env
|
// load from env
|
||||||
const INPUT_FILE =
|
const INPUT_FILE = props.inputFile || process.env.INPUT_FILE;
|
||||||
props.inputFile || process.env.INPUT_FILE || "./data/people.xlsx";
|
|
||||||
const OUTPUT_PATH =
|
const OUTPUT_PATH =
|
||||||
props.outputPath || process.env.OUTPUT_PATH || "./data/outputs";
|
props.outputPath || process.env.OUTPUT_PATH || "./data/outputs";
|
||||||
const MAPPER_FILE =
|
const MAPPER_FILE =
|
||||||
@@ -31,16 +30,21 @@ function _internalExport(props = {}) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("read file error", err);
|
// console.error("read file error", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert mapper from string to json object
|
// convert mapper from string to json object
|
||||||
const mapperJson = mapperString ? JSON.parse(mapperString) : {};
|
const mapperJson = mapperString ? JSON.parse(mapperString) : {};
|
||||||
const configs = { ...mapperJson.configs, ...props };
|
const configs = { ...mapperJson.configs, ...props };
|
||||||
const columsData = props.mappings || mapperJson.data || undefined;
|
const columsData = props.mappings || mapperJson.data || undefined;
|
||||||
|
const inFile = configs.inputFile || INPUT_FILE;
|
||||||
|
|
||||||
|
if (!inFile) {
|
||||||
|
throw Error("Input file is required!");
|
||||||
|
}
|
||||||
|
|
||||||
// read workbook from excel file
|
// read workbook from excel file
|
||||||
const wb = XLSX.readFile(configs.inputFile || INPUT_FILE);
|
const wb = XLSX.readFile(inFile);
|
||||||
const xlData = XLSX.utils.sheet_to_json(
|
const xlData = XLSX.utils.sheet_to_json(
|
||||||
wb.Sheets[configs.sheetName || SHEET_NAME]
|
wb.Sheets[configs.sheetName || SHEET_NAME]
|
||||||
);
|
);
|
||||||
|
|||||||
4
index.js
4
index.js
@@ -2,7 +2,9 @@
|
|||||||
const excel2json = require("./excel2json");
|
const excel2json = require("./excel2json");
|
||||||
|
|
||||||
// called function export excel2json
|
// called function export excel2json
|
||||||
const exported = excel2json();
|
const exported = excel2json({
|
||||||
|
inputFile: "./data/people.xlsx"
|
||||||
|
});
|
||||||
|
|
||||||
// output data from exported
|
// output data from exported
|
||||||
console.log("Output =>\n", exported);
|
console.log("Output =>\n", exported);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "excel2json-xlsx",
|
"name": "excel2json-xlsx",
|
||||||
"version": "1.0.1",
|
"version": "1.0.2",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"excel",
|
"excel",
|
||||||
"json",
|
"json",
|
||||||
|
|||||||
Reference in New Issue
Block a user