cordova-import-npm
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -0,3 +1,5 @@ | ||
const fs = require('fs') | ||
const fse = require('fs-extra') | ||
const path = require('path') | ||
const colors = require('colors/safe') | ||
@@ -13,20 +15,29 @@ const twoSpaces = ' ' // for log indentation | ||
console.log(twoSpaces + 'Project root directory: ' + projectRoot) | ||
copyFile('jquery', path.join('dist', 'jquery.min.js'), path.join('js', 'res', 'jquery.min.js')) | ||
copyFile('bootstrap', path.join('dist', 'js', 'bootstrap.min.js'), path.join('js', 'res', 'bootstrap.min.js')) | ||
copyFile('bootstrap', path.join('dist', 'css', 'bootstrap.min.css'), path.join('css', 'res', 'bootstrap.min.css')) | ||
var npmFilesToImportFileName = context.isThisATest ? 'npmFilesToImport_Example.json' : 'npmFilesToImport.json' | ||
console.log(twoSpaces + 'Importing npm files to copy from ' + colors.cyan(npmFilesToImportFileName) + '\n') | ||
copyFile('jAlert', path.join('dist', 'jAlert.min.js'), path.join('js', 'res', 'jAlert.min.js')) | ||
copyFile('jAlert', path.join('dist', 'jAlert.css'), path.join('css', 'res', 'jAlert.css')) | ||
var rawdata = fs.readFileSync(npmFilesToImportFileName, 'utf8') | ||
try { | ||
var npmFilesToImport = JSON.parse(rawdata); | ||
} catch(e) { | ||
console.log(colors.red(`\nERROR: Your JSON file "${npmFilesToImportFileName}" has syntax errors:\n`)) | ||
console.log(rawdata) | ||
process.exit(1) | ||
} | ||
copyFile('leaflet', path.join('dist', 'leaflet.js'), path.join('js', 'res', 'leaflet.js')) | ||
copyFile('leaflet', path.join('dist', 'leaflet.css'), path.join('css', 'res', 'leaflet.css')) | ||
copyFile('leaflet.markercluster', path.join('dist', 'leaflet.markercluster.js'), path.join('js', 'res', 'leaflet.markercluster.js')) | ||
copyFile('leaflet.markercluster', path.join('dist', 'MarkerCluster.css'), path.join('css', 'res', 'MarkerCluster.css')) | ||
copyFile('leaflet.markercluster', path.join('dist', 'MarkerCluster.Default.css'), path.join('css', 'res', 'MarkerCluster.Default.css')) | ||
copyFile('crypto-js', path.join('crypto-js.js'), path.join('js', 'res', 'crypto-js.js')) | ||
copyFile('google-android-app-ids', path.join('dist', 'google-app-ids.json'), path.join('js', 'res', 'google-app-ids.json')) | ||
for (let npmPackage in npmFilesToImport) { | ||
let npmFiles = npmFilesToImport[npmPackage] | ||
if (!Array.isArray(npmFiles) && typeof npmFiles === 'object') { | ||
copyFile(npmPackage, path.join.apply(this, npmFiles.from), path.join.apply(this, npmFiles.to)) | ||
} else if (Array.isArray(npmFiles)){ | ||
for (let i = 0; i < npmFiles.length; i++) { | ||
npmFilesI = npmFiles[i] | ||
copyFile(npmPackage, path.join.apply(this, npmFilesI.from), path.join.apply(this, npmFilesI.to)) | ||
} | ||
} else { | ||
console.log(colors.red(`JSON file "${npmFilesToImportFileName}" has good syntax but fails template, see readme on https://www.npmjs.com/package/cordova-import-npm`)) | ||
process.exit(1) | ||
} | ||
} | ||
} | ||
@@ -45,3 +56,3 @@ | ||
const consoleMsg = npmPackage + ': ' + | ||
const consoleMsg = colors.cyan(npmPackage) + ': ' + | ||
path.relative(projectRoot, fileOriginFullPath) + ' -> ' + | ||
@@ -48,0 +59,0 @@ path.relative(projectRoot, fileDestFullPath) |
@@ -14,4 +14,4 @@ { | ||
"to": ["css", "res", "bootstrap.min.css"] | ||
}, | ||
], | ||
} | ||
] | ||
} |
{ | ||
"name": "cordova-import-npm", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Import files from npm packages into your cordova www directory automatically, upon cordova prepare or cordova build", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "npm i jquery bootstrap && node test.js && npm remove jquery bootstrap && echo \"TEST OK\"", | ||
"postinstall": "node onInstall.js" | ||
}, | ||
@@ -16,3 +17,7 @@ "keywords": [ | ||
"author": "João Pimentel Ferreira", | ||
"license": "GPL-3.0" | ||
"license": "GPL-3.0", | ||
"dependencies": { | ||
"colors": "^1.4.0", | ||
"fs-extra": "^9.1.0" | ||
} | ||
} |
@@ -13,3 +13,3 @@ # On development, don't use this yet... | ||
It will add a hook at hooks/ and edit your `config.xml` accordingly, such that npm files that you define will be imported upon `cordova prepare` or `cordova build` | ||
It will add a hook at your hooks directory (if you have none defined in `config.xml` it will use `hooks/`) and edit your `config.xml` accordingly, such that npm files that you set will be imported upon `cordova prepare` or `cordova build` | ||
@@ -34,6 +34,7 @@ ## Settings | ||
Imagine you want the latest jquery and bootsrap files on your `www/js/res/` and `www/css/res/ directories`. Just run | ||
Imagine you wanted the latest jquery and bootsrap files on your `www/js/res/` and `www/css/res/` directories. Just run | ||
``` | ||
npm i cordova-import-npm | ||
npm i jquery bootstrap | ||
``` | ||
@@ -62,2 +63,2 @@ | ||
Then run `cordova prepare` or `cordova build` and the npm files will be copied. | ||
Then run `cordova prepare` or `cordova build` and the npm files will be copied before anything else is processed. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
40946
8
81
1
62
2
1
5
+ Addedcolors@^1.4.0
+ Addedfs-extra@^9.1.0
+ Addedat-least-node@1.0.0(transitive)
+ Addedcolors@1.4.0(transitive)
+ Addedfs-extra@9.1.0(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedjsonfile@6.1.0(transitive)
+ Addeduniversalify@2.0.1(transitive)