专职C++

不能停止的脚步

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  163 Posts :: 7 Stories :: 135 Comments :: 0 Trackbacks

常用链接

留言簿(28)

我参与的团队

搜索

  •  

最新评论

阅读排行榜

评论排行榜

#

酷派 全魔王 8298-M02用于测试的手机,需要root,试了7兔,kingroot,百度root,root精灵,最后在完美root这个工具root成功了。
这手机,还不错,算是性价比非常高的手机了,在京东618的时候,以389入手。由于活动的原因,今天才收到。

看到很多人也在求root,在这里发一贴,希望对root的人有帮忙了。不过,这手机,真的不错,超值了。可以确定比某米4A强!质量也比它的好。我去酷派官网看了一下,原价是1299的,哈。

另:完美root好像已经停止进展了~~~


补充:这个手机,居然还送一年乐视会员!太强了

posted @ 2017-06-26 16:03 冬瓜 阅读(789) | 评论 (0)编辑 收藏

对于vscode,已经更新到1.13了,更新的好快啊。有的时候,需要在Linux下面工作,所以我选择了centos 7.x

废话一下ubuntu,最新17.04,我试装过不少版本(虚拟机下),最后就一个字卡。所以,每次都果断放弃了。反过来说,centos 桌面,虽然很多东西不是很新,但是在虚拟机下,它一点都不卡。centos 7.x的GUI也非常不错。

对于怎么安装vscode,参考官方的https://code.visualstudio.com/docs/setup/linux 有详细的说明。

对于centos则如下:

 

[javascript] view plain copy
 print?
  1. sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc  
  2. sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'  

然后用yum命令安装

 

 

[javascript] view plain copy
 print?
  1. yum check-update  
  2. sudo yum install code  

完成后,就可以用vscode了

 

后面附两张centos 7.x的UI




0
posted @ 2017-06-20 09:43 冬瓜 阅读(2587) | 评论 (0)编辑 收藏

centos 安装nodejs主要有两种方式,一种是源码,第二种是二进制安装。 
Linux系统一般来说,不追求新,而是追求稳定。centos 下的软件往往不是最新的,却是相对比较稳定的。我想这也是我们很多人选择centos的原因。(最重要的一点,是用习惯了centos或rhel)

现在Node.js已经8.1.2的,发展很快。如果用源码编译至少需要gcc 4.8.x或clang 3.xx,对于centos 6.x(默认是gcc 4.4.x)是一个麻烦的事,如果你仅是使用nodejs,nodejs编译时间又比较长,所以我这里还是倾向于二进制安装。

本身centos的yum默认是不带的node的安装包的,所以需要第三方方法。 
大家可以看这个网站,https://github.com/nodesource/distributions

上面提供了ubuntu,debian,linux Mint,还有centos(rhel)等安装方法。 
我这里,使用安装 nodejs 8.x 
所以内容如下

#要求在root下执行 curl -sL https://rpm.nodesource.com/setup_8.x | bash - yum install -y nodejs
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

很简单,我在centos 6.x下就完成了node.js 8.1.2的安装。

posted @ 2017-06-20 09:43 冬瓜 阅读(769) | 评论 (0)编辑 收藏

版权声明:本文为zdhsoft博主原创文章,未经博主允许不得转载。

因为装了Android studio 2.3 所以就默认安装了android sdk和NDK,用的NDK的版本是r10d x64。在安装RAD Studio的时候,就没有选择安装android的sdk和NDK,然后,用C++Builder创建MultDevice工程 ,编译为android目标就报如下错:


问是是arm-Linux-androideabi-ld.exe执行报错,而Delphi的版本,则没有问题!

然后找到RAD Studio的安装包,发现它有一个android-ndk.7zip的文件,然后用7z工具打开,发现里面是一个NDK r9c的版本,然后我就它提出出来,放到一个目录,如:d:\ndk\r9c,然后配置RAD studio





配置完成后,就可以编译android了,接上手机,就可以在真机上跑了

初步试用通过,感觉还是一个半成品的样子!C++Builder代码提示还是卡,有点改善的样子。

