Skip to content

Commit

Permalink
Quick pass at bootstrapping.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashryanbeats committed May 23, 2019
1 parent 571cd5a commit df32abd
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 30 deletions.
65 changes: 65 additions & 0 deletions commands/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2018 Adobe Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const fs = require("fs");
const path = require("path");
const shell = require("shelljs");

const dirname = "my-plugin";
const fileNames = [
"CODE_OF_CONDUCT.md",
"LICENSE",
"CONTRIBUTING.md",
"PULL_REQUEST_TEMPLATE.md",
"COPYRIGHT",
"ISSUE_TEMPLATE.md"
];

function bootstrap(opts, args) {
if (!shell.which("git")) {
shell.echo("Sorry, `xdpm bootstrap` requires git.");
shell.exit(1);
}

// git clone from I/O console starter proj
shell.exec(
`git clone [email protected]:AdobeXD/io-console-starter-project.git ${dirname}`,
function(code, stdout, stderr) {
if (code === 0) {
cleanupClone();
} else {
shell.echo("Failed to clone starter project.");
}
}
);
}

function cleanupClone() {
const dirpath = path.resolve(`./${dirname}/`);

fileNames.forEach(filename => {
fs.unlink(`${dirpath}/${filename}`, err => {
if (err) {
shell.echo("err");
shell.exit(1);
}
});
});

shell.rm("-rf", `${dirpath}/.git`);
}

module.exports = bootstrap;
75 changes: 45 additions & 30 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,52 +21,67 @@ const package = require("./package.json");
cli.enable("status");

const commands = {
"install": "Install a plugin in development mode",
"ls": "List all plugins in development mode",
"package": "Package a plugin",
"validate": "Validate a plugin's manifest",
"watch": "Watch a plugin directory. If no directory is specified, `.` is assumed",
bootstrap: "Create a new plugin scaffold",
install: "Install a plugin in development mode",
ls: "List all plugins in development mode",
package: "Package a plugin",
validate: "Validate a plugin's manifest",
watch:
"Watch a plugin directory. If no directory is specified, `.` is assumed"
};

const options = {
clean: ["c", "Clean before install", "bool", false],
json: ["j", "If true, indicates that JSON output should be generated", "bool", false],
// mode: ["m", "Indicates which plugin mode to use", ["d", "p"], "d"],
overwrite: ["o", "Allow overwriting plugins", "bool", false],
which: ["w", "Which Adobe XD instance to target", ["r", "p", "d", "release", "pre", "prerelease", "dev", "development"], "r"],
clean: ["c", "Clean before install", "bool", false],
json: [
"j",
"If true, indicates that JSON output should be generated",
"bool",
false
],
// mode: ["m", "Indicates which plugin mode to use", ["d", "p"], "d"],
overwrite: ["o", "Allow overwriting plugins", "bool", false],
which: [
"w",
"Which Adobe XD instance to target",
["r", "p", "d", "release", "pre", "prerelease", "dev", "development"],
"r"
]
};

const parsedOpts = cli.parse(options, commands);

if (parsedOpts.json) {
cli.status = function() {};
cli.status = function() {};
} else {
cli.info(`xdpm ${package.version} - XD Plugin Manager CLI`);
cli.info(`Use of this tool means you agree to the Adobe Terms of Use at
cli.info(`xdpm ${package.version} - XD Plugin Manager CLI`);
cli.info(`Use of this tool means you agree to the Adobe Terms of Use at
https://www.adobe.com/legal/terms.html and the Developer Additional
Terms at https://wwwimages2.adobe.com/content/dam/acom/en/legal/servicetou/Adobe-Developer-Additional-Terms_en_US_20180605_2200.pdf.`)
Terms at https://wwwimages2.adobe.com/content/dam/acom/en/legal/servicetou/Adobe-Developer-Additional-Terms_en_US_20180605_2200.pdf.`);
}

const { command, args } = cli;

if (parsedOpts.which) {
parsedOpts.which = parsedOpts.which[0];
parsedOpts.which = parsedOpts.which[0];
}

switch (command.toLowerCase()) {
case "ls":
require("./commands/ls")(parsedOpts, args);
break;
case "install":
require("./commands/install")(parsedOpts, args);
break;
case "watch":
require("./commands/watch")(parsedOpts, args);
break;
case "package":
require("./commands/package")(parsedOpts, args);
break;
case "validate":
require("./commands/validate")(parsedOpts, args);
break;
case "ls":
require("./commands/ls")(parsedOpts, args);
break;
case "install":
require("./commands/install")(parsedOpts, args);
break;
case "watch":
require("./commands/watch")(parsedOpts, args);
break;
case "package":
require("./commands/package")(parsedOpts, args);
break;
case "validate":
require("./commands/validate")(parsedOpts, args);
break;
case "bootstrap":
require("./commands/bootstrap")(parsedOpts, args);
break;
}

0 comments on commit df32abd

Please sign in to comment.