Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.

Commit eaca554

Browse files
committed
Allow project meta data to be replaced via a script
Closes #2.
1 parent a78c2b9 commit eaca554

File tree

3 files changed

+71
-1
lines changed

3 files changed

+71
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This is a simple boilerplate that has been developed to make it easier to develo
77
88
## Basic Usage
99

10+
* Replacing meta information - **npm run replace-meta** - This will allow you to update project metadata (GitHub user/project). Note that this can be potentially dangerous since it does just a naive search/replace over *README.md* and *package.json*!
1011
* Linting - **npm run lint**
1112
* Testing - **npm test** - This will lint too.
1213
* Developing - **npm start** - This will run a server at *localhost:3000* and use Hot Module Reloading.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"gh-pages": "webpack --config ./config/webpack.gh-pages.js",
1111
"deploy-gh-pages": "node ./config/deploy-gh-pages.js",
1212
"dist": "webpack --config ./config/webpack.dist.js && webpack --config ./config/webpack.dist.min.js && babel ./lib --out-dir dist-modules",
13-
"lint": "eslint . --ext .js --ext .jsx"
13+
"lint": "eslint . --ext .js --ext .jsx",
14+
"replace-meta": "node scripts/replace_meta.js"
1415
},
1516
"main": "dist-modules/index.js",
1617
"dependencies": {},
@@ -31,11 +32,13 @@
3132
"json-loader": "^0.5.1",
3233
"lodash": "^3.6.0",
3334
"markdown-loader": "^0.1.2",
35+
"prompt": "^0.2.14",
3436
"purecss": "^0.6.0",
3537
"react": "^0.13.1",
3638
"react-ghfork": "^0.3.0",
3739
"react-hot-loader": "^1.2.5",
3840
"react-tools": "^0.13.1",
41+
"replace": "^0.3.0",
3942
"style-loader": "^0.10.2",
4043
"url-loader": "^0.5.5",
4144
"webpack": "^1.8.4",

scripts/replace_meta.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
'use strict';
2+
var prompt = require('prompt');
3+
var replace = require('replace');
4+
5+
var meta = require('../package.json');
6+
7+
8+
main();
9+
10+
function main() {
11+
var originals = {
12+
user: meta.user,
13+
project: meta.name,
14+
};
15+
var schema = {
16+
properties: {
17+
user: {
18+
description: 'Enter GitHub user/organization name',
19+
default: originals.user,
20+
required: true
21+
},
22+
project: {
23+
description: 'Enter GitHub project name',
24+
default: originals.project,
25+
required: true
26+
},
27+
}
28+
};
29+
30+
prompt.start();
31+
32+
prompt.get(schema, function (err, result) {
33+
if(err) {
34+
return console.error(err);
35+
}
36+
37+
var replacementPaths = [
38+
'README.md',
39+
'package.json',
40+
];
41+
42+
if(originals.user !== result.user) {
43+
replace({
44+
regex: originals.user,
45+
replacement: result.user,
46+
paths: replacementPaths,
47+
recursive: true,
48+
silent: false,
49+
quiet: false,
50+
count: true,
51+
});
52+
}
53+
54+
if(originals.project !== result.project) {
55+
replace({
56+
regex: originals.project,
57+
replacement: result.project,
58+
paths: replacementPaths,
59+
recursive: true,
60+
silent: false,
61+
quiet: false,
62+
count: true,
63+
});
64+
}
65+
});
66+
}

0 commit comments

Comments
 (0)