Skip to content

Commit 0234264

Browse files
authored
Merge pull request #305 from donejs/plugin-scoped-project-support
Handle scoped name of projects
2 parents 83843b8 + e25ed7f commit 0234264

File tree

4 files changed

+62
-9
lines changed

4 files changed

+62
-9
lines changed

plugin/index.js

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ module.exports = class extends BaseGenerator {
3131
this.srcFiles = [
3232
'plugin-test.js',
3333
'plugin.js',
34-
'plugin.md',
35-
'test.js'
34+
'plugin.md'
3635
];
3736
}
3837

@@ -50,6 +49,15 @@ module.exports = class extends BaseGenerator {
5049
message: 'Project name',
5150
when: !this.pkg.name,
5251
default: process.cwd().split(path.sep).pop()
52+
}, {
53+
name: 'public',
54+
type: 'confirm',
55+
message: 'Is this project public',
56+
default: true,
57+
when: function (response) {
58+
// Only prompt if the name prop starts with "@" indicating a scoped package
59+
return response.name.indexOf('@') === 0
60+
}
5361
}, {
5462
name: 'folder',
5563
message: 'Project main folder',
@@ -93,7 +101,22 @@ module.exports = class extends BaseGenerator {
93101

94102
this.prompt(prompts).then(function(props) {
95103
this.props = _.extend(this.props, props);
96-
this.props.name = _.kebabCase(this.props.name);
104+
var scopedPkgName = undefined;
105+
var pkgName = _.kebabCase(this.props.name);
106+
107+
// Parse out any scoping
108+
if (this.props.name.indexOf('@') === 0) {
109+
// Get the scope of the package
110+
var scope = this.props.name.match(/@.+\//)[0];
111+
// kebabCase the package name minus the scope
112+
// this will be used in the repository url
113+
pkgName = _.kebabCase(this.props.name.replace(scope, ''));
114+
// Create the scoped name for use in the package.json
115+
scopedPkgName = scope + pkgName;
116+
}
117+
118+
this.props.name = pkgName;
119+
this.props.pkgName = scopedPkgName || pkgName;
97120
done();
98121
}.bind(this));
99122
}.bind(this));
@@ -105,7 +128,7 @@ module.exports = class extends BaseGenerator {
105128
' ./' + this.props.folder + '/' : '';
106129
var keywords = getKeywords('plugin', this.props.keywords);
107130
var pkgJsonFields = {
108-
name: this.props.name,
131+
name: this.props.pkgName,
109132
version: '0.0.0',
110133
description: this.props.description,
111134
homepage: this.props.homepage,
@@ -125,9 +148,9 @@ module.exports = class extends BaseGenerator {
125148
testee: "testee test.html --browsers firefox",
126149
test: "npm run jshint && npm run testee",
127150
jshint: "jshint ./*.js" + jshintFolder + " --config",
128-
"release:patch": "npm version patch && npm publish",
129-
"release:minor": "npm version minor && npm publish",
130-
"release:major": "npm version major && npm publish",
151+
"release:patch": "npm version patch && npm publish".concat(this.props.public ? " --access public" : ""),
152+
"release:minor": "npm version minor && npm publish".concat(this.props.public ? " --access public" : ""),
153+
"release:major": "npm version major && npm publish".concat(this.props.public ? " --access public" : ""),
131154
build: "node build.js",
132155
develop: "done-serve --static --develop --port 8080"
133156
},

plugin/templates/test.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<!doctype html>
22
<title><%= name %></title>
3-
<script src="node_modules/steal/steal.js" main="<%= name %>/test"></script>
3+
<script src="node_modules/steal/steal.js" main="~/<%= name %>-test"></script>
44
<div id="qunit-fixture"></div>

plugin/templates/test.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/plugin.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,35 @@ describe('generator-donejs:plugin', function () {
154154
done();
155155
});
156156
});
157+
158+
it('should handle scoped package names', function (done) {
159+
var tmpDir;
160+
161+
helpers.run(path.join(__dirname, '../plugin'))
162+
.inTmpDir(function (dir) {
163+
tmpDir = dir;
164+
})
165+
.withOptions({
166+
packages: donejsPackage.donejs,
167+
skipInstall: false
168+
})
169+
.withPrompts({
170+
name: '@bitovi/my-plugin'
171+
})
172+
.on('end', function () {
173+
var child = exec('npm test', {
174+
cwd: tmpDir
175+
});
176+
177+
pipe(child);
178+
179+
child.on('exit', function (status) {
180+
assert.equal(status, 0, 'Got correct exit status');
181+
182+
assert.jsonFileContent('package.json', { name: '@bitovi/my-plugin' }, 'correct name set in package.json');
183+
assert.jsonFileContent('package.json', { main: 'dist/cjs/my-plugin' }, 'correct main set in package.json');
184+
done();
185+
});
186+
});
187+
});
157188
});

0 commit comments

Comments
 (0)