npm module works!

This commit is contained in:
daniel-j 2016-08-14 22:42:57 +02:00
parent 422e0804a1
commit daf4c4ec7f
12 changed files with 143 additions and 104 deletions

2
.gitignore vendored
View file

@ -1,3 +1,4 @@
.DS_Store
node_modules/
extension/fimfic2epub.js
@ -7,4 +8,5 @@ extension.pem
extension.xpi
extension.zip
fimfic2epub.safariextension/
fimfic2epub.js
*.epub

View file

@ -1,15 +0,0 @@
# git ignore
.DS_Store
node_modules/
extension/fimfic2epub.js
extension/eventPage.js
extension.crx
extension.pem
extension.xpi
extension.zip
fimfic2epub.safariextension/
*.epub
# npm ignore
extension/
assets/

11
bin/fimfic2epub Executable file
View file

@ -0,0 +1,11 @@
#!/usr/bin/env node
const FimFic2Epub = require('../fimfic2epub')
const STORY_ID = process.argv[2]
const ffc = new FimFic2Epub(STORY_ID)
ffc.download().then(() => {
ffc.saveStory()
})

View file

@ -1,21 +0,0 @@
#!/usr/bin/env node
require("babel-register")
// have to load these from the outside so webpack doesn't try to include them
process.fs = require('fs')
process.path = require('path')
process.request = require('request')
process.stylus = require('stylus')
process.tidy = require('tidy-html5').tidy_html5
process.sizeOf = require('image-size')
const FimFic2Epub = require('../src/FimFic2Epub').default
const STORY_ID = process.argv[2]
const ffc = new FimFic2Epub(STORY_ID)
ffc.download().then(() => {
ffc.saveStory()
})

View file

