Skip to content

chore: add 3.4 en documents to en folder, add 3.4 zh-cn documents to … #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions README.md

This file was deleted.

87 changes: 87 additions & 0 deletions en/css-and-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Handle css and template

---

Css and html template are significant parts in front-end development, and spm is just good for it.

## Css

The spm package could be a pure css package, use `main` and `output` to specify endpoint files.

For Example, there is a `main-style` package for our site layout:

```
button.css
tip.css
index.css
package.json
```

```json
{
"name": "main-style",
"version": "1.0.0",
"spm": {
"dependencies": {
"normalize.css": "3.0.1"
},
"main": "index.css"
}
}
```

Simply import files and other packages by a standard `@import`.

```
/* index.css */
@import url(http://github.com/'normalize.css');

@import url(http://github.com/'./button.css');
@import url(http://github.com/'./tip.css');
```

[alice-button](https://github.com/aliceui/button) is a nice example as well.

You can also require css package in js file, just like js package but without exports.

```
require('main-style');
var moment = require('moment');
```

spm will use [import-style](http://spmjs.io/package/import-style) to import css package's content after building.


## Template

Fisrtly, write your template in file, named it as `*.html` or `*.tpl` or `*.handlebars`.

```html
<!-- defalut.tpl -->
<div>
<span>{{name}}</span>
<span>{{content}}</span>
</div>
```

Then require it in js file.

```js
var Handlebars = require('handlebars');
var source = require('./defalut.tpl'); // string content of defalut.tpl

var template = Handlebars.compile(source); // compile it with your compiler
var result = template({
name: 'alex',
content: 'content'
});
```

If the extension is `.handlebars`, `spm build` will precompile it and import [handlebars-runtime](http://spmjs.io/package/handlebars-runtime) automaticly for better perfermance, just similar with css's procedure.


## Precompile language

People prefer a lot precompile languages both for css and template, such as [less](http://lesscss.org/), [scss](http://sass-lang.com/), [mustache](https://github.com/janl/mustache.js), [Hogan.js](https://github.com/twitter/hogan.js), [doT](https://github.com/olado/doT) and etc.

Consider [spm.scripts](/documentation/package.json#fields) in package.json for precompileing procedure.
198 changes: 198 additions & 0 deletions en/develop-a-package.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
# Develop A Package

---

You can follow the steps to develop a package using [spm](https://github.com/spmjs/spm).

```
$ spm --version
3.x.x
```

Make sure that [email protected] is installed.

## init

```bash
$ mkdir now
$ cd now
$ spm init
```

```
Creating a spm package:
[?] Package name: (now)
[?] Version: (1.0.0)
[?] Description:
[?] Author: afc163 <[email protected]>

Initialize a spm package Succeccfully!
```

Then you have a package named `now`.

## Install dependencies

Install default devDependencies first.

```bash
$ spm install
```

We need [moment](http://momentjs.com) as a dependency which can be found [here](http://spmjs.io/package/moment).

```bash
$ spm install moment --save
```

## Code and Debug

Edit `index.js` as follow, just like nodejs.

```javascript
// require module in spm.dependencies
var moment = require('moment');

// require relative file in you project
// var util = require('./util');

var now = moment().format('MMMM Do YYYY, h:mm:ss a');
module.exports = now;
```

Then edit `examples/index.md`:

<pre>
# Demo

---

## Normal usage

````javascript
var now = require('../index');
console.log(now);
````
</pre>


Run `spm doc` to start a documentation service at `127.0.0.1:8000` .

```bash
$ spm doc
```

Open [http://127.0.0.1:8000/examples/](http://127.0.0.1:8000/examples/) in browser to see the result.

Except using three &#96; in Markdown file, you can also use four &#96; to wrap your code.

It is a special rule that make your code highlighted and would be inserted to document page as a script block so they can be excuted at the same time. That is very useful for debugging your demo and writing a beautiful documentation both.

If you want to insert a iframe in your demo, make your code to `iframe` type.

<pre>
````iframe:600
I am in a iframe of 600px high
````
</pre>


> If you don't want to debug your code by `spm doc`, you can try [seajs-wrap](https://github.com/seajs/seajs-wrap) or [spm-server](https://github.com/spmjs/spm-server/) to debug `CommonJS` modules in development.

## Add Test Case

Edit test file at `tests/now-spec.js`. We introduce a default assert solution [expect.js](http://spmjs.io/package/expect.js).

```javascript
var expect = require('expect.js');
var now = require('../index');

describe('now', function() {

it('normal usage', function() {
expect(now).to.be.a('string'); // add this
});

});
```

See tests result.

```bash
$ spm test
```

You can also open [http://127.0.0.1:8000/tests/runner.html](http://127.0.0.1:8000/tests/runner.html) in browser.

## Publish

Now you have a great package having wonderful function and complete tests case, you can publish the package to [spmjs.io](http://spmjs.io/).

```bash
$ spm publish
```

You should run `spm login` first to get permission, otherwise it would propmt the authorization problem.

```bash
$ spm login
```

`username` is the name of your github account, and `authkey` can be found at http://spmjs.io/account after signing in.

> The package `now` is published by me, of cause. You should change other name and retry.

## Documentation

spmjs.io can host your package's documentation. What all you need to do is editing `README.md` and `examples` folder, preview it by `spm doc watch`, then publish it to spmjs.io.

```bash
$ spm doc publish
```

The documentation url is `http://spmjs.io/docs/{{name}}/` for latest version and `http://spmjs.io/docs/{{name}}/{{version}}/` for each versions.

For example, http://spmjs.io/docs/now/.

## Build

```bash
$ spm build
```

This command will build the files indicated by `spm.main` and `spm.output` field to `dist` folder. The `spm.buildArgs` would be executed as arguments.

The default build result is a package which could be deployed at cdn. Then you can use it by using [Sea.js](https://github.com/seajs/seajs/), [[email protected]](https://raw.githubusercontent.com/seajs/seajs/2.2.1/dist/sea.js) for example.


```html
<script src="http://cdn.example.com/path/to/sea.js"></script>
<script src="http://cdn.example.com/path/to/seajs-combo.js"></script><!-- If your need that -->
<script>
seajs.config({
base: 'http://cdn.example.com/',
alias: {
now: 'now/1.0.0/index.js'
}
});
// load http://cdn.example.com/??now/1.0.0/index.js,moment/2.6.0/moment.js
seajs.use(['now'], function(now) {
console.log(now);
});
</script>
```

And We strongly recommend building a [standalone](/documentation/spm-commands#spm-build) package by adding an argument.

```bash
$ spm build --include standalone
```

```html
<!-- use it without loader -->
<script src="http://cdn.example.com/path/to/standalone.js"></script>
```

## Congratulation

Now you learn how to develop a package using spm, welcome to publish your packages here!
21 changes: 21 additions & 0 deletions en/difference-from-2.x.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Difference From [email protected]

---

[[email protected]](https://github.com/spmjs/spm/tree/master) is new version of [[email protected]](https://github.com/spmjs/spm/tree/2.x), we have a collection of updates now.

- [spmjs.org](https://spmjs.org) is package service for [email protected], now is [spmjs.io](http://spmjs.io) which is prettier and easier to [deploy in your company](https://github.com/spmjs/spmjs.io/).

- Change spm profile from `~/.spm/spmrc` to `~/.spm/spmrc-3x`.

- `family` is removed from package.json.

- `spm.alias` is replaced by `spm.dependencies` now.

- `spm doc`, `spm init`, `spm build`, `spm test` are integrated to spm commands.

- [docs.spmjs.org](http://docs.spmjs.org) is old documentation for [email protected].

- No need to build first before publish, the package only contains source code. Building is needed just before using in your website.

- [迁移 spm2 到 spm3](https://github.com/spmjs/spm/wiki/%E8%BF%81%E7%A7%BB-spm2-%E7%9A%84%E6%A8%A1%E5%9D%97%E5%88%B0-spm3)
Loading