我正在为Angular2使用一个非常优秀的小部件库,名为PrimeNg。
假设PrimeNg缺少我需要的一些功能,所以我分叉回购并提交一个 pull request让我的更改进入主要版本 回购。当我在等待拉取请求被接受时,我想包括我的分支 我的package.json中的repo。
我尝试更新我的package.json:
"dependencies": {
...
"primeng": "1.0.0-beta.13",
...
}
对此:
"dependencies": {
...
"primeng": "JakeSummers/primeng.git#d35f5635a216005018bed89d249816e0f65f68f6",
...
}
不幸的是,这不起作用。
查看我的node_modules目录,我们发现它基本上是空的:
[Aug-30 18:04][node_modules]$ tree primeng/
primeng/
├── LICENSE.md
├── package.json
└── README.md
0 directories, 3 files
在更改我的package.json之前,该目录包含以下内容:
primeng/
├── components
│ ├── accordion
│ │ ├── accordion.d.ts
│ │ ├── accordion.js
│ │ └── accordion.js.map
│ ├── autocomplete
│ │ ├── autocomplete.d.ts
│ │ ├── autocomplete.js
│ │ └── autocomplete.js.map
│ ├── breadcrumb
│ │ ├── breadcrumb.d.ts
│ │ ├── breadcrumb.js
│ │ └── breadcrumb.js.map
│ ├── button
│ │ ├── button.d.ts
│ │ ├── button.js
│ │ └── button.js.map
│ ├── calendar
│ │ ├── calendar.d.ts
...
├── LICENSE.md
├── package.json
├── primeng.d.ts
├── primeng.js
├── primeng.js.map
├── prod
│ ├── application.js
│ ├── polyfills.js
│ └── vendor.js
└── README.md
62 directories, 195 files
进一步观察package.json docs,看起来我可能没有做
对于非特定于平台的构建步骤,例如将CoffeeScript或其他语言编译为JavaScript,请使用预发布脚本执行此操作,并使所需的包成为devDependency。
例如:
{ "name": "ethopia-waza",
"description": "a delightfully fruity coffee varietal",
"version": "1.2.3",
"devDependencies": {
"coffee-script": "~1.6.3"
},
"scripts": {
"prepublish": "coffee -o lib/ -c src/waza.coffee"
},
"main": "lib/waza.js"
}
预发布脚本将在发布之前运行,以便用户可以使用该功能而无需他们自己编译。在开发模式下(即本地运行npm install),它也会运行此脚本,以便您可以轻松地进行测试。
primeNg项目的package.json没有预发布脚本,我在讨论是否需要添加一个,如果是这样的话怎么样?该脚本何时运行?它会在git repo的拉动下运行吗?
任何指针或示例都将不胜感激。谢谢!
答案 0 :(得分:4)
问题是你在Typescript中有源代码,但你需要在npm包中编译JS。不幸的是:
.npmignore
档案excludes所有打字稿来源; public class loginActivity extends AppCompatActivity
{
private static final int MY_PERMISSIONS_REQUEST = 0;
EditText email,password;
Button login;
String emailCred,passwordCred;
TextView emailer,caller;
static csBar cShowProgress = csBar.getInstance();
String tag_login_req = "tag_login_req";
static ArrayList<child> childModel;
private static final String loggedInParentTracker = "loggedIn";
SharedPreferences sharedpreferences;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
email = (EditText)findViewById(R.id.email);
password = (EditText)findViewById(R.id.password);
emailer = (TextView) findViewById(R.id.emailIcon);
caller = (TextView) findViewById(R.id.callIcon);
emailer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Email();
}
});
caller.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view)
{
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(loginActivity.this,Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED)
{
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(loginActivity.this, new String[]{Manifest.permission.CALL_PHONE},MY_PERMISSIONS_REQUEST);
}
else
{
Call();
}
}
});
// Let's mark this ViewGroup as an icon container
Typeface iconFont = FontManager.getTypeface(getApplicationContext(),FontManager.FONTAWESOME);
FontManager.markAsIconContainer(findViewById(R.id.icons_container),iconFont);
ConnectivityManager cm = (ConnectivityManager)this.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
final boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
login = (Button)findViewById(R.id.email_sign_in_button);
login.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
emailCred = email.getText().toString();
passwordCred = password.getText().toString();
if(emailCred.isEmpty())
{
email.setError("Enter your Email");
}
else if(passwordCred.isEmpty())
{
password.setError("Enter your Password");
}
else if(!isConnected)
{
Toast.makeText(loginActivity.this,"Sorry,Please connect to a network",Toast.LENGTH_LONG).show();
}
else
{
cShowProgress.showProgress(loginActivity.this);
try{
makeRequest(emailCred,passwordCred);
}
catch (Exception ex)
{
Toast.makeText(loginActivity.this,"Error logging in,Please try again",Toast.LENGTH_LONG).show();
}
}
}
});
}
public void makeRequest(final String user, final String cred)
{
//the url we are posting the request to
String url = "http://mobile.map.education/api/login";
sharedpreferences = getSharedPreferences(loggedInParentTracker, Context.MODE_PRIVATE);
//the post request function
StringRequest postRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>()
{
@Override
public void onResponse(String response)
{
csBar.hideProgress();
try
{
JSONObject jsonResponse = new JSONObject(response);
String status = jsonResponse.getString("status");
JSONArray children = (JSONArray) jsonResponse.get("child");
JSONArray img = (JSONArray) jsonResponse.get("passport");
if(status.equalsIgnoreCase("error"))
{
Toast.makeText(loginActivity.this,jsonResponse.getString("message"),Toast.LENGTH_LONG).show();
}
else if (status.equalsIgnoreCase("success"))
{
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString("loggedIn",emailCred);
editor.apply();
profileService(user);
ptaService();
newsService();
fromResponse(children,img);
Intent loader = new Intent(loginActivity.this,childSelect.class);
startActivity(loader);
}
}
catch (JSONException e)
{
e.printStackTrace();
}
}
},
//this handles any errors the volley package gets
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error)
{
error.printStackTrace();
}
}
){
//this is a method to set the parameters we are sending to be in the proper format
@Override
protected Map<String, String> getParams()
{
Map<String, String> params = new HashMap<>();
//the proper format of the login parameters is portal[parameter name goes here]
params.put("portal[username]", user);
params.put("portal[password]", cred);
params.put("portal[From]","web");
return params;
}
};
//this is a retry policy that has been set to deal with timeout errors
postRequest.setRetryPolicy(new DefaultRetryPolicy(
30000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
try{
queuer.getInstance().addToRequestQueue(postRequest, tag_login_req);
}
catch (Exception ex)
{
Toast.makeText(loginActivity.this,"Error logging in,Please try again",Toast.LENGTH_LONG).show();
}
}
,意味着它不会被devDependencies
拉动; npm install --production
或prepublish
脚本可以自动编译。您可能会从这些点看到解决方案的内容;几点想法:
postinstall
文件编译并签入git repository; .js
脚本编译为npm publish
的一部分; prepublish
的一部分:
npm install
; .ts
个文件
.npmignore
提取到devDependencies
; dependencies
脚本。第一个选项最容易实现,但也最容易出错 - 在提交之前很容易忘记运行编译步骤,所以你可能想要将它添加到git hook中。但在那时,你最好选择第二或第三阶段。
如果您决定使用自己的第二个并使用自己的分支,请确保在安装软件包时执行postinstall
脚本。
从Github *
安装看起来你提到的prepublish
是正确的,但我会提倡更明确的格式:
npm install
* // The thing that actually gets saved into `package.json`:
github:${username}/${repository}#${optional-id}
// So the command would be:
npm install github:JakeSummers/primeng#d35f5635a216005018bed89d249816e0f65f68f6
还支持从自己的registry和github以外的地方安装,看看“包”是什么here,如果你很好奇。
答案 1 :(得分:-2)
最简单的方法就是在master上创建你想要的代码,然后将它作为普通的JakeSummer/primeng
列在package.json中。
如果您需要重新运行发布内容,则在推送代码之前执行此操作,可能是npm run prepublish
之类的命令。并非所有包都需要,所以如果它没有它,请不要这样认为。