UNPKG

6.83 kBJavaScriptView Raw
1// This file is the source for constructing a `package.json` file.
2// JSON is a wonderful interchange format, but due to the fact that the
3// [JSON Specification](http://json.org) does not allow for comments, I find
4// it horrid for self documenting examples.
5//
6// JavaScript allows for comments and inherently allows JSON. This file will
7// act as the source for building a `package.json` file that also manages this
8// package.
9//
10// It is the closest I can get to a self-documenting `package.json` file.
11
12
13
14// The `package.json` file always consists of one top level object, which is
15// what we export here in a [Node.js](http://nodejs.org) friendly way that
16// will allow us to build our `package.json` file. A real `package.json` file
17// will not contain the `exports = ` definition, nor any of these comments.
18module.exports = {
19 // Many of the following `package.json` parameters are optional depending
20 // on whether or not this package will ever be published, and depending
21 // on how much management we want to delegate to npm. I did not mark
22 // optional vs. not-optional for the parameters, as a `package.json` file
23 // is by its nature always optional.
24
25 // Our npm package name needs to be unique only if we are going to publish
26 // our package into an npm registry. If we aren't going to publish the
27 // package the name can be anything we want.
28 //
29 // Leave off redundant affixes like `node-package` or `package-js`.
30 // We know it is JavaScript for Node.
31 "name": "projectname",
32 // A single line, or sometimes slightly longer, description of our package.
33 "description": "Clone this project to scaffold a new (npm/node) project.",
34 // [npm](http://npmjs.org) enforces the X.Y.Z semantic version
35 // scheme that is described at [http://semver.org/](http://semver.org/)
36 // and we should follow this versioning for our package.
37 "version": "0.1.0",
38 // URL to the homepage for this package.
39 "homepage": "https://github.com/michieljoris/projectname",
40 // An array of keywords used to describe this package to search engines,
41 // mainly for people searching within the npm universe.
42 "keywords": [
43
44 ],
45 // Where is the source of truth for this code, and what type of repo is it?
46 "repository": {
47 "type": "git",
48 "url": "https://github.com/michieljoris/projectname.git"
49 },
50 // Every package should have at least one author. There are a couple of
51 // formats for the author. I prefer the explicit object format as follows:
52 "author": {
53 "name": "Michiel van Oosten",
54 "email": "mail@axion5.net",
55 "url": "http://www.axion5.net/"
56 },
57 // What licenses govern this code, and where is the license associated
58 // with this code?
59 // The complex form, "licenses", is an array of objects.
60 // The simplest form is "license", and may point to just a string that
61 // represents the standard name of the license, like "MIT".
62 "licenses": [
63 {
64 "type": "MIT",
65 "url": "http://github.com/michieljoris/projectname/blob/master/LICENSE.txt"
66 }
67 ],
68 // If there is a file that should be loaded when require()ing this
69 // folder-as-a-package, declare this file here, relative to our package
70 // structure.
71 "main": "src/projectname.js",
72 // Essentially, which Node.js platforms do we support? These are glob
73 // like expressions supported by the
74 // [npm semantic version parser](https://npmjs.org/doc/semver.html),
75 // and the below version means what it looks like:
76 //
77 // require a Node.js installation that is greater than or equal to version 0.6.0
78 "engines": {
79 "node": ">= 0.6.x"
80 },
81 // What other modules/libraries do we require for our own module?
82 // The beauty of this dependencies block is that these modules will
83 // be downloaded magically when we run npm install from within our
84 // directory. npm itself will sort out any dependency conflicts within
85 // our own dependencies and we can be pretty much assured that the
86 // modules we need will be ready to run.
87 //
88 // **NOTE:** We don't have any dependencies for this module. See the
89 // `devDependencies` block for the way to include dependencies.
90 "dependencies": {
91 // "bb-server": "0.4.x",
92 // "html-builder": "0.1.x",
93 "bb-server": "git://github.com/michieljoris/bb-server.git",
94 "html-builder": "git://github.com/michieljoris/html-builder.git",
95 "fs-extra": "0.8.x"
96
97 // "nodemailer": "*",
98 // "dbox": "*",
99 // "nodemailer": "0.5.x",
100 // "dbox": "0.6.x",
101 // "colors": "*",
102 },
103 // What dependencies are useful only for developers?
104 // Installed when we `npm install` in our working directory, but not
105 // when people require our package in their own package.json. This is the
106 // usual and accepted place to put test frameworks and documentation
107 // tools.
108 //
109 // The packages we depend on for development:
110 //
111 // * **fs-extra**: Mixin for the fs (filesystem) module.
112 // * **doccoh**: Documentation utility for this code.
113 "devDependencies": {
114 // "doccoh": "*"
115 "docco": "*"
116 },
117 // Should this package be prevented from accidental publishing by npm?
118 // The default is false (not hidden), but I include this here for doc
119 // purposes.
120 "private": false,
121 // npm has can manage a set of standard and non-standard scripts. The
122 // standard set of scripts can be run with:
123 //
124 // npm standard-script-name
125 //
126 // The non-standard scripts can be run with:
127 //
128 // npm run-script script-name
129 //
130 // `docs` is a non-standard script, and can be run with:
131 //
132 // npm run-script docs
133 "scripts": {
134 // "docs": "node node_modules/.bin/doccoh package.js"
135 "docs": "node node_modules/.bin/docco src/projectname.js"
136 }
137};
138
139
140// Small script used to write the package.json file out from the package.js
141// file.
142
143var fs = require("fs-extra");
144var packagejs = require("./package.js");
145var v = '0.1.0';
146if (!packagejs.version) {
147
148 try {
149 v = require('./package.json').version;
150 } catch(e) {
151 console.log('Created new package.json. You\'re at version 0.0.0.');
152 }
153 var s = v.split('.');
154 v = [s[0],s[1],parseInt(s[2]) + 1].join('.');
155 packagejs.version = v;
156}
157
158console.log("Writing the package.json file out from package.js...");
159fs.writeJSONFile("package.json", packagejs, function(err){
160 if (err) {
161 console.log("Error writing package.json");
162 console.log(err);
163 console.log("");
164 }
165 else {
166 console.log(packagejs);
167 console.log("package.json written successfully.");
168 console.log("");
169 }
170});