Skip to content

Commit

Permalink
feat: add import subcommand to import a customize setting from an exi…
Browse files Browse the repository at this point in the history
…sting app (#56)

fix #24

* Generate customize-manifest.json from the app setting #Issue-24

Introduce --import-customize-setting option.
With this option (and --dest option),
this tool fetch customize settings, And then generate customize-manifest.json.
customize-manifest.json has a format of this tool.

finally, download uploaded files and put it in dest directroy.

At kintone customize partner, there are kintone application which already has been customized.
kintone-customize-uploader is very good tool, but It is not usefull in contining development situation.

If I tried this tool at contining developmenet situation,
I must create customize-manifest.json using various APIs Or copy from browser by hand.

By this option, I can introduce this tool more easily :)

* Use mkdirp library (v6/v8 hasn't api for make directory recursively)

* Add Test Code and fix Promise warning

- Add test code about api request history
- Improve promise warning

* Fix for test at windows os. use rimraf

* Introduce import subcommand alternative of --import-customize-settings

* Use sync method on writing file or creating directory

* Add TypeAnnotation for GetAppCustomizeResp

* Fix async/wait problem

* Add log message

* Fix for windows platform test

* fix wait test

* Add SubCommands help

* Replace ${sep} to "/"

* Fix test for multiplat form path

* Remove unused option

* simplify array#concat

* return Promise
  • Loading branch information
yokotaso authored and koba04 committed Mar 27, 2020
1 parent caa8558 commit 4a89a67
Show file tree
Hide file tree
Showing 12 changed files with 682 additions and 68 deletions.
43 changes: 36 additions & 7 deletions packages/customize-uploader/bin/cli.js
Expand Up @@ -3,6 +3,7 @@
const osLocale = require('os-locale');
const meow = require('meow');
const { run } = require('../dist/src/index');
const { runImport } = require('../dist/src/import');
const { inquireParams } = require('../dist/src/params');
const { getDefaultLang } = require('../dist/src/lang');
const { getMessage } = require('../dist/src/messages');
Expand All @@ -16,7 +17,6 @@ const {
KINTONE_BASIC_AUTH_USERNAME,
KINTONE_BASIC_AUTH_PASSWORD
} = process.env;

const cli = meow(
`
Usage
Expand All @@ -29,8 +29,16 @@ const cli = meow(
--basic-auth-password Basic Authentication password
--proxy Proxy server
--watch Watch the changes of customize files and re-run
--dest-dir -d option for subcommand import.
this option stands for output directory
default value is dest/
--lang Using language (en or ja)
--guest-space-id Guest space ID for uploading files
SubCommands
import generate customize-manifest.json and
download js/css files from existing app customization
You can set the values through environment variables
domain: KINTONE_DOMAIN
username: KINTONE_USERNAME
Expand Down Expand Up @@ -77,11 +85,23 @@ const cli = meow(
type: 'number',
default: 0
},
// Optional option for import subcommand
destDir: {
type: 'string',
default: 'dest',
alias: 'd'
}
}
}
);

const manifestFile = cli.input[0];
const subCommands = ["import"];
const hasSubCommand = subCommands.indexOf(cli.input[0]) >= 0;
const subCommand = hasSubCommand ? cli.input[0] : null;
const isImportCommand = subCommand === "import";

const manifestFile = hasSubCommand ? cli.input[1] : cli.input[0];

const {
username,
password,
Expand All @@ -91,23 +111,32 @@ const {
proxy,
watch,
lang,
guestSpaceId
guestSpaceId,
destDir,
} = cli.flags;

const options = proxy ? { watch, lang, proxy } : { watch, lang };
if (guestSpaceId) {
options.guestSpaceId = guestSpaceId;
}

if(isImportCommand) {
options.destDir = destDir;
}

if (!manifestFile) {
console.error(getMessage(lang, 'E_requiredManifestFile'));
cli.showHelp();
process.exit(1);
}

inquireParams({ username, password, domain, lang })
.then(({ username, password, domain }) => (
run(domain, username, password, basicAuthUsername, basicAuthPassword, manifestFile, options)
))
.then(({ username, password, domain }) => {
if(isImportCommand) {
runImport(domain, username, password, basicAuthUsername, basicAuthPassword, manifestFile, options)
} else {
run(domain, username, password, basicAuthUsername, basicAuthPassword, manifestFile, options)
}
})
.catch(error => console.log(error.message));
;

0 comments on commit 4a89a67

Please sign in to comment.