posted @ 2017-06-01 21:20 冬瓜 阅读(1062) | 评论 (0)编辑 收藏

版权声明:本文为zdhsoft博主原创文章,未经博主允许不得转载。

N久没有碰C++Builder,虽然他给了一个注册码,基本版的,但是一想我XE6,XE7的时候,那个版本,对于我128G的C盘都觉得不够,反正装完就少了几十个G,C盘提示一下就变红了有没有。今天想看看,于是下载了一个10.2版本,

下载地址:http://altd.embarcadero.com/download/radstudio/10.2/delphicbuilder10_2.iso

安装的时候,需要.net 3.5,我只能说,从C++Builder 6以后,就摔不开.net

然后就顺利安装完成。给我最大的惊喜是安装的临时文件都清理了,只需要11G就OK了!以前要是要30G以上,少于40G剩余空间,则会安装不了。

先用delphi创建一个mult device 应用,就随便选了一个,如下图:


然后就直接编译运行,在Android运行OK

当一切都顺利的时候,我接着用C++Builder创建一个同样的工程

然后就报这样的错:


所有的C++Builder的android应用 ,都是同样的错误,对于iOSLinux,由于空间有限,就没有选择安装。

对于win32程序,则暂时OK!

posted @ 2017-06-01 21:19 冬瓜 阅读(987) | 评论 (0)编辑 收藏

使用appium输入中文,发现好慢!至少5秒以上,如果在这样的情况下做测试,这就好悲剧了。 
从appium(1.6.3)代码上来看,没有什么问题,直接是通过boostrap的setText的方法。说是就下载了appium-bootstrap的代码看,从这里开发找到的代码,都是java的代码,找到 io.appium.android.bootstrap.handler.SetText 
在new Clear().execute(command);时间长达5秒(打日志发现),不管文本框有没有内容,都会执行
/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 * You may obtain a copy of the License at
 *
 *     
http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 
*/

package io.appium.android.bootstrap.handler;

import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiSelector;
import io.appium.android.bootstrap.*;
import io.appium.android.bootstrap.exceptions.ElementNotFoundException;
import io.appium.android.bootstrap.handler.Find;
import org.json.JSONException;

import java.util.Hashtable;

/**
 * This handler is used to set text in elements that support it.
 *
 
*/
public class SetText extends CommandHandler {

  /*
   * @param command The {@link AndroidCommand} used for this handler.
   *
   * @return {@link AndroidCommandResult}
   *
   * @throws JSONException
   *
   * @see io.appium.android.bootstrap.CommandHandler#execute(io.appium.android.
   * bootstrap.AndroidCommand)
   
*/
  @Override
  public AndroidCommandResult execute(final AndroidCommand command)
      throws JSONException {
    AndroidElement el = null;
    if (command.isElementCommand()) {
      el = command.getElement();
      Logger.debug("Using element passed in: " + el.getId());
    } else {
      try {
        AndroidElementsHash  elements = AndroidElementsHash.getInstance();
        el = elements.getElement(new UiSelector().focused(true), "");
        Logger.debug("Using currently-focused element: " + el.getId());
      } catch (ElementNotFoundException e) {
        Logger.debug("Error retrieving focused element: " + e);
        return getErrorResult("Unable to set text without a focused element.");
      }
    }
    try {
      final Hashtable<String, Object> params = command.params();
      boolean replace = Boolean.parseBoolean(params.get("replace").toString());
      String text = params.get("text").toString();
      boolean pressEnter = false;
      if (text.endsWith("\\n")) {
        pressEnter = true;
        text = text.replace("\\n", "");
        Logger.debug("Will press enter after setting text");
      }
      boolean unicodeKeyboard = false;
      if (params.get("unicodeKeyboard") != null) {
        unicodeKeyboard = Boolean.parseBoolean(params.get("unicodeKeyboard").toString());
      }
      String currText = el.getText();
      new Clear().execute(command); //不管有没有,这里都会执行
      if (!el.getText().isEmpty()) {
        // clear could have failed, or we could have a hint in the field
        
// we'll assume it is the latter
        Logger.debug("Text not cleared. Assuming remainder is hint text.");
        currText = "";
      }
      if (!replace) {
        text = currText + text;
      }
      final boolean result = el.setText(text, unicodeKeyboard);
      if (!result) {
        return getErrorResult("el.setText() failed!");
      }
      if (pressEnter) {
        final UiDevice d = UiDevice.getInstance();
        d.pressEnter();
      }
      return getSuccessResult(result);
    } catch (final UiObjectNotFoundException e) {
      return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT,
          e.getMessage());
    } catch (final Exception e) { // handle NullPointerException
      return getErrorResult("Unknown error");
    }
  }
}
然后,我们再看Clear的代码

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 * You may obtain a copy of the License at
 *
 *     
