Commit ae2f1b7a authored by limingzhe's avatar limingzhe

fix: 新脚手架

parent 8792548f

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

No preview for this file type
/node_modules
/dist
/publish
/publish/form /publish/form
/form/publish/*.zip
/publish/play /publish/play
/publish/node_modules /node_modules
/publish/publish/play /build_android
/publish/publish/form /build_ios
/publish/publish/*.zip /build_web_desktop
#/////////////////////////////////////////////////////////////////////////////
# Fireball Projects
#/////////////////////////////////////////////////////////////////////////////
/library/
/temp/
/local/
/build/
#/////////////////////////////////////////////////////////////////////////////
# npm files
#/////////////////////////////////////////////////////////////////////////////
npm-debug.log
node_modules/
#/////////////////////////////////////////////////////////////////////////////
# Logs and databases
#/////////////////////////////////////////////////////////////////////////////
*.log
*.sql
*.sqlite
#/////////////////////////////////////////////////////////////////////////////
# files for debugger
#/////////////////////////////////////////////////////////////////////////////
*.sln
*.csproj
*.pidb
*.unityproj
*.suo
#/////////////////////////////////////////////////////////////////////////////
# OS generated files
#/////////////////////////////////////////////////////////////////////////////
.DS_Store
ehthumbs.db
Thumbs.db
#/////////////////////////////////////////////////////////////////////////////
# WebStorm files
#/////////////////////////////////////////////////////////////////////////////
.idea/
#//////////////////////////
# VS Code files
#//////////////////////////
.vscode/
# cocos-generator
cocos creator技术框架下的H5互动模板框架脚手架,基于cocos creator实现快速开发基于绘玩云的H5互动课件。
# 使用简介
## 前期准备
* git下载 https://git-scm.com/downloads
* nodejs下载 https://nodejs.org/zh-cn/download/
* 谷歌浏览器下载 https://www.google.cn/chrome/
都下载最新版就行,然后默认安装就可以
## 生成项目
* 登录绘玩云课件开发平台:http://staging-teach.ireadabc.com/
* 点击“登录账号,查看我的课件”
* 输入测试的用户名/密码:developers/12345678
* 在右上角“个人中心”的下拉菜单里,点击“我的模板” 菜单,然后点击“新建模板”, 填写必要的信息,在“技术选型”一项上选择“Cocos”
* 点击“确定”后,列表页就会出现一个新生成的模板项目
* 在项目的卡片下找到“开发”按钮,则会弹出相对应的git地址
## 获取并启动项目
```
// xxx 是上面项目对应的Git地址
git clone xxx
cd 项目名称/
npm install
```
* 打开Cocos Creator, 点击项目(Project)=> 添加(Add) 在打开的对话框里面选择进入clone下来的项目,选择本项目,然后打开
* 基于项目里“this.data”进行常规的Cocos开发 (其中this.data是云平台的配置数据)
* 注意 Cocos Creator 版本必须是2.4.5
## 本地调试
在基于CocosCreator的开发与预览调试都完成之后,需要进行模板放到云平台上的数据配置等方面的调试,还要进行cocos打包到IOS/Android真机上的调试,为了更方便与高效的调试,我们提供了如下工具进行调试与测试
### 普通模板
* 启动本地服务
```
npm start
```
* 打开浏览器:http://staging-teach.ireadabc.com/template_ci/debug
* 点击右上角齿轮,选择技术选型、调试模式选择“普通”
### 互动模板
* 找到项目根路径下 index.html 文件
* 在引入JS的位置将air.js改为air_online_open.js
* 启动本地服务
```
npm start
```
* 打开浏览器:http://staging-teach.ireadabc.com/template_ci/debug
* 点击右上角齿轮,选择技术选型、调试模式选择“互动”
* 左侧老师、右侧学生
### 真机调试
* 下载模板调试专用app
http://download-iplayabc.oss-cn-beijing.aliyuncs.com/iDebugABC.apk
![avatar](http://staging-teach.cdn.ireadabc.com/084f2f95-8213-4c5a-8c46-b194819d7677.png)
* 启动本地服务
```
npm start
```
* 手机和电脑连接同一个Wifi
* 打开调试app,根据提示输入IP地址,点击开始就可以在手机上预览模板了
* 使用 this.log("==调试信息=="); 可以打印日志进行必要的调试
\ No newline at end of file
{"ver":"1.1.2","uuid":"fdff4116-c56c-457b-8de8-ff8355cde84e","isBundle":false,"bundleName":"","priority":1,"compressionType":{},"optimizeHotUpdate":{},"inlineSpriteFrames":{},"isRemoteBundle":{"ios":false,"android":false},"subMetas":{}}
\ No newline at end of file
{ {
"ver": "1.2.7", "ver": "1.2.9",
"uuid": "30049277-60ee-4b53-b4a2-718e207e491a", "uuid": "30049277-60ee-4b53-b4a2-718e207e491a",
"optimizationPolicy": "AUTO", "optimizationPolicy": "AUTO",
"asyncLoadAssets": false, "asyncLoadAssets": false,
......
...@@ -57,8 +57,8 @@ ...@@ -57,8 +57,8 @@
"_is3DNode": true, "_is3DNode": true,
"_groupIndex": 0, "_groupIndex": 0,
"groupIndex": 0, "groupIndex": 0,
"autoReleaseAssets": true, "autoReleaseAssets": false,
"_id": "c3f18614-c716-4f1f-899f-09f073ac6c43" "_id": "0a39a6bf-a4e5-4550-892d-d8a83f5dda1e"
}, },
{ {
"__type__": "cc.Node", "__type__": "cc.Node",
...@@ -4214,7 +4214,6 @@ ...@@ -4214,7 +4214,6 @@
"_materials": [], "_materials": [],
"_srcBlendFactor": 770, "_srcBlendFactor": 770,
"_dstBlendFactor": 771, "_dstBlendFactor": 771,
"_useOriginalSize": true,
"_string": "", "_string": "",
"_N$string": "", "_N$string": "",
"_fontSize": 40, "_fontSize": 40,
...@@ -4388,6 +4387,7 @@ ...@@ -4388,6 +4387,7 @@
"_volume": 1, "_volume": 1,
"_mute": false, "_mute": false,
"_loop": false, "_loop": false,
"_firstlyEnabled": true,
"playOnLoad": false, "playOnLoad": false,
"preload": false, "preload": false,
"_id": "d4vFHBRrZKbZcEOhrGGJj6" "_id": "d4vFHBRrZKbZcEOhrGGJj6"
...@@ -4468,6 +4468,7 @@ ...@@ -4468,6 +4468,7 @@
"_volume": 1, "_volume": 1,
"_mute": false, "_mute": false,
"_loop": false, "_loop": false,
"_firstlyEnabled": true,
"playOnLoad": false, "playOnLoad": false,
"preload": false, "preload": false,
"_id": "9819JdQWhPc64pw4lhL4sx" "_id": "9819JdQWhPc64pw4lhL4sx"
...@@ -4548,6 +4549,7 @@ ...@@ -4548,6 +4549,7 @@
"_volume": 1, "_volume": 1,
"_mute": false, "_mute": false,
"_loop": false, "_loop": false,
"_firstlyEnabled": true,
"playOnLoad": false, "playOnLoad": false,
"preload": false, "preload": false,
"_id": "78tKiI3cFJ5IUWTq68V2xy" "_id": "78tKiI3cFJ5IUWTq68V2xy"
...@@ -4628,6 +4630,7 @@ ...@@ -4628,6 +4630,7 @@
"_volume": 1, "_volume": 1,
"_mute": false, "_mute": false,
"_loop": false, "_loop": false,
"_firstlyEnabled": true,
"playOnLoad": false, "playOnLoad": false,
"preload": false, "preload": false,
"_id": "92iMg0c3xKeoAhkDRvLWaH" "_id": "92iMg0c3xKeoAhkDRvLWaH"
...@@ -4708,6 +4711,7 @@ ...@@ -4708,6 +4711,7 @@
"_volume": 1, "_volume": 1,
"_mute": false, "_mute": false,
"_loop": false, "_loop": false,
"_firstlyEnabled": true,
"playOnLoad": false, "playOnLoad": false,
"preload": false, "preload": false,
"_id": "09DNLutpJMoKe0mkMiz+DV" "_id": "09DNLutpJMoKe0mkMiz+DV"
...@@ -4788,6 +4792,7 @@ ...@@ -4788,6 +4792,7 @@
"_volume": 1, "_volume": 1,
"_mute": false, "_mute": false,
"_loop": false, "_loop": false,
"_firstlyEnabled": true,
"playOnLoad": false, "playOnLoad": false,
"preload": false, "preload": false,
"_id": "e843BwsyRGiZcX7u6rqC3o" "_id": "e843BwsyRGiZcX7u6rqC3o"
...@@ -4837,7 +4842,7 @@ ...@@ -4837,7 +4842,7 @@
"_id": "29zXboiXFBKoIV4PQ2liTe" "_id": "29zXboiXFBKoIV4PQ2liTe"
}, },
{ {
"__type__": "335fea4K1JFqanJyztUAUJR", "__type__": "4c0e88l0YxFj7ng7D/BrNIE",
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"node": { "node": {
...@@ -4846,6 +4851,6 @@ ...@@ -4846,6 +4851,6 @@
"_enabled": true, "_enabled": true,
"baseWidth": 1280, "baseWidth": 1280,
"baseHeight": 720, "baseHeight": 720,
"_id": "28v7Et3UdB3JZRlTOtLFi9" "_id": "a3DRw4RsdOnZYDlCeUjrbr"
} }
] ]
\ No newline at end of file
{ {
"ver": "1.2.7", "ver": "1.2.9",
"uuid": "c3f18614-c716-4f1f-899f-09f073ac6c43", "uuid": "0a39a6bf-a4e5-4550-892d-d8a83f5dda1e",
"asyncLoadAssets": false, "asyncLoadAssets": false,
"autoReleaseAssets": true, "autoReleaseAssets": false,
"subMetas": {} "subMetas": {}
} }
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
// Learn life-cycle callbacks: // Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import {playAudioByUrl, setSprNodeMaxLen, btnClickAnima} from "./util"; import {playAudioByUrl, setSprNodeMaxLen, btnClickAnima} from "../script/util";
cc.Class({ cc.Class({
extends: cc.Component, extends: cc.Component,
...@@ -200,6 +200,13 @@ cc.Class({ ...@@ -200,6 +200,13 @@ cc.Class({
} }
}) })
if (this.data.skeJsonData) {
this._animaResList.push({url: this.data.skeJsonData.url});
this._animaResList.push({url: this.data.texJsonData.url});
this._animaResList.push({url: this.data.texPngData.url});
}
}, },
loadEnd() { loadEnd() {
...@@ -278,6 +285,7 @@ cc.Class({ ...@@ -278,6 +285,7 @@ cc.Class({
this.initMaskLayer(); this.initMaskLayer();
this.showStartAudio(); this.showStartAudio();
}, },
initHotZone() { initHotZone() {
...@@ -372,6 +380,7 @@ cc.Class({ ...@@ -372,6 +380,7 @@ cc.Class({
}, },
addCircleListener(circlePosNode) { addCircleListener(circlePosNode) {
const circle = circlePosNode.getChildByName('circle'); const circle = circlePosNode.getChildByName('circle');
if ( circle.isAddTouch ) { if ( circle.isAddTouch ) {
...@@ -384,9 +393,15 @@ cc.Class({ ...@@ -384,9 +393,15 @@ cc.Class({
return; return;
} }
console.log('circle 1')
if (circlePosNode.isClicked || this.isShowRightAnima) { if (circlePosNode.isClicked || this.isShowRightAnima) {
return; return;
} }
console.log('circle 2')
circlePosNode.isClicked = true; circlePosNode.isClicked = true;
if (circlePosNode.data.isRight == '0') { if (circlePosNode.data.isRight == '0') {
...@@ -975,6 +990,12 @@ cc.Class({ ...@@ -975,6 +990,12 @@ cc.Class({
const asset = new dragonBones.DragonBonesAsset(); const asset = new dragonBones.DragonBonesAsset();
asset.dragonBonesJson = dragonBonesJson; asset.dragonBonesJson = dragonBonesJson;
console.log(' texture: ', texture)
console.log(' atlasJson: ', atlasJson)
console.log(' dragonBonesJson: ', dragonBonesJson)
dragonDisplay.dragonAtlasAsset = atlas; dragonDisplay.dragonAtlasAsset = atlas;
dragonDisplay.dragonAsset = asset; dragonDisplay.dragonAsset = asset;
...@@ -997,6 +1018,8 @@ cc.Class({ ...@@ -997,6 +1018,8 @@ cc.Class({
animationNames.push(animations[i].name); animationNames.push(animations[i].name);
} }
console.log('animationNames: ', animationNames.toString())
// rectNode.addComponent(cc.Button); // rectNode.addComponent(cc.Button);
// rectNode.on('click', () => { // rectNode.on('click', () => {
// if (rectNode.isClicked) { // if (rectNode.isClicked) {
...@@ -1015,17 +1038,19 @@ cc.Class({ ...@@ -1015,17 +1038,19 @@ cc.Class({
// } // }
// }); // });
dragonDisplay.playAnimation('normal', 1);
dragonDisplay.timeScale = 0;
dragonDisplay.animaNames = animationNames;
// setSprNodeMaxLen(animaNode, 474, 290); dragonDisplay.playAnimation('normal', -1);
// animaNode.addComponent(cc.Button) dragonDisplay.animaNames = animationNames;
// animaNode.y = animaNode.height / 2;
animaNode.y -= 30; animaNode.y -= 30;
animaNode.scale = 376 / animaNode.height; if ( animaNode.height ) {
animaNode.scale = 376 / animaNode.height;
}
// animaNode.on('click', () => { // animaNode.on('click', () => {
// console.log('anima node clicked ~~~'); // console.log('anima node clicked ~~~');
// this.showDragonAnima(); // this.showDragonAnima();
......
{ {
"ver": "1.0.8", "ver": "1.0.8",
"uuid": "335fe6b8-2b52-45a9-a9c9-cb3b54014251", "uuid": "4c0e8f25-d18c-458f-b9e0-ec3fc1acd204",
"isPlugin": false, "isPlugin": false,
"loadPluginInWeb": true, "loadPluginInWeb": true,
"loadPluginInNative": true, "loadPluginInNative": true,
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
"premultiplyAlpha": false, "premultiplyAlpha": false,
"genMipmaps": false, "genMipmaps": false,
"packable": true, "packable": true,
"width": 162, "width": 124,
"height": 167, "height": 124,
"platformSettings": {}, "platformSettings": {},
"subMetas": { "subMetas": {
"circle_mask": { "circle_mask": {
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
"premultiplyAlpha": false, "premultiplyAlpha": false,
"genMipmaps": false, "genMipmaps": false,
"packable": true, "packable": true,
"width": 528, "width": 862,
"height": 355, "height": 485,
"platformSettings": {}, "platformSettings": {},
"subMetas": { "subMetas": {
"frame": { "frame": {
......
const express = require('express');
const os = require('os');
const readline = require('readline');
const { build, buildAndroid, buildIos } = require('./buildCocos');
const networkInfo = os.networkInterfaces();
let host = '';
for (const infos of Object.values(networkInfo)) {
for (const info of infos) {
if (info.family == 'IPv4') {
if (info.address.split('.')[0] != "127") {
host = info.address;
}
}
}
}
var app = express();
app.use('/dist', express.static('dist'));
app.use('/form', express.static('form'));
app.get('/', function (req, res) {
res.send('Hello World');
})
let port = '';
var server = app.listen(8081, function () {
port = server.address().port
console.log("测试服务已启动:%s:%s", host, port)
console.log("如果已经build可访问如下地址");
console.log("http://%s:%s/dist/play/index.html", host, port)
console.log("http://%s:%s/dist/play/index.html", "localhost", port)
console.log('-----------------');
console.log(" 输入 build 构建安卓脚本");
console.log(" 输入 build ios 构建IOS脚本");
console.log('-----------------');
})
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
rl.on('line', async (str) => {
if (str.trim() == 'build') {
await buildAndroid();
} else if (str.trim() == 'build ios') {
await buildIos();
}
console.log("服务器:%s:%s", host, port)
})
const {build} = require('./buildCocos');
build();
\ No newline at end of file
This diff is collapsed.
const fs = require('fs');
const removeDir = async function (src) {
const exists = await fs.existsSync(src);
if (!exists) {
return;
}
//读取目录
const st = await fs.statSync(src);
const paths = await fs.readdirSync(src);
for (let i = 0; i < paths.length; i++) {
let path = paths[i];
const newSrc = `${src}/${path}`;
const st = await fs.statSync(newSrc);
if (st.isFile()) {
console.log('remove: ' + newSrc);
await fs.unlinkSync(newSrc);
} else if (st.isDirectory()) {
await removeDir(newSrc);
}
}
await fs.rmdirSync(src);
}
const copyDir = async function (src, dst) {
const exists = await fs.existsSync(dst);
if (!exists) {
await fs.mkdirSync(dst);
}
//读取目录
const paths = await fs.readdirSync(src);
for (let i = 0; i < paths.length; i++) {
let path = paths[i];
const newSrc = `${src}/${path}`;
const newDst = `${dst}/${path}`;
const st = await fs.statSync(newSrc);
if (st.isFile()) {
console.log('copy: ' + newDst);
const data = await fs.readFileSync(newSrc);
await fs.writeFileSync(newDst, data);
} else if (st.isDirectory()) {
await copyDir(newSrc, newDst);
}
}
};
module.exports = {
fix2: function (num) {
if (num >= 10) {
return '' + num;
} else {
return '0' + num;
}
},
copyDir: copyDir,
removeDir: removeDir,
};
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
<script src="src/settings.js" charset="utf-8"></script> <script src="src/settings.js" charset="utf-8"></script>
<script src="main.js" charset="utf-8"></script> <script src="main.js" charset="utf-8"></script>
<script type="text/javascript" src="https://staging-teach.cdn.ireadabc.com/h5template/h5-static-lib/js/air.js"></script> <script type="text/javascript" src="//staging-teach.cdn.ireadabc.com/h5template/h5-static-lib/js/air.js"></script>
<script type="text/javascript"> <script type="text/javascript">
......
This diff is collapsed.
## 0.5.2 / 2020-06-08 # 0.4.24 / 2018-08-22
* Added `iconv.getEncoder()` and `iconv.getDecoder()` methods to typescript definitions (#229).
* Fixed semver version to 6.1.2 to support Node 8.x (by @tanandara).
* Capped iconv version to 2.x as 3.x has dropped support for older Node versions.
* Switched from instanbul to c8 for code coverage.
## 0.5.1 / 2020-01-18
* Added cp720 encoding (#221, by @kr-deps)
* (minor) Changed Changelog.md formatting to use h2.
## 0.5.0 / 2019-06-26
* Added UTF-32 encoding, both little-endian and big-endian variants (UTF-32LE, UTF32-BE). If endianness
is not provided for decoding, it's deduced automatically from the stream using a heuristic similar to
what we use in UTF-16. (great work in #216 by @kshetline)
* Several minor updates to README (#217 by @oldj, plus some more)
* Added Node versions 10 and 12 to Travis test harness.
## 0.4.24 / 2018-08-22
* Added MIK encoding (#196, by @Ivan-Kalatchev) * Added MIK encoding (#196, by @Ivan-Kalatchev)
## 0.4.23 / 2018-05-07 # 0.4.23 / 2018-05-07
* Fix deprecation warning in Node v10 due to the last usage of `new Buffer` (#185, by @felixbuenemann) * Fix deprecation warning in Node v10 due to the last usage of `new Buffer` (#185, by @felixbuenemann)
* Switched from NodeBuffer to Buffer in typings (#155 by @felixfbecker, #186 by @larssn) * Switched from NodeBuffer to Buffer in typings (#155 by @felixfbecker, #186 by @larssn)
## 0.4.22 / 2018-05-05 # 0.4.22 / 2018-05-05
* Use older semver style for dependencies to be compatible with Node version 0.10 (#182, by @dougwilson) * Use older semver style for dependencies to be compatible with Node version 0.10 (#182, by @dougwilson)
* Fix tests to accomodate fixes in Node v10 (#182, by @dougwilson) * Fix tests to accomodate fixes in Node v10 (#182, by @dougwilson)
## 0.4.21 / 2018-04-06 # 0.4.21 / 2018-04-06
* Fix encoding canonicalization (#156) * Fix encoding canonicalization (#156)
* Fix the paths in the "browser" field in package.json (#174 by @LMLB) * Fix the paths in the "browser" field in package.json (#174 by @LMLB)
* Removed "contributors" section in package.json - see Git history instead. * Removed "contributors" section in package.json - see Git history instead.
## 0.4.20 / 2018-04-06 # 0.4.20 / 2018-04-06
* Updated `new Buffer()` usages with recommended replacements as it's being deprecated in Node v10 (#176, #178 by @ChALkeR) * Updated `new Buffer()` usages with recommended replacements as it's being deprecated in Node v10 (#176, #178 by @ChALkeR)
## 0.4.19 / 2017-09-09 # 0.4.19 / 2017-09-09
* Fixed iso8859-1 codec regression in handling untranslatable characters (#162, caused by #147) * Fixed iso8859-1 codec regression in handling untranslatable characters (#162, caused by #147)
* Re-generated windows1255 codec, because it was updated in iconv project * Re-generated windows1255 codec, because it was updated in iconv project
* Fixed grammar in error message when iconv-lite is loaded with encoding other than utf8 * Fixed grammar in error message when iconv-lite is loaded with encoding other than utf8
## 0.4.18 / 2017-06-13 # 0.4.18 / 2017-06-13
* Fixed CESU-8 regression in Node v8. * Fixed CESU-8 regression in Node v8.
## 0.4.17 / 2017-04-22 # 0.4.17 / 2017-04-22
* Updated typescript definition file to support Angular 2 AoT mode (#153 by @larssn) * Updated typescript definition file to support Angular 2 AoT mode (#153 by @larssn)
## 0.4.16 / 2017-04-22 # 0.4.16 / 2017-04-22
* Added support for React Native (#150) * Added support for React Native (#150)
* Changed iso8859-1 encoding to usine internal 'binary' encoding, as it's the same thing (#147 by @mscdex) * Changed iso8859-1 encoding to usine internal 'binary' encoding, as it's the same thing (#147 by @mscdex)
...@@ -75,12 +53,12 @@ ...@@ -75,12 +53,12 @@
* Added a warning if iconv-lite is loaded not as utf-8 (see #142) * Added a warning if iconv-lite is loaded not as utf-8 (see #142)
## 0.4.15 / 2016-11-21 # 0.4.15 / 2016-11-21
* Fixed typescript type definition (#137) * Fixed typescript type definition (#137)
## 0.4.14 / 2016-11-20 # 0.4.14 / 2016-11-20
* Preparation for v1.0 * Preparation for v1.0
* Added Node v6 and latest Node versions to Travis CI test rig * Added Node v6 and latest Node versions to Travis CI test rig
...@@ -90,12 +68,12 @@ ...@@ -90,12 +68,12 @@
* Add ms prefix to dbcs windows encodings (@rokoroku) * Add ms prefix to dbcs windows encodings (@rokoroku)
## 0.4.13 / 2015-10-01 # 0.4.13 / 2015-10-01
* Fix silly mistake in deprecation notice. * Fix silly mistake in deprecation notice.
## 0.4.12 / 2015-09-26 # 0.4.12 / 2015-09-26
* Node v4 support: * Node v4 support:
* Added CESU-8 decoding (#106) * Added CESU-8 decoding (#106)
...@@ -103,18 +81,18 @@ ...@@ -103,18 +81,18 @@
* Added Travis tests for Node v4 and io.js latest (#105 by @Mithgol) * Added Travis tests for Node v4 and io.js latest (#105 by @Mithgol)
## 0.4.11 / 2015-07-03 # 0.4.11 / 2015-07-03
* Added CESU-8 encoding. * Added CESU-8 encoding.
## 0.4.10 / 2015-05-26 # 0.4.10 / 2015-05-26
* Changed UTF-16 endianness heuristic to take into account any ASCII chars, not * Changed UTF-16 endianness heuristic to take into account any ASCII chars, not
just spaces. This should minimize the importance of "default" endianness. just spaces. This should minimize the importance of "default" endianness.
## 0.4.9 / 2015-05-24 # 0.4.9 / 2015-05-24
* Streamlined BOM handling: strip BOM by default, add BOM when encoding if * Streamlined BOM handling: strip BOM by default, add BOM when encoding if
addBOM: true. Added docs to Readme. addBOM: true. Added docs to Readme.
...@@ -126,12 +104,12 @@ ...@@ -126,12 +104,12 @@
* Use strict mode in all files. * Use strict mode in all files.
## 0.4.8 / 2015-04-14 # 0.4.8 / 2015-04-14
* added alias UNICODE-1-1-UTF-7 for UTF-7 encoding (#94) * added alias UNICODE-1-1-UTF-7 for UTF-7 encoding (#94)
## 0.4.7 / 2015-02-05 # 0.4.7 / 2015-02-05
* stop official support of Node.js v0.8. Should still work, but no guarantees. * stop official support of Node.js v0.8. Should still work, but no guarantees.
reason: Packages needed for testing are hard to get on Travis CI. reason: Packages needed for testing are hard to get on Travis CI.
...@@ -139,40 +117,40 @@ ...@@ -139,40 +117,40 @@
props (#89). props (#89).
## 0.4.6 / 2015-01-12 # 0.4.6 / 2015-01-12
* fix rare aliases of single-byte encodings (thanks @mscdex) * fix rare aliases of single-byte encodings (thanks @mscdex)
* double the timeout for dbcs tests to make them less flaky on travis * double the timeout for dbcs tests to make them less flaky on travis
## 0.4.5 / 2014-11-20 # 0.4.5 / 2014-11-20
* fix windows-31j and x-sjis encoding support (@nleush) * fix windows-31j and x-sjis encoding support (@nleush)
* minor fix: undefined variable reference when internal error happens * minor fix: undefined variable reference when internal error happens
## 0.4.4 / 2014-07-16 # 0.4.4 / 2014-07-16
* added encodings UTF-7 (RFC2152) and UTF-7-IMAP (RFC3501 Section 5.1.3) * added encodings UTF-7 (RFC2152) and UTF-7-IMAP (RFC3501 Section 5.1.3)
* fixed streaming base64 encoding * fixed streaming base64 encoding
## 0.4.3 / 2014-06-14 # 0.4.3 / 2014-06-14
* added encodings UTF-16BE and UTF-16 with BOM * added encodings UTF-16BE and UTF-16 with BOM
## 0.4.2 / 2014-06-12 # 0.4.2 / 2014-06-12
* don't throw exception if `extendNodeEncodings()` is called more than once * don't throw exception if `extendNodeEncodings()` is called more than once
## 0.4.1 / 2014-06-11 # 0.4.1 / 2014-06-11
* codepage 808 added * codepage 808 added
## 0.4.0 / 2014-06-10 # 0.4.0 / 2014-06-10
* code is rewritten from scratch * code is rewritten from scratch
* all widespread encodings are supported * all widespread encodings are supported
......
## Pure JS character encoding conversion ## Pure JS character encoding conversion [![Build Status](https://travis-ci.org/ashtuchkin/iconv-lite.svg?branch=master)](https://travis-ci.org/ashtuchkin/iconv-lite)
* Doesn't need native code compilation. Works on Windows and in sandboxed environments like [Cloud9](http://c9.io). * Doesn't need native code compilation. Works on Windows and in sandboxed environments like [Cloud9](http://c9.io).
* Used in popular projects like [Express.js (body_parser)](https://github.com/expressjs/body-parser), * Used in popular projects like [Express.js (body_parser)](https://github.com/expressjs/body-parser),
...@@ -12,11 +12,7 @@ ...@@ -12,11 +12,7 @@
* React Native is supported (need to explicitly `npm install` two more modules: `buffer` and `stream`). * React Native is supported (need to explicitly `npm install` two more modules: `buffer` and `stream`).
* License: MIT. * License: MIT.
[![NPM Stats](https://nodei.co/npm/iconv-lite.png)](https://npmjs.org/package/iconv-lite/) [![NPM Stats](https://nodei.co/npm/iconv-lite.png?downloads=true&downloadRank=true)](https://npmjs.org/packages/iconv-lite/)
[![Build Status](https://travis-ci.org/ashtuchkin/iconv-lite.svg?branch=master)](https://travis-ci.org/ashtuchkin/iconv-lite)
[![npm](https://img.shields.io/npm/v/iconv-lite.svg)](https://npmjs.org/package/iconv-lite/)
[![npm downloads](https://img.shields.io/npm/dm/iconv-lite.svg)](https://npmjs.org/package/iconv-lite/)
[![npm bundle size](https://img.shields.io/bundlephobia/min/iconv-lite.svg)](https://npmjs.org/package/iconv-lite/)
## Usage ## Usage
### Basic API ### Basic API
...@@ -98,7 +94,7 @@ iconv.undoExtendNodeEncodings(); ...@@ -98,7 +94,7 @@ iconv.undoExtendNodeEncodings();
## Supported encodings ## Supported encodings
* All node.js native encodings: utf8, ucs2 / utf16-le, ascii, binary, base64, hex. * All node.js native encodings: utf8, ucs2 / utf16-le, ascii, binary, base64, hex.
* Additional unicode encodings: utf16, utf16-be, utf-7, utf-7-imap, utf32, utf32-le, and utf32-be. * Additional unicode encodings: utf16, utf16-be, utf-7, utf-7-imap.
* All widespread singlebyte encodings: Windows 125x family, ISO-8859 family, * All widespread singlebyte encodings: Windows 125x family, ISO-8859 family,
IBM/DOS codepages, Macintosh family, KOI8 family, all others supported by iconv library. IBM/DOS codepages, Macintosh family, KOI8 family, all others supported by iconv library.
Aliases like 'latin1', 'us-ascii' also supported. Aliases like 'latin1', 'us-ascii' also supported.
...@@ -137,12 +133,6 @@ smart about endianness in the following ways: ...@@ -137,12 +133,6 @@ smart about endianness in the following ways:
overridden with `defaultEncoding: 'utf-16be'` option. Strips BOM unless `stripBOM: false`. overridden with `defaultEncoding: 'utf-16be'` option. Strips BOM unless `stripBOM: false`.
* Encoding: uses UTF-16LE and writes BOM by default. Use `addBOM: false` to override. * Encoding: uses UTF-16LE and writes BOM by default. Use `addBOM: false` to override.
## UTF-32 Encodings
This library supports UTF-32LE, UTF-32BE and UTF-32 encodings. Like the UTF-16 encoding above, UTF-32 defaults to UTF-32LE, but uses BOM and 'spaces heuristics' to determine input endianness.
* The default of UTF-32LE can be overridden with the `defaultEncoding: 'utf-32be'` option. Strips BOM unless `stripBOM: false`.
* Encoding: uses UTF-32LE and writes BOM by default. Use `addBOM: false` to override. (`defaultEncoding: 'utf-32be'` can also be used here to change encoding.)
## Other notes ## Other notes
When decoding, be sure to supply a Buffer to decode() method, otherwise [bad things usually happen](https://github.com/ashtuchkin/iconv-lite/wiki/Use-Buffers-when-decoding). When decoding, be sure to supply a Buffer to decode() method, otherwise [bad things usually happen](https://github.com/ashtuchkin/iconv-lite/wiki/Use-Buffers-when-decoding).
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
// We support Browserify by skipping automatic module discovery and requiring modules directly. // We support Browserify by skipping automatic module discovery and requiring modules directly.
var modules = [ var modules = [
require("./internal"), require("./internal"),
require("./utf32"),
require("./utf16"), require("./utf16"),
require("./utf7"), require("./utf7"),
require("./sbcs-codec"), require("./sbcs-codec"),
...@@ -14,7 +13,7 @@ var modules = [ ...@@ -14,7 +13,7 @@ var modules = [
require("./dbcs-data"), require("./dbcs-data"),
]; ];
// Put all encoding/alias/codec definitions to single object and export it. // Put all encoding/alias/codec definitions to single object and export it.
for (var i = 0; i < modules.length; i++) { for (var i = 0; i < modules.length; i++) {
var module = modules[i]; var module = modules[i];
for (var enc in module) for (var enc in module)
......
...@@ -22,11 +22,6 @@ module.exports = { ...@@ -22,11 +22,6 @@ module.exports = {
"chars": "АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюя└┴┬├─┼╣║╚╔╩╦╠═╬┐░▒▓│┤№§╗╝┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ " "chars": "АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюя└┴┬├─┼╣║╚╔╩╦╠═╬┐░▒▓│┤№§╗╝┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ "
}, },
"cp720": {
"type": "_sbcs",
"chars": "\x80\x81éâ\x84à\x86çêëèïî\x8d\x8e\x8f\x90\u0651\u0652ô¤ـûùءآأؤ£إئابةتثجحخدذرزسشص«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀ضطظعغفµقكلمنهوىي≡\u064b\u064c\u064d\u064e\u064f\u0650≈°∙·√ⁿ²■\u00a0"
},
// Aliases of generated encodings. // Aliases of generated encodings.
"ascii8bit": "ascii", "ascii8bit": "ascii",
"usascii": "ascii", "usascii": "ascii",
......
'use strict';
var Buffer = require('safer-buffer').Buffer;
// == UTF32-LE/BE codec. ==========================================================
exports._utf32 = Utf32Codec;
function Utf32Codec(codecOptions, iconv) {
this.iconv = iconv;
this.bomAware = true;
this.isLE = codecOptions.isLE;
}
exports.utf32le = { type: '_utf32', isLE: true };
exports.utf32be = { type: '_utf32', isLE: false };
// Aliases
exports.ucs4le = 'utf32le';
exports.ucs4be = 'utf32be';
Utf32Codec.prototype.encoder = Utf32Encoder;
Utf32Codec.prototype.decoder = Utf32Decoder;
// -- Encoding
function Utf32Encoder(options, codec) {
this.isLE = codec.isLE;
this.highSurrogate = 0;
}
Utf32Encoder.prototype.write = function(str) {
var src = Buffer.from(str, 'ucs2');
var dst = Buffer.alloc(src.length * 2);
var write32 = this.isLE ? dst.writeUInt32LE : dst.writeUInt32BE;
var offset = 0;
for (var i = 0; i < src.length; i += 2) {
var code = src.readUInt16LE(i);
var isHighSurrogate = (0xD800 <= code && code < 0xDC00);
var isLowSurrogate = (0xDC00 <= code && code < 0xE000);
if (this.highSurrogate) {
if (isHighSurrogate || !isLowSurrogate) {
// There shouldn't be two high surrogates in a row, nor a high surrogate which isn't followed by a low
// surrogate. If this happens, keep the pending high surrogate as a stand-alone semi-invalid character
// (technically wrong, but expected by some applications, like Windows file names).
write32.call(dst, this.highSurrogate, offset);
offset += 4;
}
else {
// Create 32-bit value from high and low surrogates;
var codepoint = (((this.highSurrogate - 0xD800) << 10) | (code - 0xDC00)) + 0x10000;
write32.call(dst, codepoint, offset);
offset += 4;
this.highSurrogate = 0;
continue;
}
}
if (isHighSurrogate)
this.highSurrogate = code;
else {
// Even if the current character is a low surrogate, with no previous high surrogate, we'll
// encode it as a semi-invalid stand-alone character for the same reasons expressed above for
// unpaired high surrogates.
write32.call(dst, code, offset);
offset += 4;
this.highSurrogate = 0;
}
}
if (offset < dst.length)
dst = dst.slice(0, offset);
return dst;
};
Utf32Encoder.prototype.end = function() {
// Treat any leftover high surrogate as a semi-valid independent character.
if (!this.highSurrogate)
return;
var buf = Buffer.alloc(4);
if (this.isLE)
buf.writeUInt32LE(this.highSurrogate, 0);
else
buf.writeUInt32BE(this.highSurrogate, 0);
this.highSurrogate = 0;
return buf;
};
// -- Decoding
function Utf32Decoder(options, codec) {
this.isLE = codec.isLE;
this.badChar = codec.iconv.defaultCharUnicode.charCodeAt(0);
this.overflow = null;
}
Utf32Decoder.prototype.write = function(src) {
if (src.length === 0)
return '';
if (this.overflow)
src = Buffer.concat([this.overflow, src]);
var goodLength = src.length - src.length % 4;
if (src.length !== goodLength) {
this.overflow = src.slice(goodLength);
src = src.slice(0, goodLength);
}
else
this.overflow = null;
var dst = Buffer.alloc(goodLength);
var offset = 0;
for (var i = 0; i < goodLength; i += 4) {
var codepoint = this.isLE ? src.readUInt32LE(i) : src.readUInt32BE(i);
if (codepoint < 0x10000) {
// Simple 16-bit character
dst.writeUInt16LE(codepoint, offset);
offset += 2;
}
else {
if (codepoint > 0x10FFFF) {
// Not a valid Unicode codepoint
dst.writeUInt16LE(this.badChar, offset);
offset += 2;
}
else {
// Create high and low surrogates.
codepoint -= 0x10000;
var high = 0xD800 | (codepoint >> 10);
var low = 0xDC00 + (codepoint & 0x3FF);
dst.writeUInt16LE(high, offset);
offset += 2;
dst.writeUInt16LE(low, offset);
offset += 2;
}
}
}
return dst.slice(0, offset).toString('ucs2');
};
Utf32Decoder.prototype.end = function() {
this.overflow = null;
};
// == UTF-32 Auto codec =============================================================
// Decoder chooses automatically from UTF-32LE and UTF-32BE using BOM and space-based heuristic.
// Defaults to UTF-32LE. http://en.wikipedia.org/wiki/UTF-32
// Encoder/decoder default can be changed: iconv.decode(buf, 'utf32', {defaultEncoding: 'utf-32be'});
// Encoder prepends BOM (which can be overridden with (addBOM: false}).
exports.utf32 = Utf32AutoCodec;
exports.ucs4 = Utf32AutoCodec;
function Utf32AutoCodec(options, iconv) {
this.iconv = iconv;
}
Utf32AutoCodec.prototype.encoder = Utf32AutoEncoder;
Utf32AutoCodec.prototype.decoder = Utf32AutoDecoder;
// -- Encoding
function Utf32AutoEncoder(options, codec) {
options = options || {};
if (options.addBOM === undefined)
options.addBOM = true;
this.encoder = codec.iconv.getEncoder(options.defaultEncoding || 'utf-32le', options);
}
Utf32AutoEncoder.prototype.write = function(str) {
return this.encoder.write(str);
};
Utf32AutoEncoder.prototype.end = function() {
return this.encoder.end();
};
// -- Decoding
function Utf32AutoDecoder(options, codec) {
this.decoder = null;
this.initialBytes = [];
this.initialBytesLen = 0;
this.options = options || {};
this.iconv = codec.iconv;
}
Utf32AutoDecoder.prototype.write = function(buf) {
if (!this.decoder) {
// Codec is not chosen yet. Accumulate initial bytes.
this.initialBytes.push(buf);
this.initialBytesLen += buf.length;
if (this.initialBytesLen < 32) // We need more bytes to use space heuristic (see below)
return '';
// We have enough bytes -> detect endianness.
var buf2 = Buffer.concat(this.initialBytes),
encoding = detectEncoding(buf2, this.options.defaultEncoding);
this.decoder = this.iconv.getDecoder(encoding, this.options);
this.initialBytes.length = this.initialBytesLen = 0;
}
return this.decoder.write(buf);
};
Utf32AutoDecoder.prototype.end = function() {
if (!this.decoder) {
var buf = Buffer.concat(this.initialBytes),
encoding = detectEncoding(buf, this.options.defaultEncoding);
this.decoder = this.iconv.getDecoder(encoding, this.options);
var res = this.decoder.write(buf),
trail = this.decoder.end();
return trail ? (res + trail) : res;
}
return this.decoder.end();
};
function detectEncoding(buf, defaultEncoding) {
var enc = defaultEncoding || 'utf-32le';
if (buf.length >= 4) {
// Check BOM.
if (buf.readUInt32BE(0) === 0xFEFF) // UTF-32LE BOM
enc = 'utf-32be';
else if (buf.readUInt32LE(0) === 0xFEFF) // UTF-32LE BOM
enc = 'utf-32le';
else {
// No BOM found. Try to deduce encoding from initial content.
// Using the wrong endian-ism for UTF-32 will very often result in codepoints that are beyond
// the valid Unicode limit of 0x10FFFF. That will be used as the primary determinant.
//
// Further, we can suppose the content is mostly plain ASCII chars (U+00**).
// So, we count ASCII as if it was LE or BE, and decide from that.
var invalidLE = 0, invalidBE = 0;
var asciiCharsLE = 0, asciiCharsBE = 0, // Counts of chars in both positions
_len = Math.min(buf.length - (buf.length % 4), 128); // Len is always even.
for (var i = 0; i < _len; i += 4) {
var b0 = buf[i], b1 = buf[i + 1], b2 = buf[i + 2], b3 = buf[i + 3];
if (b0 !== 0 || b1 > 0x10) ++invalidBE;
if (b3 !== 0 || b2 > 0x10) ++invalidLE;
if (b0 === 0 && b1 === 0 && b2 === 0 && b3 !== 0) asciiCharsBE++;
if (b0 !== 0 && b1 === 0 && b2 === 0 && b3 === 0) asciiCharsLE++;
}
if (invalidBE < invalidLE)
enc = 'utf-32be';
else if (invalidLE < invalidBE)
enc = 'utf-32le';
if (asciiCharsBE > asciiCharsLE)
enc = 'utf-32be';
else if (asciiCharsBE < asciiCharsLE)
enc = 'utf-32le';
}
}
return enc;
}
...@@ -6,22 +6,15 @@ ...@@ -6,22 +6,15 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
declare module 'iconv-lite' { declare module 'iconv-lite' {
// Basic API
export function decode(buffer: Buffer, encoding: string, options?: Options): string; export function decode(buffer: Buffer, encoding: string, options?: Options): string;
export function encode(content: string, encoding: string, options?: Options): Buffer; export function encode(content: string, encoding: string, options?: Options): Buffer;
export function encodingExists(encoding: string): boolean; export function encodingExists(encoding: string): boolean;
// Stream API
export function decodeStream(encoding: string, options?: Options): NodeJS.ReadWriteStream; export function decodeStream(encoding: string, options?: Options): NodeJS.ReadWriteStream;
export function encodeStream(encoding: string, options?: Options): NodeJS.ReadWriteStream; export function encodeStream(encoding: string, options?: Options): NodeJS.ReadWriteStream;
// Low-level stream APIs
export function getEncoder(encoding: string, options?: Options): EncoderStream;
export function getDecoder(encoding: string, options?: Options): DecoderStream;
} }
export interface Options { export interface Options {
...@@ -29,13 +22,3 @@ export interface Options { ...@@ -29,13 +22,3 @@ export interface Options {
addBOM?: boolean; addBOM?: boolean;
defaultEncoding?: string; defaultEncoding?: string;
} }
export interface EncoderStream {
write(str: string): Buffer;
end(): Buffer | undefined;
}
export interface DecoderStream {
write(buf: Buffer): string;
end(): string | undefined;
}
{ {
"name": "iconv-lite", "name": "iconv-lite",
"description": "Convert character encodings in pure javascript.", "description": "Convert character encodings in pure javascript.",
"version": "0.5.2", "version": "0.4.24",
"license": "MIT", "license": "MIT",
"keywords": [ "keywords": [
"iconv", "iconv",
...@@ -22,7 +22,8 @@ ...@@ -22,7 +22,8 @@
"node": ">=0.10.0" "node": ">=0.10.0"
}, },
"scripts": { "scripts": {
"coverage": "c8 _mocha --grep .", "coverage": "istanbul cover _mocha -- --grep .",
"coverage-open": "open coverage/lcov-report/index.html",
"test": "mocha --reporter spec --grep ." "test": "mocha --reporter spec --grep ."
}, },
"browser": { "browser": {
...@@ -35,9 +36,9 @@ ...@@ -35,9 +36,9 @@
"unorm": "*", "unorm": "*",
"errto": "*", "errto": "*",
"async": "*", "async": "*",
"c8": "*", "istanbul": "*",
"semver": "6.1.2", "semver": "*",
"iconv": "2" "iconv": "*"
}, },
"dependencies": { "dependencies": {
"safer-buffer": ">= 2.1.2 < 3" "safer-buffer": ">= 2.1.2 < 3"
......
This diff is collapsed.
...@@ -5,13 +5,17 @@ ...@@ -5,13 +5,17 @@
"main": "build.js", "main": "build.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"build": "sh ./publish/build.sh", "publish": "node ./bin/build.js",
"win": "cd publish && build.cmd" "start": "node ./bin/app.js"
}, },
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"compressing": "^1.5.0" "base-64": "^1.0.0",
}, "compressing": "^1.5.1",
"repository": "http://vcs.ireadabc.com/template/cc_mz_007.git" "js-base64": "^3.7.2",
"uuid": "^8.3.2",
"child_process": "^1.0.2",
"express": "^4.17.1"
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment