Skip to content

Commit

Permalink
feat: 功能实现
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxingkang committed Nov 7, 2021
1 parent 1ea4787 commit 6478484
Show file tree
Hide file tree
Showing 40 changed files with 11,616 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
parser: '@typescript-eslint/parser',
extends: [
'plugin:@typescript-eslint/recommended',
'prettier/@typescript-eslint',
'plugin:prettier/recommended',
],
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off'
},
};
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
test/
.idea/

lib
7 changes: 7 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
semi: false,
trailingComma: 'all',
singleQuote: true,
printWidth: 120,
tabWidth: 2,
};
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Lyoha Plotinka

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
99 changes: 98 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,98 @@
# images-pptx
# images-pptx

### A simple and blazing-fast javascript library for creating PPTX presentation from list of images

If you have a set of raster picture files (for example, after converting PDF to JPG's) and you want to nicely wrap them into PowerPoint presentation–**images-pptx** is everything that you need.

Use it with pure Node.js or TypeScript: library is written on TS and has all typings.

#### Currently works:
| **Node.js** | **Browser** | **CLI** |
| :------------: | :------------: | :------------: |
| Yes | WIP | Yes |

------------


### Installation
Via `npm`:
```bash
npm install --save images-pptx
```

### Usage
Add it to your project:
```javascript
// JavaScript
const ImagesPptx = require('images-pptx')
// TypeScript
import * as ImagesPptx from 'images-pptx'
// or, for TypeScript
import { createPptx } from 'images-pptx';
```
After that, you can use it like this:
```javascript
await ImagesPptx.createPptx(options)
```

Options are:

| **Option** | **Description** |
| :------------ | :------------ |
| pictures | Array of full paths to images (array of string) or single string to the directory where image files are placed |
| saveTo | Path to the directory (string) where .pptx file will be created |
| pptxFileName | Name of .pptx file (string) (default is "presentation.pptx" |
| extension | Extension of pictures (string, default: "jpg") which will be used in pptx (f.e. "jpg") |
| native | Boolean (default is `false`). Forces `images-pptx` use native OS commands, such as `cp` or `rm` on Mac and Linux instead of Node-based solutions. This solution can be a bit faster. **WARNING to Windows users:** this functionality was not tested correctly on Windows yet. |
| meta | Meta fields for presentation (see below)
Example usage:
```javascript
await ImagesPptx.createPptx({
pictures: '/Users/username/Pictures',
saveTo: '/Users/username/Presentation',
pptxFileName: 'Our great party.pptx',
extension: 'png',
native: true,
meta: {
author: 'Lyoha Plotinka',
title: 'Our great party!',
revision: 2,
createdAt: '2020-09-08T10:24:09.658Z'
}
})
```
This will generate file `/Users/username/Presentation/Our great party.pptx` with all the .png files from `/Users/username/Pictures`.

For every key in `meta` objects there are default values:
* `Images-pptx presentation` from `title`;
* `Images-pptx` for `author`;
* `1` for `revision`;
* Output from `new Date().toISOString()` for `createdAt`

### CLI usage
You can use `images-pptx` as command-line app. Install it globally or call it from node_modules folder.
For example:
```bash
npm install -g images-pptx
# after installing
images-pptx --help
# ...all usage options printed next
```

### How fast is it?
All test were made on MacOS, using `console.time` and `console.timeEnd`

| Options | Result |
| :------------ | :------------ |
| 3 pictures, ~8.5mb total; native: false; directory with extension as a path | 453.053ms |
| 3 pictures, ~8.5mb total; native: true; directory with extension as a path | 335.393ms |
| 27 pictures, ~49mb total; native: false; directory with extension as a path | 2518.479ms |
| 27 pictures, ~49mb total; native: true; directory with extension as a path | 1893.986ms |
| 3 pictures, ~8.5mb total; native: false; array of direct paths | 323.845ms |

### TODO
1. Browser version of `images-pptx`
2. Proportional resizing of pictures

### Found a bug?
Feel free to contribute, create an issue or contact me directly. All my contacts are availabe on [my website](https://lyoha.info)
13 changes: 13 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
globals: {
'ts-jest': {
tsConfig: 'tsconfig.json',
},
},
moduleFileExtensions: ['ts', 'js'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
},
testRegex: '(./tests/.*\\.(test|spec))\\.(jsx?|tsx?)$',
testEnvironment: 'node',
}
71 changes: 71 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"name": "@walrus/images-pptx",
"version": "1.0.0",
"description": "A simple javascript library for creating PPTX presentation from list of images",
"main": "lib/index.js",
"scripts": {
"build": "tsc",
"dev": "tsc --watch",
"lint": "eslint ./src ./tests --ext .ts,.js --fix",
"test": "jest",
"release": "walrus release"
},
"keywords": [
"pptx",
"images",
"node"
],
"repository": {
"type": "git",
"url": "https://github.com/lyohaplotinka/images-pptx.git"
},
"homepage": "https://github.com/lyohaplotinka/images-pptx",
"bugs": {
"url": "https://github.com/lyohaplotinka/images-pptx/issues"
},
"author": "Lyoha Plotinka",
"license": "MIT",
"devDependencies": {
"@types/archiver": "^3.1.0",
"@types/fs-extra": "^9.0.13",
"@types/jest": "^25.2.3",
"@types/node": "^13.13.16",
"@types/rimraf": "^2.0.4",
"@types/swig": "0.0.29",
"@types/yargs": "^15.0.5",
"@typescript-eslint/eslint-plugin": "^2.34.0",
"@typescript-eslint/parser": "^2.34.0",
"@walrus/cli": "^1.3.4",
"@walrus/plugin-release": "^1.14.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-prettier": "^3.1.4",
"husky": "^4.3.0",
"jest": "^25.5.4",
"minimist": ">=1.2.2",
"prettier": "^1.19.1",
"ts-jest": "^25.5.1",
"typescript": "^3.9.7",
"uglify-js": "^3.10.4"
},
"dependencies": {
"archiver": "^3.1.1",
"fs-extra": "^10.0.0",
"rimraf": "^3.0.2",
"swig": "^1.4.2",
"yargs": "^15.4.1"
},
"husky": {
"hooks": {
"pre-commit": "npm run lint",
"pre-push": "npm run test"
}
},
"bin": {
"images-pptx": "./lib/cli.js"
},
"publishConfig": {
"registry": "https://registry.npmjs.org",
"access": "public"
}
}
2 changes: 2 additions & 0 deletions shared/_rels/.rels
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId3" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail" Target="docProps/thumbnail.jpeg"/><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="ppt/presentation.xml"/><Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/></Relationships>
51 changes: 51 additions & 0 deletions shared/docProps/app.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"
xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
<Template>Office Theme</Template>
<TotalTime>4</TotalTime>
<Words>0</Words>
<Application>Microsoft Office PowerPoint</Application>
<PresentationFormat>On-screen Show (4:3)</PresentationFormat>
<Paragraphs>0</Paragraphs>
<Slides>2</Slides>
<Notes>0</Notes>
<HiddenSlides>0</HiddenSlides>
<MMClips>0</MMClips>
<ScaleCrop>false</ScaleCrop>
<HeadingPairs>
<vt:vector size="6" baseType="variant">
<vt:variant>
<vt:lpstr>Fonts Used</vt:lpstr>
</vt:variant>
<vt:variant>
<vt:i4>3</vt:i4>
</vt:variant>
<vt:variant>
<vt:lpstr>Theme</vt:lpstr>
</vt:variant>
<vt:variant>
<vt:i4>1</vt:i4>
</vt:variant>
<vt:variant>
<vt:lpstr>Slide Titles</vt:lpstr>
</vt:variant>
<vt:variant>
<vt:i4>2</vt:i4>
</vt:variant>
</vt:vector>
</HeadingPairs>
<TitlesOfParts>
<vt:vector size="6" baseType="lpstr">
<vt:lpstr>Arial</vt:lpstr>
<vt:lpstr>Calibri</vt:lpstr>
<vt:lpstr>Calibri Light</vt:lpstr>
<vt:lpstr>Office Theme</vt:lpstr>
<vt:lpstr>PowerPoint Presentation</vt:lpstr>
<vt:lpstr>PowerPoint Presentation</vt:lpstr>
</vt:vector>
</TitlesOfParts>
<LinksUpToDate>false</LinksUpToDate>
<SharedDoc>false</SharedDoc>
<HyperlinksChanged>false</HyperlinksChanged>
<AppVersion>15.0000</AppVersion>
</Properties>
Binary file added shared/docProps/thumbnail.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions shared/ppt/presProps.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<p:presentationPr xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main">
<p:extLst>
<p:ext uri="{E76CE94A-603C-4142-B9EB-6D1370010A27}">
<p14:discardImageEditData xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main" val="0"/>
</p:ext>
<p:ext uri="{D31A062A-798A-4329-ABDD-BBA856620510}">
<p14:defaultImageDpi xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main" val="220"/>
</p:ext>
<p:ext uri="{FD5EFAAD-0ECE-453E-9831-46B23BE46B34}">
<p15:chartTrackingRefBased xmlns:p15="http://schemas.microsoft.com/office/powerpoint/2012/main" val="1"/>
</p:ext>
</p:extLst>
</p:presentationPr>
2 changes: 2 additions & 0 deletions shared/ppt/slideLayouts/_rels/slideLayout1.xml.rels
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideMaster" Target="../slideMasters/slideMaster1.xml"/></Relationships>
2 changes: 2 additions & 0 deletions shared/ppt/slideLayouts/slideLayout1.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<p:sldLayout xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" type="blank" preserve="1"><p:cSld name="Blank"><p:spTree><p:nvGrpSpPr><p:cNvPr id="1" name=""/><p:cNvGrpSpPr/><p:nvPr/></p:nvGrpSpPr><p:grpSpPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="0" cy="0"/><a:chOff x="0" y="0"/><a:chExt cx="0" cy="0"/></a:xfrm></p:grpSpPr><p:sp><p:nvSpPr><p:cNvPr id="2" name="Date Placeholder 1"/><p:cNvSpPr><a:spLocks noGrp="1"/></p:cNvSpPr><p:nvPr><p:ph type="dt" sz="half" idx="10"/></p:nvPr></p:nvSpPr><p:spPr/><p:txBody><a:bodyPr/><a:lstStyle/><a:p><a:fld id="{C764DE79-268F-4C1A-8933-263129D2AF90}" type="datetimeFigureOut"><a:rPr lang="en-US" dirty="0"/><a:t>1/27/2016</a:t></a:fld><a:endParaRPr lang="en-US" dirty="0"/></a:p></p:txBody></p:sp><p:sp><p:nvSpPr><p:cNvPr id="3" name="Footer Placeholder 2"/><p:cNvSpPr><a:spLocks noGrp="1"/></p:cNvSpPr><p:nvPr><p:ph type="ftr" sz="quarter" idx="11"/></p:nvPr></p:nvSpPr><p:spPr/><p:txBody><a:bodyPr/><a:lstStyle/><a:p><a:endParaRPr lang="en-US" dirty="0"/></a:p></p:txBody></p:sp><p:sp><p:nvSpPr><p:cNvPr id="4" name="Slide Number Placeholder 3"/><p:cNvSpPr><a:spLocks noGrp="1"/></p:cNvSpPr><p:nvPr><p:ph type="sldNum" sz="quarter" idx="12"/></p:nvPr></p:nvSpPr><p:spPr/><p:txBody><a:bodyPr/><a:lstStyle/><a:p><a:fld id="{48F63A3B-78C7-47BE-AE5E-E10140E04643}" type="slidenum"><a:rPr lang="en-US" dirty="0"/><a:t>‹#›</a:t></a:fld><a:endParaRPr lang="en-US" dirty="0"/></a:p></p:txBody></p:sp></p:spTree><p:extLst><p:ext uri="{BB962C8B-B14F-4D97-AF65-F5344CB8AC3E}"><p14:creationId xmlns:p14="http://schemas.microsoft.com/office/powerpoint/2010/main" val="3588940663"/></p:ext></p:extLst></p:cSld><p:clrMapOvr><a:masterClrMapping/></p:clrMapOvr></p:sldLayout>
2 changes: 2 additions & 0 deletions shared/ppt/slideMasters/_rels/slideMaster1.xml.rels
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="../theme/theme1.xml"/><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout" Target="../slideLayouts/slideLayout1.xml"/></Relationships>
Loading

0 comments on commit 6478484

Please sign in to comment.