http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 
*/

package io.appium.android.bootstrap.handler;

import android.graphics.Rect;
import android.os.SystemClock;
import android.view.InputDevice;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiSelector;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.AndroidElement;
import io.appium.android.bootstrap.CommandHandler;
import io.appium.android.bootstrap.Logger;
import io.appium.android.bootstrap.WDStatus;
import io.appium.uiautomator.core.InteractionController;
import io.appium.uiautomator.core.UiAutomatorBridge;
import org.json.JSONException;

import java.lang.reflect.InvocationTargetException;

/**
 * This handler is used to clear elements in the Android UI.
 *
 * Based on the element Id, clear that element.
 *
 * UiAutomator method clearText is flaky hence overriding it with custom implementation.
 
*/
public class Clear extends CommandHandler {

  /*
   * Trying to select entire text with correctLongClick and increasing time intervals.
   * Checking if element still has text in them and and if true falling back on UiAutomator clearText
   *
   * @param command The {@link AndroidCommand}
   *
   * @return {@link AndroidCommandResult}
   *
   * @throws JSONException
   *
   * @see io.appium.android.bootstrap.CommandHandler#execute(io.appium.android.
   * bootstrap.AndroidCommand)
   
*/
  @Override
  public AndroidCommandResult execute(final AndroidCommand command)
          throws JSONException {
    if (command.isElementCommand()) {
      try {
        final AndroidElement el = command.getElement();

        // first, try to do native clearing
        Logger.debug("Attempting to clear using UiObject.clearText().");
        el.clearText();  //无条件都会执行这块。然后再分析clearText
        if (el.getText().isEmpty()) {
          return getSuccessResult(true);
        }

        // see if there is hint text
        if (hasHintText(el)) {
          Logger.debug("Text remains after clearing, "
              + "but it appears to be hint text.");
          return getSuccessResult(true);
        }

        // next try to select everything and delete
        Logger.debug("Clearing text not successful. Attempting to clear " +
                "by selecting all and deleting.");
        if (selectAndDelete(el)) {
          return getSuccessResult(true);
        }

        // see if there is hint text
        if (hasHintText(el)) {
          Logger.debug("Text remains after clearing, "
              + "but it appears to be hint text.");
          return getSuccessResult(true);
        }

        // finally try to send delete keys
        Logger.debug("Clearing text not successful. Attempting to clear " +
                "by sending delete keys.");
        if (sendDeleteKeys(el)) {
          return getSuccessResult(true);
        }

        if (!el.getText().isEmpty()) {
          // either there was a failure, or there is hint text
          if (hasHintText(el)) {
            Logger.debug("Text remains after clearing, " +
                    "but it appears to be hint text.");
            return getSuccessResult(true);
          } else if (!el.getText().isEmpty()) {
            Logger.debug("Exhausted all means to clear text but '" +
                    el.getText() + "' remains.");
            return getErrorResult("Clear text not successful.");
          }
        }
        return getSuccessResult(true);
      } catch (final UiObjectNotFoundException e) {
        return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT,
            e.getMessage());
      } catch (final Exception e) { // handle NullPointerException
        return getErrorResult("Unknown error clearing text");
      }
    }
    return getErrorResult("Unknown error");
  }

  private boolean selectAndDelete(AndroidElement el)
      throws UiObjectNotFoundException, IllegalAccessException,
        InvocationTargetException, NoSuchMethodException {
    Rect rect = el.getVisibleBounds();
    // Trying to select entire text.
    TouchLongClick.correctLongClick(rect.left + 20, rect.centerY(), 2000);
    UiObject selectAll = new UiObject(new UiSelector().descriptionContains("Select all"));
    if (selectAll.waitForExists(2000)) {
      selectAll.click();
    }
    // wait for the selection
    SystemClock.sleep(500);
    // delete it
    UiAutomatorBridge.getInstance().getInteractionController().sendKey(KeyEvent.KEYCODE_DEL, 0);

    return el.getText().isEmpty();
  }

  private boolean sendDeleteKeys(AndroidElement el)
      throws UiObjectNotFoundException, IllegalAccessException,
        InvocationTargetException, NoSuchMethodException {
    String tempTextHolder = "";

    // Preventing infinite while loop.
    while (!el.getText().isEmpty() && !tempTextHolder.equalsIgnoreCase(el.getText())) {
      // Trying send delete keys after clicking in text box.
      el.click();
      // Sending delete keys asynchronously, both forward and backward
      for (int key : new int[] { KeyEvent.KEYCODE_DEL, KeyEvent.KEYCODE_FORWARD_DEL }) {
        tempTextHolder = el.getText();
        final int length = tempTextHolder.length();
        final long eventTime = SystemClock.uptimeMillis();
        KeyEvent deleteEvent = new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_DOWN,
                key, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0,
                InputDevice.SOURCE_KEYBOARD);
        for (int count = 0; count < length; count++) {
          UiAutomatorBridge.getInstance().injectInputEvent(deleteEvent, false);
        }
      }
    }

    return el.getText().isEmpty();
  }

  private boolean hasHintText(AndroidElement el)
      throws UiObjectNotFoundException, IllegalAccessException,
        InvocationTargetException, NoSuchMethodException {
    // to test if the remaining text is hint text, try sending a single
    
// delete key and testing if there is any change.
    
// ignore the off-chance that the delete silently fails and we get a false
    
// positive.
    String currText = el.getText();

    try {
      if (!el.getBoolAttribute("focused")) {
        Logger.debug("Could not check for hint text because the element is not focused!");
        return false;
      }
    } catch (final Exception e) {
      Logger.debug("Could not check for hint text: " + e.getMessage());
      return false;
    }

    InteractionController interactionController = UiAutomatorBridge.getInstance().getInteractionController();
    interactionController.sendKey(KeyEvent.KEYCODE_DEL, 0);
    interactionController.sendKey(KeyEvent.KEYCODE_FORWARD_DEL, 0);

    return currText.equals(el.getText());
  }
}
再看看AndroidElement.clearText是什么样的
  public void clearText() throws UiObjectNotFoundException {
    el.clearTextField();
  }
