小编Sim*_*mon的帖子

npm脚本使用yargs将参数/参数传递给节点脚本

当用作npm脚本参数时,是否可以调出从yargs中检索密钥?

OSX终端中的用户类型:

npm run scaffold --name=blah
Run Code Online (Sandbox Code Playgroud)

在package.json中执行:

"scaffold" : "node ./scaffold/index.js -- "
Run Code Online (Sandbox Code Playgroud)

这导致了

const yargs = require('yargs').argv

if (yargs) {
  console.log(yargs);
  console.log(yargs.name);
  process.exit(1)
}
...
result:
{ _: [], '$0': 'scaffold/index.js' }
undefined
Run Code Online (Sandbox Code Playgroud)

这只适用于我在package.json中的硬编码"scaffold" : "node scaffold/index.js --name=blah",但我需要这个是可配置的.

正如我所说,我正在使用args,因为它似乎可以很容易地按名称检索密钥(而不是数组).接受建议.

我错过了什么?

更新11-07-2017 相关:将命令行参数发送到npm脚本

但是,传递命令行1: npm run scaffold name=hello OR会2: npm run scaffold --name=hello产生:

1: { _: [], '$0': 'scaffold/index.js' }
2: { _: [ 'name=hello' ], '$0': 'scaffold/index.js' }
Run Code Online (Sandbox Code Playgroud)

仍然看不到检索yargs.name财产的方法.仍未定义.


更新13-07-2017

暂时,我放弃了.这似乎是不可能的.我在终端中手动运行脚本.例如 …

javascript npm yargs

13
推荐指数
3
解决办法
5174
查看次数

无法获得$ .ajax.mostRecentCall与jasmine 2.0.2一起使用

找到一个简单的例子工作真的很麻烦.我使用的这个例子来自https://gist.github.com/Madhuka/7854709

describe("Test for spies", function() {
 function sendRequest(callbacks, configuration) {
        $.ajax({
            url: configuration.url,
            dataType: "json",
            success: function(data) {
                callbacks.checkForInformation(data);
            },
            error: function(data) {
                callbacks.displayErrorMessage();
            },
            timeout: configuration.remainingCallTime
        });
    }

    it("should make an Ajax request to the correct URL", function() {

    var configuration = {
        url : "http://www.google.com",
        remainingCallTime : 30000
    };

        spyOn($, "ajax");

        sendRequest(undefined, configuration);
        expect($.ajax.mostRecentCall.args[0]["url"]).toEqual(configuration.url);
    });
});
Run Code Online (Sandbox Code Playgroud)

无论出于何种原因,$.ajax.mostRecentCall都是未定义的.

使用jasmine 2.0.2和jasmine jquery 2.0.5.

在这里小提琴:http://jsfiddle.net/sidouglas/85b35993/

javascript ajax jquery jasmine jasmine-jquery

12
推荐指数
1
解决办法
2932
查看次数

vue webpack 2 autoprefixer for ie9 +

使用Vuecli生成的Vue和webpack构建.有很多魔法在继续.我无法弄清楚的是如何生成IE所需的供应商前缀.

这是从github问题复制的:https://github.com/vuejs-templates/webpack/issues/421#issuecomment-284322065

VUE-loader.conf.js

var utils = require('./utils')
var config = require('../config')
var isProduction = process.env.NODE_ENV === 'production'

module.exports = {
  loaders: utils.cssLoaders({
    sourceMap: isProduction
      ? config.build.productionSourceMap
      : config.dev.cssSourceMap,
    extract: isProduction
  }),
  postcss: [
    require('postcss-import')(),
    require('autoprefixer')({
      browsers: ['ie >= 9']
    })
  ]
}
Run Code Online (Sandbox Code Playgroud)

简单容器组件示例

容器/ index.vue

<template>
    <div class="container">
        <slot></slot>
    </div>
</template>
<script>
    import './index.scss'
    export default {}
</script>
Run Code Online (Sandbox Code Playgroud)

容器/ index.scss

// this is aliased in webpack.base.conf
@import "~styles/base-config";

.container {
  @include grid(); // this generates display:flex and …
Run Code Online (Sandbox Code Playgroud)

webpack vue.js vuejs2 vue-cli

10
推荐指数
1
解决办法
1775
查看次数

将对象作为属性传递给已编译的指令

我在页面上有一个角度元素,需要与其他非角度页面元素进行通信.

我正在创建指令元素,并将其附加到其目标div.我试图传递该创建的指令一个对象(ajax对象),它只包含属性.

问题是我无法弄清楚如何将这个ajax对象传递给指令,因为$ compile需要一个范围.当http结束,并且因为我必须=在指令中使用时,指令被覆盖.

请看我的插件:https://plnkr.co/edit/brTWgUWTotI44tECZXlQ (抱歉图片).单击<button>以触​​发指令.

(function() {
'use strict';
var CHANNEL = 'podOverlay';
angular.module('CavernUI', [])
  .controller('CavernCtrl', function($scope,getItemService) {

    $scope.model = {};
    var _pods = $scope.model.pods = {};

    function getData(selector) {
      $(selector).each(function(i, pod) {
        _pods[+pod.dataset.item] = {
          $: $(pod)
        };
      });

      Object.keys($scope.model.pods).map(function(key) {
        getItemService.getItem(key).success(function(response) {
          _pods[key] = angular.extend(_pods[key], response);
          $scope.$broadcast(CHANNEL, _pods[key], $scope);
        });
      })
    }

    $scope.runPodCheck = function(selector) {
      getData(selector);
    }
  })
  .directive('podchecker', function($compile) {

     var createOverlay = function(e,data,scope){
         scope.data = data;
         // can …
Run Code Online (Sandbox Code Playgroud)

directive angularjs

8
推荐指数
1
解决办法
2240
查看次数

不知道如何使用angular2类中的接口实现枚举

在这里绕圈子.对Typescript来说是一个新手,它引起了一些令人头疼的琐碎实现.

如何定义AgentStatusService它应该有一个名为4个选项的数组['offline','available','busy','away']?AgentStatus是定义的(或者是?),我将它注入到AgentStatusService.

Microsoft Visual Studio Code在第21行进行了barfing,其中类型'typeof AgentStatus'不能分配给'AgentStatus'类型...为什么?

更新:

import { EventEmitter, Injectable } from '@angular/core';

export enum AgentStatus {
    available =1 ,
    busy = 2,
    away = 3,
    offline = 0
}

export interface IAgentStatusService {
    state: number
    states: AgentStatus
}
@Injectable()
export class AgentStatusService implements IAgentStatusService {

    state:number;  // this really should be string, but line 22 returns a number
    states:AgentStatus;

    constructor(states:typeof AgentStatus = AgentStatus){
        // unreacheable code browser_adapter.ts:78EXCEPTION: Error: Uncaught (in promise): …
Run Code Online (Sandbox Code Playgroud)

typescript angular2-forms angular2-services angular

8
推荐指数
1
解决办法
6784
查看次数

具有输入范围的HTML音频辅助功能

最小的问题示例:https//codepen.io/sidouglas/pen/LYPZaOG

当输入范围集中在Chrome Vox或Mac的Voice over上时-的每个值valuetext都会连续读出。

<input
 ...
  v-bind:aria-valuemax="valueMax"
  v-bind:aria-valuenow="valueNow"
  v-bind:aria-valuetext="currentTime + ' of ' + totalDuration"
  ...
/>
Run Code Online (Sandbox Code Playgroud)

将此与非常易于访问的https://plyr.io/#audio组件进行对比-当重点关注时,它会继续更新其aria值,但只向屏幕阅读器宣布两次。

有人知道吗?

<input
 ...
  v-bind:aria-valuemax="valueMax"
  v-bind:aria-valuenow="valueNow"
  v-bind:aria-valuetext="currentTime + ' of ' + totalDuration"
  ...
/>
Run Code Online (Sandbox Code Playgroud)
new Vue({
  el: '#range',
  data: {
    valueMax:100,
    duration:100,
    current:0,
    totalDuration:'1:40'
  },
  computed:{
    currentTime: function() {
      return this.convertTime(this.current);
    },
     valueNow() {
      return Math.round(this.current);
    },
  },
  methods: {
    convertTime(time) {
      const minutes = Math.floor(time / 60);
      const seconds = time …
Run Code Online (Sandbox Code Playgroud)

javascript accessibility uiaccessibility vue.js

7
推荐指数
1
解决办法
78
查看次数

要导入的文件未找到或不可读:susy

我无法弄清楚我与Susy的设置有什么问题.我在OS X 10.7.4上

我跟在这里:http://susy.oddbird.net/guides/getting-started/

错误

Syntax error: File to import not found or unreadable: susy.
Load paths:
Users/simon/Websites/wpsvntree/trunk/sass
/Users/simon/.gem/ruby/1.8/gems/compass-0.11.7/frameworks/blueprint/stylesheets
/Users/simon/.gem/ruby/1.8/gems/compass-0.11.7/frameworks/compass/stylesheets
            Compass::SpriteImporter
on line 2 of /Users/simon/Websites/wpsvntree/trunk/sass/_base.sass
from line 2 of /Users/simon/Websites/wpsvntree/trunk/sass/screen.sass
Run Code Online (Sandbox Code Playgroud)

我安装的宝石:

*** LOCAL GEMS ***

chunky_png (1.2.6, 1.2.5)
compass (0.12.2, 0.11.7)
compass-boilerplate-plugin (0.1.0)
compass-h5bp (0.0.5, 0.0.2)
compass-rails (1.0.3)
fssm (0.2.9, 0.2.8.1)
html5-boilerplate (2.1.0)
sass (3.2.1, 3.1.15)
susy (1.0.3)
Run Code Online (Sandbox Code Playgroud)

我的config.rb文件位于项目的根目录中

require 'susy' 
# Require any additional compass plugins here.

# Set this to the root of your …
Run Code Online (Sandbox Code Playgroud)

susy-compass compass-sass

6
推荐指数
1
解决办法
2万
查看次数

jQuery数据绑定库或插件推荐

停止完整的框架,如Angular,Knockout等,任何人都可以推荐一个简单的数据绑定jQuery插件?

购买车需要一个页面应用程序,需要在ajax完成后更新页面上的某些元素.只需要遍历字段并更新用户界面.

是的,我知道我可以自己写点东西,但是如果已经存在某些东西,我不想重新发明轮子.

我的研究引导我进入jquery.bindings - 但它并不受欢迎(只有一个贡献者)

建议?

data-binding ajax jquery plugins jquery-plugins

6
推荐指数
1
解决办法
1876
查看次数

Nightwatch.js通过配置文件设置测试环境

Noob节点警告:如何以编程方式设置运行测试时要使用的配置对象?

一直在努力寻找明确的答案.

建立:

/e2e-tests
    |-globals.js
    |-product.page.notify.stock.js
|-nightwatch.json 
|-nightwatch 
Run Code Online (Sandbox Code Playgroud)

var SITE_URL = 'http://dev.local/', //this needs to be set somehow production||dev
  AJAX_URL = 'ajaxproc/getrandomoutofstock', //relative so this doesn't need to change
  select = '#mysize',
  emailError = '.error-message',
  outOfStockItem = {
    id: false,
    url: false
  };

module.exports = {
  'Get backorder stock url': function(browser) {
    browser.url(SITEURL + AJAX_URL)
      // ommitted for brevity
  },
  'Check notify stock on product page': function(client) {

    client.url(SITE_URL + outOfStockItem.url); …
Run Code Online (Sandbox Code Playgroud)

javascript config node.js nightwatch.js

6
推荐指数
1
解决办法
7730
查看次数

VueJS将所有道具传递给子组件

我对VueJS很新.在反应中,您可以轻松使用休息参数将道具传递给儿童.Vue中有类似的模式吗?

考虑具有一些子组件的父组件:

<template>
<header class="primary-nav">
<search-bar :config="searchBar"><search-bar>
//          ^^^^ this becomes the key on the props for SearchBar
header>
</template>

export default {
  data(){
    return {
      ... a few components ...
      searchBar : {
        model: '',
        name: 'search-bar',
        placeholder: 'Search Away',
        required:true,
        another: true
        andanother: true,
        andonemoreanotherone:true,
        thiscouldbehundredsofprops:true
      }
    }
  }
}

<template>
    <div :class="name">
        <form action="/s" method="post">
            <input type="checkbox">
            <label :for="config.name" class="icon-search">{{config.label}}</label>
            <text-input :config="computedTextInputProps"></text-input>
                        //^^^^ and so on. I don't like this config-dot property structure.
        </form>
    </div>
</template>

  export …
Run Code Online (Sandbox Code Playgroud)

javascript rest vue.js

6
推荐指数
3
解决办法
1万
查看次数