1
0
Fork 0

🚧 Bumping alpha pre-release

This commit is contained in:
Joost De Cock 2019-05-02 12:40:03 +02:00
parent 6b6f6fd7cd
commit bca5deedb3
62 changed files with 477 additions and 358 deletions

View file

@ -1,32 +1,45 @@
#!/usr/bin/env node
'use strict'
"use strict";
const path = require('path')
const chalk = require('chalk')
const program = require('commander')
const { version } = require('../package')
const path = require("path");
const chalk = require("chalk");
const program = require("commander");
const { version } = require("../package");
const getDefaultLibraryParams = require('./get-default-library-params')
const createLibrary = require('./create-library')
const promptLibraryParams = require('./prompt-library-params')
const getDefaultLibraryParams = require("./get-default-library-params");
const createLibrary = require("./create-library");
const promptLibraryParams = require("./prompt-library-params");
module.exports = async () => {
const defaults = await getDefaultLibraryParams()
const defaults = await getDefaultLibraryParams();
program
.name('create-freesewing-pattern')
.name("create-freesewing-pattern")
.version(version)
.usage('[options] [package-name]')
.option('-d, --desc <string>', 'package description')
.option('-a, --author <string>', 'author\'s github handle', defaults.author)
.option('-l, --license <string>', 'package license', defaults.license)
.option('-r, --repo <string>', 'package repo path')
.option('-g, --no-git', 'generate without git init')
.option('-m, --manager <npm|yarn>', 'package manager to use', /^(npm|yarn)$/, defaults.manager)
.option('-t, --template <default|custom>', 'package template to use', /^(default|custom)$/, defaults.template)
.option('-p, --template-path <string>', 'custom package template path')
.option('-s, --skip-prompts', 'skip all prompts (must provide package-name via cli)')
.parse(process.argv)
.usage("[options] [package-name]")
.option("-d, --desc <string>", "package description")
.option("-a, --author <string>", "author's github handle", defaults.author)
.option("-l, --license <string>", "package license", defaults.license)
.option("-r, --repo <string>", "package repo path")
.option("-g, --no-git", "generate without git init")
.option(
"-m, --manager <npm|yarn>",
"package manager to use",
/^(npm|yarn)$/,
defaults.manager
)
.option(
"-t, --template <default|custom>",
"package template to use",
/^(default|custom)$/,
defaults.template
)
.option("-p, --template-path <string>", "custom package template path")
.option(
"-s, --skip-prompts",
"skip all prompts (must provide package-name via cli)"
)
.parse(process.argv);
const opts = {
description: program.desc,
@ -38,24 +51,24 @@ module.exports = async () => {
templatePath: program.templatePath,
skipPrompts: program.skipPrompts,
git: program.git
}
};
Object.keys(opts).forEach((key) => {
Object.keys(opts).forEach(key => {
if (!opts[key] && defaults[key]) {
opts[key] = defaults[key]
opts[key] = defaults[key];
}
})
});
if (program.args.length === 1) {
opts.name = program.args[0]
opts.name = program.args[0];
} else if (program.args.length > 1) {
console.error('invalid arguments')
program.help()
process.exit(1)
console.error("invalid arguments");
program.help();
process.exit(1);
}
const params = await promptLibraryParams(opts)
const dest = await createLibrary(params)
const params = await promptLibraryParams(opts);
const dest = await createLibrary(params);
console.log(`
@ -67,14 +80,15 @@ In one terminal, start the rollup bundler in watch mode:
$ ${chalk.cyan(`cd ${params.shortName} && ${params.manager} start`)}
And in another terminal, run the dev server:
$ ${chalk.cyan(`cd ${path.join(params.shortName, 'example')} && ${params.manager} start`)}
`)
$ ${chalk.cyan(
`cd ${path.join(params.shortName, "example")} && ${params.manager} start`
)}
`);
return dest
}
return dest;
};
module.exports()
.catch((err) => {
console.error(err)
process.exit(1)
})
module.exports().catch(err => {
console.error(err);
process.exit(1);
});

View file

@ -1,54 +1,54 @@
'use strict'
"use strict";
const getGitConfigPath = require('git-config-path')
const githubUsername = require('github-username')
const parseGitConfig = require('parse-git-config')
const which = require('which')
const getGitConfigPath = require("git-config-path");
const githubUsername = require("github-username");
const parseGitConfig = require("parse-git-config");
const which = require("which");
const config = require('./config')
const config = require("./config");
module.exports = async () => {
const defaults = {
name: '',
description: '',
author: config.get('author'),
repo: (info) => `${info.author}/${info.name}`,
license: config.get('license', 'MIT'),
manager: config.get('manager', 'npm'),
template: config.get('template', 'default')
}
name: "",
description: "",
author: config.get("author"),
repo: info => `${info.author}/${info.name}`,
license: config.get("license", "MIT"),
manager: config.get("manager", "npm"),
template: config.get("template", "default")
};
try {
if (!config.get('author')) {
const gitConfigPath = getGitConfigPath('global')
if (!config.get("author")) {
const gitConfigPath = getGitConfigPath("global");
if (gitConfigPath) {
const gitConfig = parseGitConfig.sync({ path: gitConfigPath })
const gitConfig = parseGitConfig.sync({ path: gitConfigPath });
if (gitConfig.github && gitConfig.github.user) {
defaults.author = gitConfig.github.user
defaults.author = gitConfig.github.user;
} else if (gitConfig.user && gitConfig.user.email) {
defaults.author = await githubUsername(gitConfig.user.email)
defaults.author = await githubUsername(gitConfig.user.email);
}
}
if (defaults.author) {
config.set('author', defaults.author)
config.set("author", defaults.author);
}
}
if (!config.get('manager')) {
if (which.sync('yarn', { nothrow: true })) {
defaults.manager = 'yarn'
if (!config.get("manager")) {
if (which.sync("yarn", { nothrow: true })) {
defaults.manager = "yarn";
}
config.set('manager', defaults.manager)
config.set("manager", defaults.manager);
}
if (!config.get('template')) {
config.set('template', defaults.template)
if (!config.get("template")) {
config.set("template", defaults.template);
}
} catch (err) { }
} catch (err) {}
return defaults
}
return defaults;
};

View file

@ -1,14 +1,14 @@
'use strict'
"use strict";
const path = require('path')
const fs = require('fs')
const inquirer = require('inquirer')
const validateNpmName = require('validate-npm-package-name')
const languages = require('@freesewing/i18n').languages;
const strings = require('@freesewing/i18n').strings;
const config = require('./config')
const path = require("path");
const fs = require("fs");
const inquirer = require("inquirer");
const validateNpmName = require("validate-npm-package-name");
const languages = require("@freesewing/i18n").languages;
const strings = require("@freesewing/i18n").strings;
const config = require("./config");
let languageChoices = []
let languageChoices = [];
for (let l of Object.keys(languages)) {
languageChoices.push({
name: languages[l],
@ -17,99 +17,113 @@ for (let l of Object.keys(languages)) {
});
}
module.exports = async (opts) => {
module.exports = async opts => {
if (opts.name && !validateNpmName(opts.name).validForNewPackages) {
throw new Error(`invalid package name "${opts.name}"`)
throw new Error(`invalid package name "${opts.name}"`);
}
if (opts.skipPrompts) {
if (!opts.name) {
throw new Error('invalid input; you must pass a package name with --skip-prompts')
throw new Error(
"invalid input; you must pass a package name with --skip-prompts"
);
}
Object.keys(opts).forEach((key) => {
const value = opts[key]
if (typeof value === 'function') {
opts[key] = value(opts)
Object.keys(opts).forEach(key => {
const value = opts[key];
if (typeof value === "function") {
opts[key] = value(opts);
}
})
});
return opts
return opts;
} else {
const info = await inquirer.prompt([
{
type: 'list',
name: 'language',
message: 'Language',
type: "list",
name: "language",
message: "Language",
choices: languageChoices,
default: 'en'
default: "en"
},
{
type: 'input',
name: 'name',
message: info => strings[info.language]['cfp.patternName'],
type: "input",
name: "name",
message: info => strings[info.language]["cfp.patternName"],
validate: name => {
return name && validateNpmName(name).validForNewPackages
return name && validateNpmName(name).validForNewPackages;
},
default: opts.name
},
{
type: 'input',
name: 'description',
message: info => strings[info.language]['cfp.patternDescription'],
type: "input",
name: "description",
message: info => strings[info.language]["cfp.patternDescription"],
default: opts.description
},
{
type: 'list',
name: 'type',
message: info => strings[info.language]['cfp.patternType'],
type: "list",
name: "type",
message: info => strings[info.language]["cfp.patternType"],
choices: info => [
{ name: strings[info.language]['filter.type.pattern'], value: 'pattern'},
{ name: strings[info.language]['filter.type.block'], value: 'block'},
{
name: strings[info.language]["filter.type.pattern"],
value: "pattern"
},
{ name: strings[info.language]["filter.type.block"], value: "block" }
],
default: 'pattern',
default: "pattern"
},
{
type: 'list',
name: 'department',
message: info => strings[info.language]['filter.department.title'],
type: "list",
name: "department",
message: info => strings[info.language]["filter.department.title"],
choices: info => [
{ name: strings[info.language]['filter.department.menswear'], value: 'menswear'},
{ name: strings[info.language]['filter.department.womenswear'], value: 'womenswear'},
{ name: strings[info.language]['filter.department.accessories'], value: 'accessories'},
{
name: strings[info.language]["filter.department.menswear"],
value: "menswear"
},
{
name: strings[info.language]["filter.department.womenswear"],
value: "womenswear"
},
{
name: strings[info.language]["filter.department.accessories"],
value: "accessories"
}
],
default: 'womenswear',
default: "womenswear"
},
{
type: 'input',
name: 'author',
message: info => strings[info.language]['cfp.author'],
type: "input",
name: "author",
message: info => strings[info.language]["cfp.author"],
default: opts.author
},
{
type: 'input',
name: 'repo',
message: info => strings[info.language]['cfp.githubRepo'],
type: "input",
name: "repo",
message: info => strings[info.language]["cfp.githubRepo"],
default: opts.repo
},
{
type: 'list',
name: 'manager',
message: info => strings[info.language]['cfp.packageManager'],
choices: [ 'npm', 'yarn' ],
type: "list",
name: "manager",
message: info => strings[info.language]["cfp.packageManager"],
choices: ["npm", "yarn"],
default: opts.manager
},
])
}
]);
config.set('author', info.author)
config.set('manager', info.manager)
config.set('template', 'default')
config.set('license', 'MIT')
info.template = 'default';
config.set("author", info.author);
config.set("manager", info.manager);
config.set("template", "default");
config.set("license", "MIT");
info.template = "default";
return {
...info,
git: opts.git
}
};
}
}
};

View file

@ -1,14 +1,14 @@
import React, { Component } from 'react';
import React, { Component } from "react";
import freesewing from "freesewing";
import './App.css';
import "./App.css";
import ExampleComponent from '{{name}}';
import ExampleComponent from "{{name}}";
class App extends Component {
render() {
console.log(freesewing);
console.log({ExampleComponent});
return (<p>hi there</p>)
console.log({ ExampleComponent });
return <p>hi there</p>;
}
}

View file

@ -1,9 +1,9 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
it('renders without crashing', () => {
const div = document.createElement('div');
it("renders without crashing", () => {
const div = document.createElement("div");
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});

View file

@ -1,10 +1,10 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import * as serviceWorker from "./serviceWorker";
ReactDOM.render(<App />, document.getElementById('root'));
ReactDOM.render(<App />, document.getElementById("root"));
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.

View file

@ -9,9 +9,9 @@
// This link also includes instructions on opting out of this behavior.
const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
window.location.hostname === "localhost" ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
window.location.hostname === "[::1]" ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
@ -19,7 +19,7 @@ const isLocalhost = Boolean(
);
export function register(config) {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
if (process.env.NODE_ENV === "production" && "serviceWorker" in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location);
if (publicUrl.origin !== window.location.origin) {
@ -29,7 +29,7 @@ export function register(config) {
return;
}
window.addEventListener('load', () => {
window.addEventListener("load", () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
if (isLocalhost) {
@ -40,8 +40,8 @@ export function register(config) {
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit https://goo.gl/SC7cgQ'
"This web app is being served cache-first by a service " +
"worker. To learn more, visit https://goo.gl/SC7cgQ"
);
});
} else {
@ -59,13 +59,13 @@ function registerValidSW(swUrl, config) {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (installingWorker.state === "installed") {
if (navigator.serviceWorker.controller) {
// At this point, the old content will have been purged and
// the fresh content will have been added to the cache.
// It's the perfect time to display a "New content is
// available; please refresh." message in your web app.
console.log('New content is available; please refresh.');
console.log("New content is available; please refresh.");
// Execute callback
if (config.onUpdate) {
@ -75,7 +75,7 @@ function registerValidSW(swUrl, config) {
// At this point, everything has been precached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
console.log('Content is cached for offline use.');
console.log("Content is cached for offline use.");
// Execute callback
if (config.onSuccess) {
@ -87,7 +87,7 @@ function registerValidSW(swUrl, config) {
};
})
.catch(error => {
console.error('Error during service worker registration:', error);
console.error("Error during service worker registration:", error);
});
}
@ -98,7 +98,7 @@ function checkValidServiceWorker(swUrl, config) {
// Ensure service worker exists, and that we really are getting a JS file.
if (
response.status === 404 ||
response.headers.get('content-type').indexOf('javascript') === -1
response.headers.get("content-type").indexOf("javascript") === -1
) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => {
@ -113,13 +113,13 @@ function checkValidServiceWorker(swUrl, config) {
})
.catch(() => {
console.log(
'No internet connection found. App is running in offline mode.'
"No internet connection found. App is running in offline mode."
);
});
}
export function unregister() {
if ('serviceWorker' in navigator) {
if ("serviceWorker" in navigator) {
navigator.serviceWorker.ready.then(registration => {
registration.unregister();
});

View file

@ -1,27 +1,27 @@
import babel from 'rollup-plugin-babel'
import commonjs from 'rollup-plugin-commonjs'
import external from 'rollup-plugin-peer-deps-external'
import postcss from 'rollup-plugin-postcss'
import babel from "rollup-plugin-babel";
import commonjs from "rollup-plugin-commonjs";
import external from "rollup-plugin-peer-deps-external";
import postcss from "rollup-plugin-postcss";
import json from "rollup-plugin-json";
import resolve from 'rollup-plugin-node-resolve'
import url from 'rollup-plugin-url'
import svgr from '@svgr/rollup'
import resolve from "rollup-plugin-node-resolve";
import url from "rollup-plugin-url";
import svgr from "@svgr/rollup";
import minify from "rollup-plugin-babel-minify";
import { name, version, description, author, license } from "./package.json";
import pkg from './package.json'
import pkg from "./package.json";
export default {
input: 'src/index.js',
input: "src/index.js",
output: [
{
file: pkg.main,
format: 'cjs',
format: "cjs",
sourcemap: true
},
{
file: pkg.module,
format: 'es',
format: "es",
sourcemap: true
}
],
@ -30,14 +30,14 @@ export default {
postcss({
modules: true
}),
url({ exclude: ['**/*.svg'] }),
url({ exclude: ["**/*.svg"] }),
svgr(),
babel({
exclude: 'node_modules/**',
plugins: [ '@babel/external-helpers' ]
exclude: "node_modules/**",
plugins: ["@babel/external-helpers"]
}),
resolve({ browser: true }),
json(),
commonjs()
]
}
};