这个都就是com.android.uiautomator.core.UiObject.clearTextField 
于是找再找到uiautomator的代码再来分析(这个代码需要下载andriod sdk,在对应android版本的目录下,会有源码,也有uiautomator的源代码),我这里的路径是: 
Android\sdk\sources\android-19\com\android\uiautomator\core 
在UiObject.java找到clearTextField实现
/**
     * Clears the existing text contents in an editable field.
     *
     * The {
@link UiSelector} of this object must reference a UI element that is editable.
     *
     * When you call this method, the method first sets focus at the start edge of the field.
     * The method then simulates a long-press to select the existing text, and deletes the
     * selected text.
     *
     * If a "Select-All" option is displayed, the method will automatically attempt to use it
     * to ensure full text selection.
     *
     * Note that it is possible that not all the text in the field is selected; for example,
     * if the text contains separators such as spaces, slashes, at symbol etc.
     * Also, not all editable fields support the long-press functionality.
     *
     * 
@throws UiObjectNotFoundException
     * 
@since API Level 16
     
*/
    public void clearTextField() throws UiObjectNotFoundException {
        Tracer.trace();
        // long click left + center
        AccessibilityNodeInfo node = findAccessibilityNodeInfo(mConfig.getWaitForSelectorTimeout());
        if(node == null) {
            throw new UiObjectNotFoundException(getSelector().toString());
        }
        Rect rect = getVisibleBounds(node);
        getInteractionController().longTapNoSync(rect.left + 20, rect.centerY()); //长按
        
// check if the edit menu is open
        UiObject selectAll = new UiObject(new UiSelector().descriptionContains("Select all"));
        if(selectAll.waitForExists(50))
            selectAll.click();
        // wait for the selection
        SystemClock.sleep(250); //这里等250ms
        
// delete it
        getInteractionController().sendKey(KeyEvent.KEYCODE_DEL, 0);
    }
