create-neon
Advanced tools
Comparing version 0.1.5 to 0.2.0
{ | ||
"neon": "0.9", | ||
"neon": "0.10", | ||
"napi": "6", | ||
"cargo-cp-artifact": "0.1" | ||
} |
@@ -42,6 +42,6 @@ #!/usr/bin/env node | ||
const TEMPLATES = { | ||
'.gitignore.hbs': '.gitignore', | ||
'Cargo.toml.hbs': 'Cargo.toml', | ||
'README.md.hbs': 'README.md', | ||
'lib.rs.hbs': path.join('src', 'lib.rs') | ||
".gitignore.hbs": ".gitignore", | ||
"Cargo.toml.hbs": "Cargo.toml", | ||
"README.md.hbs": "README.md", | ||
"lib.rs.hbs": path.join("src", "lib.rs"), | ||
}; | ||
@@ -57,3 +57,3 @@ function inferVersions() { | ||
neon: versions_json_1.default.neon, | ||
napi: napi | ||
napi: napi, | ||
}; | ||
@@ -63,23 +63,36 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let tmpFolderName = ""; | ||
try { | ||
// pretty lightweight way to check both that folder doesn't exist and | ||
// that the user has write permissions. | ||
yield fs_1.promises.mkdir(name); | ||
yield fs_1.promises.rmdir(name); | ||
tmpFolderName = yield fs_1.promises.mkdtemp(`${name}-`); | ||
} | ||
catch (err) { | ||
die_1.default(`Could not create \`${name}\`: ${err.message}`); | ||
yield (0, die_1.default)(`Could not create \`${name}\`: ${err.message}`, tmpFolderName); | ||
} | ||
let pkg; | ||
try { | ||
pkg = yield package_1.default.create(name); | ||
pkg = yield package_1.default.create(name, tmpFolderName); | ||
yield fs_1.promises.mkdir(path.join(tmpFolderName, "src")); | ||
} | ||
catch (err) { | ||
die_1.default("Could not create `package.json`: " + err.message); | ||
yield (0, die_1.default)("Could not create `package.json`: " + err.message, tmpFolderName); | ||
} | ||
yield fs_1.promises.mkdir(path.join(name, 'src')); | ||
for (let source of Object.keys(TEMPLATES)) { | ||
let target = path.join(name, TEMPLATES[source]); | ||
yield expand_1.default(source, target, { | ||
package: pkg, | ||
versions: inferVersions() | ||
}); | ||
if (pkg) { | ||
for (let source of Object.keys(TEMPLATES)) { | ||
let target = path.join(tmpFolderName, TEMPLATES[source]); | ||
yield (0, expand_1.default)(source, target, { | ||
package: pkg, | ||
versions: inferVersions(), | ||
}); | ||
} | ||
} | ||
try { | ||
yield fs_1.promises.rename(tmpFolderName, name); | ||
} | ||
catch (err) { | ||
yield (0, die_1.default)(`Could not create \`${name}\`: ${err.message}`, tmpFolderName); | ||
} | ||
console.log(`✨ Created Neon project \`${name}\`. Happy 🦀 hacking! ✨`); | ||
@@ -86,0 +99,0 @@ }); |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function die(message) { | ||
console.error(`❌ ${message}`); | ||
process.exit(1); | ||
const fs_1 = require("fs"); | ||
function deleteNeonDir(dir) { | ||
return fs_1.promises.rm(dir, { force: true, recursive: true }); | ||
} | ||
function die(message, tmpFolderName) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
console.error(`❌ ${message}`); | ||
if (tmpFolderName) { | ||
yield deleteNeonDir(tmpFolderName); | ||
} | ||
process.exit(1); | ||
}); | ||
} | ||
exports.default = die; |
@@ -37,14 +37,12 @@ "use strict"; | ||
const path = __importStar(require("path")); | ||
const TEMPLATES_DIR = path.join(__dirname, '..', 'data', 'templates'); | ||
; | ||
; | ||
const TEMPLATES_DIR = path.join(__dirname, "..", "data", "templates"); | ||
function expand(source, target, metadata) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let template = yield fs_1.promises.readFile(path.join(TEMPLATES_DIR, source), 'utf8'); | ||
let template = yield fs_1.promises.readFile(path.join(TEMPLATES_DIR, source), "utf8"); | ||
let compiled = handlebars_1.default.compile(template, { noEscape: true }); | ||
let expanded = compiled(metadata); | ||
// The 'wx' flag creates the file but fails if it already exists. | ||
yield fs_1.promises.writeFile(target, expanded, { flag: 'wx' }); | ||
yield fs_1.promises.writeFile(target, expanded, { flag: "wx" }); | ||
}); | ||
} | ||
exports.default = expand; |
@@ -45,8 +45,8 @@ "use strict"; | ||
"author", | ||
"license" | ||
"license", | ||
]; | ||
function sort(json) { | ||
// First copy the keys in the order specified in KEYS. | ||
let next = KEYS.filter(key => json.hasOwnProperty(key)) | ||
.map(key => [key, json[key]]) | ||
let next = KEYS.filter((key) => json.hasOwnProperty(key)) | ||
.map((key) => [key, json[key]]) | ||
.reduce((acc, [key, val]) => Object.assign(acc, { [key]: val }), {}); | ||
@@ -66,3 +66,3 @@ // Then copy any remaining keys in the original order. | ||
} | ||
static create(name) { | ||
static create(name, dir) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
@@ -74,19 +74,19 @@ let seed = { | ||
scripts: { | ||
"build": "cargo-cp-artifact -nc index.node -- cargo build --message-format=json-render-diagnostics", | ||
build: "cargo-cp-artifact -nc index.node -- cargo build --message-format=json-render-diagnostics", | ||
"build-debug": "npm run build --", | ||
"build-release": "npm run build -- --release", | ||
"install": "npm run build-release", | ||
"test": "cargo test" | ||
install: "npm run build-release", | ||
test: "cargo test", | ||
}, | ||
devDependencies: { | ||
"cargo-cp-artifact": `^${versions_json_1.default['cargo-cp-artifact']}` | ||
} | ||
"cargo-cp-artifact": `^${versions_json_1.default["cargo-cp-artifact"]}`, | ||
}, | ||
}; | ||
let filename = path.join(name, 'package.json'); | ||
let filename = path.join(dir, "package.json"); | ||
// 1. Write initial values to prevent `npm init` from asking unnecessary questions. | ||
yield fs_1.promises.writeFile(filename, JSON.stringify(seed)); | ||
// 2. Call `npm init` to ask the user remaining questions. | ||
yield shell_1.default('npm', ['init'], name); | ||
yield (0, shell_1.default)("npm", ["init"], dir); | ||
// 3. Sort the values in idiomatic `npm init` order. | ||
let sorted = sort(JSON.parse(yield fs_1.promises.readFile(filename, 'utf8'))); | ||
let sorted = sort(JSON.parse(yield fs_1.promises.readFile(filename, "utf8"))); | ||
// 4. Save the result to package.json. | ||
@@ -93,0 +93,0 @@ yield fs_1.promises.writeFile(filename, JSON.stringify(sorted, undefined, 2)); |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const child_process_1 = require("child_process"); | ||
const fs_1 = require("fs"); | ||
const path_1 = __importDefault(require("path")); | ||
/** | ||
@@ -9,3 +23,3 @@ * Transparently shell out to an executable with a list of arguments. | ||
function shell(cmd, args, cwd) { | ||
let child = child_process_1.spawn(cmd, args, { stdio: 'inherit', shell: true, cwd }); | ||
let child = (0, child_process_1.spawn)(cmd, args, { stdio: "inherit", shell: true, cwd }); | ||
let resolve; | ||
@@ -17,16 +31,31 @@ let reject; | ||
}); | ||
child.on('exit', (code) => { | ||
child.on("exit", (code) => __awaiter(this, void 0, void 0, function* () { | ||
if (code == null) { | ||
process.exit(1); | ||
reject(Error(`error code: ${code}`)); | ||
} | ||
if (code !== 0) { | ||
process.exit(code); | ||
//This will catch answering no and many other failures | ||
reject(Error(`error code: ${code}`)); | ||
} | ||
if (code === 0) { | ||
try { | ||
let data = yield fs_1.promises.readFile(path_1.default.join(cwd, "package.json"), "utf8"); | ||
//Testing whether npm init was successful. | ||
//It will catch Ctrl+C and many other failures | ||
let { description, author, license } = JSON.parse(data); | ||
if ([description, author, license].includes(undefined)) { | ||
reject(Error(`error code: ${code}`)); | ||
} | ||
} | ||
catch (e) { | ||
reject(e); | ||
} | ||
} | ||
resolve(undefined); | ||
}); | ||
child.on('error', (error) => { | ||
})); | ||
child.on("error", (error) => __awaiter(this, void 0, void 0, function* () { | ||
reject(error); | ||
}); | ||
})); | ||
return result; | ||
} | ||
exports.default = shell; |
{ | ||
"name": "create-neon", | ||
"version": "0.1.5", | ||
"version": "0.2.0", | ||
"description": "Create Neon projects with no build configuration.", | ||
@@ -21,3 +21,3 @@ "author": "Dave Herman <david.herman@gmail.com>", | ||
"prepublishOnly": "npm run build", | ||
"pretest": "npm install && npm run build", | ||
"pretest": "npm run build", | ||
"test": "mocha", | ||
@@ -35,3 +35,3 @@ "manual-test": "npm run build && rm -rf create-neon-manual-test-project && node ./dist/src/bin/create-neon.js create-neon-manual-test-project" | ||
"@types/chai": "^4.2.15", | ||
"@types/mocha": "^8.2.1", | ||
"@types/mocha": "^9.1.0", | ||
"@types/node": "^14.14.31", | ||
@@ -41,3 +41,3 @@ "@types/rimraf": "^3.0.0", | ||
"execa": "^5.0.0", | ||
"mocha": "^8.3.1", | ||
"mocha": "^9.1.0", | ||
"rimraf": "^3.0.2", | ||
@@ -44,0 +44,0 @@ "stream-to-string": "^1.2.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21189
338
5