@ -4,7 +4,7 @@
"name": "fimfic2epub",
"short_name": "fimfic2epub",
"description": "Improved EPUB exporter for Fimfiction",
"version": "1.0.4",
"version": "1.0.9",
"icons": {
"128": "icon-128.png"

View file

@ -20,40 +20,43 @@ import webpackConfig from './webpack.config.babel.js'
const sequence = Sequence.use(gulp)
let inProduction = process.env.NODE_ENV === 'production' || process.argv.indexOf('-p') !== -1
const inProduction = process.env.NODE_ENV === 'production' || process.argv.indexOf('-p') !== -1
let watchOpts = {
readDelay: 500,
verbose: true
}
if (inProduction) {
webpackConfig.plugins.push(new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}))
webpackConfig.plugins.push(new webpack.optimize.DedupePlugin())
/*
webpackConfig.plugins.push(new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
screw_ie8: true
},
comments: false,
mangle: {
screw_ie8: true
},
screw_ie8: true,
sourceMap: false
}))
*/
}
webpackConfig.forEach((c) => {
if (inProduction) {
c.plugins.push(new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}))
c.plugins.push(new webpack.optimize.DedupePlugin())
/*
c.plugins.push(new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
screw_ie8: true
},
comments: false,
mangle: {
screw_ie8: true
},
screw_ie8: true,
sourceMap: false
}))
*/
}
Object.assign({}, c, {
cache: {},
devtool: inProduction ? null : 'inline-source-map',
debug: !inProduction
})
})
let wpCompiler = webpack(Object.assign({}, webpackConfig, {
cache: {},
devtool: inProduction ? null : 'inline-source-map',
debug: !inProduction
}))
const wpCompiler = webpack(webpackConfig)
function webpackTask (callback) {
// run webpack

View file

@ -1,31 +1,38 @@
{
"name": "fimfic2epub",
"version": "1.0.7",
"version": "1.0.9",
"description": "Tool to generate EPUB ebooks from fimfiction stories",
"author": "djazz",
"scripts": {
"build": "gulp -p"
},
"bin": {
"fimfic2epub": "./bin/fimfic2epub.js"
"fimfic2epub": "./bin/fimfic2epub"
},
"main": "fimfic2epub.js",
"engines": {
"node": ">=0.6.0"
},
"files": [
"fimfic2epub.js",
"bin/"
],
"dependencies": {
"babel-register": "^6.11.6",
"babel-preset-node6": "^11.0.0",
"detect-node": "^2.0.3",
"escape-string-regexp": "^1.0.5",
"file-saver": "^1.3.2",
"html-entities": "^1.2.0",
"image-size": "^0.5.0",
"jszip": "^3.1.1",
"mithril": "^0.2.5",
"pretty-data": "^0.40.0",
"request": "^2.74.0",
"stylus": "^0.54.5",
"tidy-html5": "^0.1.1",
"zero-fill": "^2.2.3"
},
"devDependencies": {
"file-saver": "^1.3.2",
"babel-register": "^6.11.6",
"babel-preset-node6": "^11.0.0",
"babel-core": "^6.13.2",
"babel-loader": "^6.2.4",
"del": "^2.2.2",
@ -41,8 +48,10 @@
"raw-loader": "^0.5.1",
"run-sequence": "^1.2.2",
"standard": "^7.1.2",
"stylus": "^0.54.5",
"stylus-loader": "^2.2.0",
"webpack": "^2.1.0-beta.13"
"webpack": "^2.1.0-beta.13",
"webpack-node-externals": "^1.3.3"
},
"standard": {
"env": {

View file

@ -1,7 +1,6 @@
import JSZip from 'jszip'
import escapeStringRegexp from 'escape-string-regexp'
import { saveAs } from 'file-saver'
import zeroFill from 'zero-fill'
import { XmlEntities } from 'html-entities'
@ -23,7 +22,7 @@ function blobToDataURL (blob, callback) {
a.readAsDataURL(blob)
}
export default class FimFic2Epub {
module.exports = class FimFic2Epub {
constructor (storyId) {
this.storyId = storyId
@ -190,8 +189,9 @@ export default class FimFic2Epub {
this.processStory(resolve, reject, coverImage)
}, false)
} else {
const sizeOf = require('image-size')
fetchRemote(this.storyInfo.full_image, (data, type) => {
this.processStory(resolve, reject, process.sizeOf(data))
this.processStory(resolve, reject, sizeOf(data))
}, 'buffer')
}
} else {
@ -374,11 +374,21 @@ export default class FimFic2Epub {
}
saveStory () {
console.log('Saving epub...')
let filename = this.storyInfo.title + ' by ' + this.storyInfo.author.name + '.epub'
console.log('Saving epub...')
if (isNode) {
const fs = require('fs')
/*this.zip.generateAsync({
type: 'nodebuffer',
mimeType: 'application/epub+zip',
compression: 'DEFLATE',
compressionOptions: {level: 9}
}).then((epub) => {
console.log(epub)
})*/
this.zip
.generateNodeStream({
type: 'nodebuffer',
@ -387,10 +397,13 @@ export default class FimFic2Epub {
compression: 'DEFLATE',
compressionOptions: {level: 9}
})
.pipe(process.fs.createWriteStream(filename))
.pipe(fs.createWriteStream(filename))
.on('finish', () => {
console.log('Saved epub as', filename)
})
.on('error', (err) => {
throw err
})
return
}
if (typeof safari !== 'undefined') {
@ -399,6 +412,7 @@ export default class FimFic2Epub {
alert('Rename downloaded file to .epub')
})
} else {
const saveAs = require('file-saver')
saveAs(this.cachedBlob, filename)
}
}

View file

@ -1,16 +1,17 @@
import m from 'mithril'
import render from './lib/mithril-node-render'
import isNode from 'detect-node'
import fetch from './fetch'
import { tidyOptions, youtubeKey } from './constants'
import isNode from 'detect-node'
let tidy
if (!isNode) {
tidy = require('exports?tidy_html5!tidy-html5')
} else {
tidy = process.tidy
tidy = require('tidy-html5').tidy_html5
}
export function cleanMarkup (html, callback) {

View file

@ -2,7 +2,8 @@
import isNode from 'detect-node'
function fetchNode (url, cb, responseType) {
process.request({
const request = require('request')
request({
url: url,
encoding: responseType ? null : 'utf8',
headers: {

View file

@ -1,25 +1,8 @@
import isNode from 'detect-node'
let styleCss, coverstyleCss, titlestyleCss
if (!isNode) {
styleCss = require('./style')
coverstyleCss = require('./coverstyle')
titlestyleCss = require('./titlestyle')
} else {
process.stylus.render(process.fs.readFileSync(process.path.join(__dirname, './style.styl'), 'utf8'), (err, css) => {
if (err) throw err
styleCss = css
})
process.stylus.render(process.fs.readFileSync(process.path.join(__dirname, './coverstyle.styl'), 'utf8'), (err, css) => {
if (err) throw err
coverstyleCss = css
})
process.stylus.render(process.fs.readFileSync(process.path.join(__dirname, './titlestyle.styl'), 'utf8'), (err, css) => {
if (err) throw err
titlestyleCss = css
})
}
styleCss = require('./style')
coverstyleCss = require('./coverstyle')
titlestyleCss = require('./titlestyle')
export { styleCss, coverstyleCss, titlestyleCss }

View file

@ -1,17 +1,20 @@
import path from 'path'
import nodeExternals from 'webpack-node-externals'
// let inProduction = process.env.NODE_ENV === 'production' || process.argv.indexOf('-p') !== -1
export default {
const bundleExtensionConfig = {
entry: {
fimfic2epub: ['./src/main'],
eventPage: ['./src/eventPage']
eventPage: ['./src/eventPage'],
fimfic2epub: ['./src/main']
},
output: {
path: path.join(__dirname, '/'),
filename: './extension/[name].js'
},
module: {
loaders: [
/*
@ -39,8 +42,56 @@ export default {
]
},
plugins: [],
externals: ['request', 'fs', 'tidy-html5', 'image-size'],
plugins: [],
devtool: 'inline-source-map',
debug: true
}
const bundleNpmModuleConfig = {
entry: './src/FimFic2Epub',
output: {
path: path.join(__dirname, '/'),
filename: './fimfic2epub.js',
libraryTarget: 'commonjs2'
},
target: 'node',
module: {
loaders: [
/*
{
test: /\.js$/, loader: 'babel', exclude: /node_modules/, query: {
sourceMaps: inProduction
}
},
*/
{
test: /\.styl$/,
loader: 'raw-loader!stylus-loader'
}
],
noParse: [
/[\/\\]node_modules[\/\\]tidy-html5[\/\\]tidy\.js$/
]
},
resolve: {
extensions: ['', '.js', '.json', '.styl'],
modules: [
path.resolve('./src'),
'node_modules'
]
},
externals: [nodeExternals(), 'exports?tidy_html5!tidy-html5'],
plugins: [],
devtool: 'inline-source-map',
debug: true
}
export default [bundleExtensionConfig, bundleNpmModuleConfig]