相信大家,可以找到慢的原因了。这里做一次长按,然再再做全选,然后再sleep(250),还有一个selectAll.waitForExists(50), 这些都是耗费时间的。
再找一下UiObject.java中setText的实现

    public boolean setText(String text) throws UiObjectNotFoundException {
        Tracer.trace(text);
        clearTextField();
        return getInteractionController().sendText(text);
    }
发现这里又调用了一次clearTextField,这样算来,设一次文本,都会清理两次文本,于是,这时间就长了。 
优化:只需要将io.appium.android.bootstrap.handler.SetText中的new Clear().execute(command)去掉就可以了。

posted @ 2017-05-27 17:35 冬瓜 阅读(1804) | 评论 (0)编辑 收藏

node进步很快,一年前,我用的还是node 4.x LTS,现在都 node 6.x LTS了,而node 7.x也在开发中,node 8.x已经也展开了。 
node 6.x已经到了node 6.10.2了,则7.x也到了7.9.0了 
对比后,这里把发现的差异列一下

n次方运算符 **

例如

let a = 2 ** 3; console.log(a); //显示为8 
let b = 3; b **= 4; console.log(b); //显示为81
let c = Function("return 5**2");
console.log(c()); //显示为25
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 6.10.2 需要–harmony 标志
  • 7.9.0 支持

Object.values和Object.entries

6.10.2支持Object.keys,但是不支持 values和entries

let a = { a: 100, b: '2423423', c: 'jjj' }; 
let k = Object.keys(a);
let v = Object.values(a);
let e = Object.entries(a);
console.log(k); //显示为:[ 'a', 'b', 'c' ]
console.log(v); //显示为:[ 100, '2423423', 'jjj' ]
console.log(e); //显示为:[ [ 'a', 100 ], [ 'b', '2423423' ], [ 'c', 'jjj' ] ]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

这个功能在很多地方,都很用了,可以不需要lodash了

  • 6.10.2 需要–harmony 标志
  • 7.9.0 支持

String的padStart和padEnd

在显示时间的时候,我们需要对齐显示 如2017-04-26 23:01:01这样显示比较整齐,如果显示为2017-4-26 23:1:1就不好看了,之前都是我们自己写pad函数,但是node支持这个功能了

console.log('1'.padStart(2,'00')); //显示为 '01' 
console.log('2'.padEnd(2,'00')); //显示为 '20'
console.log('1234'.padStart(10)); //显示为 ' 1234'
console.log('1234'.padEnd(10)); //显示为 '1234 '
console.log('abc'.padEnd(10,'0123456789')); //显示为 'abc0123456'
console.log('abc'.padStart(10,'0123456789'));//显示为 '0123456abc' //其它的使用办法,大家就自己研究了
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 6.10.2 需要–harmony 标志
  • 7.9.0 需要–harmony 标志

async和await

这个是es2017最重要的特性了,有了它,写异步程序就方便多了

//一个延时指定时间的函数 
async function aaa_sleep(time) {
return new Promise(function (resolve) {
setTimeout(() => {
resolve();
console.log("finish", new Date());
}, time);
});
}
async function m() {
console.log(new Date());
await aaa_sleep(2000);
console.log(new Date());
}
m(); //注意:await一定要在async函数中出现,不然会报错
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

等LTS版本出来了,就可以放弃babel来编译了,可惜import引入模块的方式,一直没有被放到标准

  • 6.10.2 不支持
  • 7.9.0 支持
posted @ 2017-04-27 00:18 冬瓜 阅读(1147) | 评论 (0)编辑 收藏

基于vscode的node的ES2015(ES6)运行环境搭建

用了vscode也有一段时间了,在轻量级的开发环境,它的功能是最强的。跨平台,不依赖Java, .net等,UI也很现代,运行速度也相对比较快,占用内存少,平板电脑的win10都可以轻松开发。

环境说明:

  • node.js 6.9.x
  • vscode 1.11.2
  • 操作系统 win10 (win7之后的系统,安装方法应该都一样)
  • 编译插件:babel

第一步:安装node

www.nodejs.org 下载安装包 6.x,默认安装 注意:在生产环境,建议使用LTS,比较稳定,bug相对比较少。 
下载后,一路默认安装就可以了

第二步:安装vscode

vscode我就不介绍了,去https://code.visualstudio.com/下载对应的安装包就可以了,写这个文章的版本是1.11.2 
下载后,一路默认安装就可以了 
(如果是国产软件,千万不要一路默认安装,如百****du,会给你默认安装一个全家桶,占领你的启动,瞬间让你的电脑卡成翔)

第三步:安装全局的babel

在命令提示符下,输入下面命令:

npm install babel-cli babel-eslint -g
  • 1
  • 1

完成后,可以输入

babel --version
  • 1
  • 1

可以显示babel的版本号

第四步:用npm init创建工程

如果已创建,则跳过 
在控制台下,建好工程目录,如:d:\work\firstnode 
然后进入该目录

d: cd d:\work\firstnode ppm init
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

完成node的工程创建 
为了便于管理,我们将源代码目录放在lib目录下面,或src目录,在这里我用的是lib目录 
编译后可以运行的目录放在build目录下面 
这样就会有两个目录

d:\work\firstnode\lib d:\work\firstnode\build
  • 1
  • 2
  • 1
  • 2

第五步:安装编译插件

在控制台下,目录为d:\work\firstnode安装插件,输入: 
npm install –save-dev babel-preset-eslatest-node6 
第六步:编写.babelrc

//---------------------------------------------------------- 
{
"presets": ["eslatest-node6"],
"plugins": [ ]
}
//---------------------------------------------------------------
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

第七步:用vscode编写代码

在控制台并在d:\work\firstnode下面,输入code .就可以打开当前工程 
或者先启动vscode后,选择打开文件夹,选择这个目录也可以。 
在vscode的左边的资源管理器,新建一个index.js放到lib目录下面

//-------------index.js-------------------------------------- 
console.log("hello world");
//---------------------------------------------------------------
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

然后在控制台下输入命令

babel lib -d build\lib
  • 1
  • 1

就可以看到在build\lib目录面,多了一个index.js

第八步:配置运行

用vscode选择调试,调试显示的是没有配置,然后进行配置,就会进入vscode配置lanuch.json编辑

{     
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "启动程序",
"program": "${workspaceRoot}\\bulid\\lib\\index.js"
},
{
"type": "node",
"request": "attach",
"name": "附加到端口",
"address": "localhost",
"port": 5858
}
]
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

将program改为${workspaceRoot}\bulid\lib\index.js就可以了,然后按F5就可以运行了。 
为了方便调试,修改package.json中的script,增加如下内容

"scripts": {
"build": "babel lib -d build/lib -s inline",
"babelWatch":"babel lib/**/*.js -d build -w -s inline",
"releaseBuild":"babel lib -d release/lib --no-comments --compact true --minified"
},
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5

然后在控制台下,输入npm run build就会执行babel lib -d build/lib -s inline 
这样,就完成了node的vscode环境操作

