Skip to content

Instantly share code, notes, and snippets.

@clint74
Last active March 2, 2016 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clint74/e9d6036140e950b28933 to your computer and use it in GitHub Desktop.
Save clint74/e9d6036140e950b28933 to your computer and use it in GitHub Desktop.
this script is used to automate the task of transform cordova plugin files into utf-8 (BOM - byte order mark)
"""
#C:\dev\phonegap\
this script is used to automate the task of transform
cordova plugin files into utf-8 (BOM - byte order mark)
* This is specfic to cordova platform windows
**Windows App Certification Kit complains about encoding of files :-(
and does not allow to public your app on Windows Store until
every file was ok.
"""
import os
import codecs
TIPOS = ['.js','.html','.css']
PATH = 'C:/temp/plugins'
BOM_SIZE = len(codecs.BOM_UTF8)
def addUTF8Bom(filename):
f = codecs.open(filename, 'r', 'utf-8')
content = f.read()
f.close()
if codecs.BOM_UTF8 in content[:BOM_SIZE].encode('utf-8'):
#do nothing
print 'O arquivo %s ja esta em uft-8 BOM' %filename
else:
print '[ %s ] => UTF-8 BOM' %filename
f2 = codecs.open(filename, 'w', 'utf-8')
f2.write(u'\ufeff')
f2.write(content)
f2.close()
for tipo in TIPOS:
print "iniciando conversao do tipo %s" %tipo
for root, dirs, files in os.walk(PATH):
for file in files:
if file.endswith(tipo):
addUTF8Bom(os.path.join(root, file))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment