Skip to content

Commit

Permalink
no need to json-loader anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
Ardalan Amini committed Dec 26, 2017
1 parent 9bfc391 commit cc58cd7
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 7 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ A **TypeScript Ready** universal validation library for developers
#### require / import

```javascript
const Verifications = require('verifications');
const Verifications = require('verifications').default;
// or
import Verifications from 'verifications';
```
Expand Down Expand Up @@ -96,5 +96,3 @@ var isCreditCardValid = Verifications
- 46 active issuers are supported

*****

**for client side usage you're going to need json-loader or something...**
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
"description": "universal verification library for developers",
"main": "dist/index.js",
"scripts": {
"prepublish": "npm run build && npm run files",
"prepare": "./scripts/prepare.js",
"build": "tsc",
"files": "copyfiles -u 1 ./src/**/*.json ./dist",
"test": "echo \"Error: no test specified\" && exit 1"
},
"files": [
Expand Down Expand Up @@ -89,7 +88,9 @@
"url": "https://github.com/ardalanamini/verifications/issues"
},
"devDependencies": {
"copyfiles": "^1.2.0",
"typescript": "^2.6.2"
"fs-readdir-recursive": "^1.1.0",
"rimraf": "^2.6.2",
"typescript": "^2.6.2",
"uglify-js": "^3.3.2"
}
}
57 changes: 57 additions & 0 deletions scripts/prepare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env node

const path = require('path')
const rimraf = require('rimraf')
const {spawn} = require('child_process')
const fs = require('fs')
const readdir = require('fs-readdir-recursive')
const Uglify = require('uglify-js')

rimraf(path.join(__dirname, '..', 'dist'), (err) => {
if (err) throw new Error(err)

const tsc = spawn(path.join(__dirname, '..', 'node_modules', '.bin', 'tsc'))

tsc.stdout.on('data', (data) => {
console.log(`stdout: ${data}`)
})

tsc.stderr.on('data', (data) => console.log(`stderr: ${data}`))

tsc.on('close', (code) => {
const distDir = path.join(__dirname, '..', 'dist')

const distFileNames = readdir(distDir, (filename) => /(?<!\.ts)$/.test(filename))

distFileNames.map((filename) => {
let filePath = path.join(distDir, filename)
let content = fs.readFileSync(filePath, 'utf8')

const jsonFiles = content.match(/require\("(.*\.json)"\)/g)
if (jsonFiles) {
for (let jsonFile of jsonFiles) {
let jsonContent = fs.readFileSync(
path.join(
path.dirname(filePath.replace(/\/dist\//, '/src/')),
/"(.*\.json)"/.exec(jsonFile)[1]
),
'utf8'
)

content = content.replace(jsonFile, jsonContent)
}
}

content = Uglify.minify(content, {
toplevel: true,
})

if (content.error) throw new Error(content.error)

fs.writeFileSync(filePath, content.code, 'utf8')
})

if (code === 0) console.log('prepared and ready to go ;)')
else console.log(`child process exited with code ${code}`)
})
})
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"target": "es5",
"module": "commonjs",
"declaration": true,
"rootDir": "./src",
"outDir": "./dist",
"strict": true
}
Expand Down

0 comments on commit cc58cd7

Please sign in to comment.