第九步:最后

  • 除了配置了build,还配置了babelWatch,这样就可以处于监视状态,只要lib目录下一有文件保存,就可以实时编译到build目录下面。-s inline则是生成sourceMap,这样,用vscode断点调试的时候,就可以正常的代码位置。
  • 另外:这个使用的插件是babel-preset-eslatest-node6,这个插件的作用是将ES2015或更ES2017的js代码编译成node 6.x支持的js代码,而不是ES5,node 6.x已经支持99%的ES2015了,这样编译后的代码变化不大。
posted @ 2017-04-21 09:42 冬瓜 阅读(1866) | 评论 (0)编辑 收藏

概述

vscode是一个不错的开源IDE,可以完全替代sublime,又是跨平台,使用起来还比较方便.使用一段时间后,我觉得有些插件,值得推荐一下.我这里的开发环境是win10下vscode+Node.js 
在vscode的主UI的左边工具栏的最下边,就是插件管理了,如下图 
这里写图片描述

beautify

这是一个代码美化插件,一定要有

ESLint

这是一个代码检查的插件,一定要有,很不错.下面是我的配置使用.eslintrc

module.exports = {
"env": {
"commonjs": true,
"es6": true,
"node": true
},
parser: "babel-eslint",
"parserOptions": {
"sourceType": "module",
},
"extends": "eslint:recommended",
"rules": {
"no-console": 0,
"semi": [2, "always"],
"no-this-before-super": 2,
"no-var": 2,
"no-cond-assign": 2, //禁止在条件表达式中使用赋值语句
"no-dupe-args": 2, //函数参数禁止重名
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-extra-semi": 0,
"no-constant-condition": 0,
"no-ex-assign": 2,
"no-func-assign": 2,
"no-extra-semi": 2,
"no-irregular-whitespace": 2,
"no-negated-in-lhs": 2,
"no-obj-calls": 2,
"no-unreachable": 2,
"use-isnan": 2,
"default-case": 2,
"no-invalid-this": 2,
"consistent-return": 0,
"valid-jsdoc": 2,
"block-scoped-var": 0,
"complexity": [2, 20],
"require-yield": 0,
"no-mixed-spaces-and-tabs": 2, //注释格式要求JSDoc格式
"require-jsdoc": [2, {
"require": {
"FunctionDeclaration": true,
"MethodDefinition": false,
"ClassDeclaration": false
}
}],
"linebreak-style": 0
}
};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50

JavaScript (ES6) code snippets

从node 6.x后,就支持JavaScript ES6很多语法了, 6.9.x开始,已经支持99%的ES6了,所以这个插件很必要. 
不能理解,node 6.x为什么不支持import

Numbered Bookmarks

一个书签工具,还是很有必要的,但是感觉功能还比较弱

tortoise-svn

SVN的集成插件,虽然都用Git了,但svn还是很不错的

VSCode Great Icons

这个是非常必要的,这个为每个文件类型增加了一个图标,例得项目的目录树很直观,这个一定要用.

最后

上述是我常用的插件,还有很多新插件,还不清楚,等大家一起发现,有好的,都推荐一下.

posted @ 2017-04-17 12:01 冬瓜 阅读(7206) | 评论 (0)编辑 收藏

在很多聊天中,会有许多表情,这些表情都是类似”[微笑]”的这种,然后写了一个正则表达式,保留在这里,便于以后使用中.这里的提取支持提取中文.在Node.js 6.10.2下运行通过.
 1 let testStr = "now [里斯本] [test002] [ddddd] [adfasd][3234]";   
 2 
 3 function getFaceTag(message) {
 4     let re = /\[([\u4e00-\u9fa5\w]+)\]/g;    
 5     let r = {fulltag:[],tags:[]};
 6     let m;
 7     while(m = re.exec(message)) {
 8         r.fulltag.push(m[0]);
 9         r.tags.push(m[1]);
10     }
11     return r;
12 }
13 
14 let k = getFaceTag(testStr);
15 console.log(k);
posted @ 2017-04-17 11:41 冬瓜 阅读(1009) | 评论 (0)编辑 收藏

仅列出标题
共17页: 1 2 3 4 5 6 7 8 9 Last