Skip to content

Commit

Permalink
Refactored to support yeoman-generator v3
Browse files Browse the repository at this point in the history
no issue
  • Loading branch information
sam-lord committed Mar 9, 2023
1 parent 18b1277 commit b28d7f3
Show file tree
Hide file tree
Showing 3 changed files with 1,626 additions and 65 deletions.
47 changes: 22 additions & 25 deletions packages/slimer/lib/cli-yo.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,18 @@ class CliYo {
this.loaded = false;
}

loadEnv(cb) {
env.lookup(() => {
this.loaded = true;
cb();
});
loadEnv() {
env.lookup();
this.loaded = true;
}

findGenerator(name, cb) {
findGenerator(name) {
// @TODO: validation / error handling
if (!this.loaded) {
return this.loadEnv(() => cb(env.get(name)));
this.loadEnv();
}

return cb(env.get(name));
return env.get(name);
}

initGeneratorHelp(Generator) {
Expand All @@ -53,26 +51,25 @@ class CliYo {
}

yoToSywac(name, cb) {
this.findGenerator(name, (Generator) => {
let {args, options} = this.initGeneratorHelp(Generator);
const yoDefaults = ['help', 'skip-cache', 'skip-install'];

const toSywac = (t) => {
let tt = _.clone(t);
tt.type = t.type.name.toLowerCase();
tt.flags = `--${t.name}`;
tt.defaultValue = t.default;
return tt;
};
const Generator = this.findGenerator(name);
let {args, options} = this.initGeneratorHelp(Generator);
const yoDefaults = ['help', 'skip-cache', 'skip-install'];

const toSywac = (t) => {
let tt = _.clone(t);
tt.type = t.type.name.toLowerCase();
tt.flags = `--${t.name}`;
tt.defaultValue = t.default;
return tt;
};

args = _.map(args, toSywac);
args = _.map(args, toSywac);

options = _(options).filter((opt) => {
return !_.includes(yoDefaults, opt.name);
}).map(toSywac).value();
options = _(options).filter((opt) => {
return !_.includes(yoDefaults, opt.name);
}).map(toSywac).value();

cb(args, options);
});
cb(args, options);
}

callGenerator(name, argv, cb) {
Expand Down
2 changes: 1 addition & 1 deletion packages/slimer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
"is-public": "^1.1.0",
"lodash": "^4.17.11",
"mkdirp": "^0.5.1",
"yeoman-environment": "^2.3.3"
"yeoman-environment": "^3.15.1"
}
}
Loading

0 comments on commit b28d7f3

Please sign in to comment.