i18n-patch
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -5,6 +5,2 @@ #!/usr/bin/env node | ||
// Note for development: | ||
// $ npm run watch | ||
// $ node lib/cli.js --config example --src example/src --out example/out ja | ||
var _meow = require('meow'); | ||
@@ -20,8 +16,10 @@ | ||
var cli = (0, _meow2.default)('\n Usage\n $ i18n-patch <locale>\n\n Options\n --config Base path for config files.\n i18n.json and <locale>.json is required.\n --src Base path for source files.\n Current directory by default.\n --out Base path for output files. \'out\' by default.\n This directory should be clean,\n but this tool does not clean it.\n You must remove the directory by yourself.\n\n Examples\n $ i18n-patch --config example --src example/src --out example/out ja\n'); | ||
var cli = (0, _meow2.default)('\n Usage\n $ i18n-patch <locale> <src> [<dest>]\n\n Options\n --config Base path for config files.\n i18n.json and <locale>.json is required.\n \'config\' by default.\n\n Examples\n $ i18n-patch --config example/config ja example/src example/out\n'); | ||
var locale = cli.input[0]; | ||
var opts = cli.flags; | ||
opts.locale = cli.input[0]; | ||
opts.dest = cli.input[2]; | ||
var src = cli.input[1]; | ||
if (!locale) { | ||
if (!opts.locale || !src) { | ||
cli.showHelp(); | ||
@@ -31,5 +29,5 @@ process.exit(0); | ||
new _2.default(locale, opts).generate().catch(function (err) { | ||
new _2.default(src, opts).generate().catch(function (err) { | ||
console.log(err); | ||
}); | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9jbGkuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUNBOzs7Ozs7QUFNQTs7OztBQUNBOzs7Ozs7QUFFQSxJQUFNLE1BQU0sK2tCQUFOOztBQWtCTixJQUFNLFNBQVMsSUFBSSxLQUFKLENBQVUsQ0FBVixDQUFUO0FBQ04sSUFBTSxPQUFPLElBQUksS0FBSjs7QUFFYixJQUFJLENBQUMsTUFBRCxFQUFTO0FBQ1gsTUFBSSxRQUFKLEdBRFc7QUFFWCxVQUFRLElBQVIsQ0FBYSxDQ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RUFBUztBQUNkLFVBQVEsR0FBUixDQUFZLEdBQVosRUFEYztDQUFULENBRlAiLCJmaWxlIjoiY2xpLmpzIiwic291cmNlc0NvbnRlbnQiOlsiXG4ndXNlIHN0cmljdCc7XG5cbmltcG9ydCBtZW93IGZyb20gJ21lb3cnO1xuaW1wb3J0IEkxOG5QYXRjaCBmcm9tICcuLyc7XG5cbmNvbnN0IGNsaSA9IG1lb3coYFxuICAgIFVzYWdlXG4gICAgICAkIGkxOG4tcGF0Y2ggPGxvY2FsZT4gPHNyYz4gWzxkZXN0Pl1cblxuICAgIE9wdGlvbnNcbiAgICAgIC0tY29uZmlnICBCYXNlIHBhdGggZm9yIGNvbmZpZyBmaWxlcy5cbiAgICAgICAgICAgICAgICBpMThuLmpzb24gYW5kIDxsb2NhbGU+Lmpzb24gaXMgcmVxdWlyZWQuXG4gICAgICAgICAgICAgICAgJ2NvbmZpZycgYnkgZGVmYXVsdC5cblxuICAgIEV4YW1wbGVzXG4gICAgICAkIGkxOG4tcGF0Y2ggLS1jb25maWcgZXhhbXBsZS9jb25maWcgamEgZXhhbXBsZS9zcmMgZXhhbXBsZS9vdXRcbmApO1xuXG5jb25zdCBvcHRzID0gY2xpLmZsYWdzO1xub3B0cy5sb2NhbGUgPSBjbGkuaW5wdXRbMF07XG5vcHRzLmRlc3QgPSBjbGkuaW5wdXRbMl07XG5jb25zdCBzcmMgPSBjbGkuaW5wdXRbMV07XG5cbmlmICghb3B0cy5sb2NhbGUgfHwgIXNyYykge1xuICBjbGkuc2hvd0hlbHAoKTtcbiAgcHJvY2Vzcy5leGl0KDApO1xufVxuXG5uZXcgSTE4blBhdGNoKHNyYywgb3B0cylcbi5nZW5lcmF0ZSgpXG4uY2F0Y2goKGVycikgPT4ge1xuICBjb25zb2xlLmxvZyhlcnIpO1xufSk7XG4iXX0= |
@@ -32,7 +32,12 @@ 'use strict'; | ||
var I18nPatch = function () { | ||
function I18nPatch(locale, options) { | ||
function I18nPatch(src, options) { | ||
_classCallCheck(this, I18nPatch); | ||
this.locale = locale; | ||
if (!src) { | ||
throw new Error('src is required'); | ||
} | ||
this.src = src; | ||
this.options = options || {}; | ||
this.options.dest = this.options.dest || this.src; | ||
this.options.config = this.options.config || 'config'; | ||
} | ||
@@ -42,9 +47,12 @@ | ||
key: 'generate', | ||
value: function generate() { | ||
value: function generate(config, localeConfig) { | ||
var _this = this; | ||
this.config = this.readConfigFile('i18n.json'); | ||
this.localeConfig = this.readConfigFile(this.locale + '.json'); | ||
this.buildPatterns(); | ||
return new Promise(function (resolve, reject) { | ||
_this.setConfigs(config, localeConfig); | ||
_this.buildPatterns(); | ||
if (_this.hasDest()) { | ||
_fsExtra2.default.copySync(_this.src, _this.options.dest); | ||
} | ||
Promise.all(_this.config.translations.map(function (t) { | ||
@@ -60,6 +68,23 @@ return _this.processTranslation(t); | ||
}, { | ||
key: 'hasDest', | ||
value: function hasDest() { | ||
return this.src !== this.options.dest; | ||
} | ||
}, { | ||
key: 'setConfigs', | ||
value: function setConfigs(config, localeConfig) { | ||
this.config = config || this.readConfigFile('i18n.json'); | ||
if (localeConfig) { | ||
this.localeConfig = localeConfig; | ||
} else { | ||
if (!this.options.locale) { | ||
throw new Error('Could not determine locale'); | ||
} | ||
this.localeConfig = this.readConfigFile(this.options.locale + '.json'); | ||
} | ||
} | ||
}, { | ||
key: 'readConfigFile', | ||
value: function readConfigFile(name) { | ||
var basePath = this.options.config || '.'; | ||
var configPath = _path2.default.join(basePath, name); | ||
var configPath = _path2.default.join(this.options.config, name); | ||
var configFile = void 0; | ||
@@ -81,5 +106,12 @@ try { | ||
t.patterns.forEach(function (p) { | ||
var resolved = false; | ||
p.resolved = p.replace.replace(/\${([^}]*)}/g, function (all, matched) { | ||
if (_this2.localeConfig.hasOwnProperty(matched)) { | ||
resolved = true; | ||
} | ||
return _this2.localeConfig[matched]; | ||
}); | ||
if (!resolved) { | ||
p.resolved = undefined; | ||
} | ||
}); | ||
@@ -94,4 +126,4 @@ }); | ||
return new Promise(function (resolve, reject) { | ||
var basePath = _this3.options.src || '.'; | ||
var srcPaths = t.src ? _path2.default.join(basePath, t.src) : basePath; | ||
var srcGlob = t.src || '**/*'; | ||
var srcPaths = _path2.default.join(_this3.options.dest, srcGlob); | ||
(0, _glob2.default)(srcPaths, null, function (err, files) { | ||
@@ -115,9 +147,5 @@ if (err) { | ||
value: function processFile(t, file) { | ||
var _this4 = this; | ||
return new Promise(function (resolve, reject) { | ||
var matched = false; | ||
var error = void 0; | ||
var dest = _path2.default.join(_this4.options.out || 'out', _path2.default.relative(_this4.options.src, file)); | ||
_fsExtra2.default.mkdirsSync(_path2.default.dirname(dest)); | ||
var lr = _readline2.default.createInterface({ | ||
@@ -135,6 +163,3 @@ input: _fsExtra2.default.createReadStream(file) | ||
// TODO Preserve original file stats | ||
_fsExtra2.default.copySync(out.path, dest); | ||
} else { | ||
// Just copy original file | ||
_fsExtra2.default.copySync(file, dest); | ||
_fsExtra2.default.copySync(out.path, file); | ||
} | ||
@@ -147,3 +172,5 @@ resolve(file); | ||
var before = result; | ||
result = result.replace(p.pattern, p.resolved); | ||
if (p.resolved) { | ||
result = result.replace(p.pattern, p.resolved); | ||
} | ||
if (before !== result) { | ||
@@ -170,2 +197,2 @@ matched = true; | ||
exports.default = I18nPatch; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9pbmRleC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7Ozs7QUFFQTs7OztBQUNBOzs7O0FBQ0E7Ozs7QUFDQTs7Ozs7Ozs7QUFDQSxJQUFNLE9BQU8sUUFBUSxNQUFSLEVBQWdCLEtBQWhCLEVBQVA7O0lBRWU7QUFDbkIsV0FEbUIsU0FDbkIsQ0FBWSxNQUFaLEVBQW9CLE9BQXBCLEVBQTZCOzBCQURWLFdBQ1U7O0FBQzNCLFNBQUssTUFBTCxHQUFjLE1BQWQsQ0FEMkI7QUFFM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lIHN0YXRzXG4gICAgICAgICAgZnMuY29weVN5bmMob3V0LnBhdGgsIGRlc3QpO1xuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgIC8vIEp1c3QgY29weSBvcmlnaW5hbCBmaWxlXG4gICAgICAgICAgZnMuY29weVN5bmMoZmlsZSwgZGVzdCk7XG4gICAgICAgIH1cbiAgICAgICAgcmVzb2x2ZShmaWxlKTtcbiAgICAgIH0pO1xuICAgICAgbHIub24oJ2xpbmUnLCAobGluZSkgPT4ge1xuICAgICAgICBsZXQgcmVzdWx0ID0gbGluZTtcbiAgICAgICAgdC5wYXR0ZXJucy5mb3JFYWNoKChwKSA9PiB7XG4gICAgICAgICAgbGV0IGJlZm9yZSA9IHJlc3VsdDtcbiAgICAgICAgICByZXN1bHQgPSByZXN1bHQucmVwbGFjZShwLnBhdHRlcm4sIHAucmVzb2x2ZWQpO1xuICAgICAgICAgIGlmIChiZWZvcmUgIT09IHJlc3VsdCkge1xuICAgICAgICAgICAgbWF0Y2hlZCA9IHRydWU7XG4gICAgICAgICAgfVxuICAgICAgICB9KTtcbiAgICAgICAgLy8gVE9ETyBQcmVzZXJ2ZSBvcmlnaW5hbCBuZXdsaW5lIGlmIHBvc3NpYmxlXG4gICAgICAgIG91dC53cml0ZShgJHtyZXN1bHR9XFxuYCk7XG4gICAgICB9KVxuICAgICAgLm9uKCdlcnJvcicsIChlcnIpID0+IHtcbiAgICAgICAgZXJyb3IgPSBlcnI7XG4gICAgICAgIG91dC5lbmQoKTtcbiAgICAgICAgcmVqZWN0KGVycik7XG4gICAgICB9KVxuICAgICAgLm9uKCdjbG9zZScsICgpID0+IHtcbiAgICAgICAgb3V0LmVuZCgpO1xuICAgICAgfSk7XG4gICAgfSk7XG4gIH1cbn1cbiJdfQ== | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9pbmRleC5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUF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A9IGZhbHNlO1xuICAgICAgICBwLnJlc29sdmVkID0gcC5yZXBsYWNlLnJlcGxhY2UoL1xcJHsoW159XSopfS9nLCAoYWxsLCBtYXRjaGVkKSA9PiB7XG4gICAgICAgICAgaWYgKHRoaXMubG9jYWxlQ29uZmlnLmhhc093blByb3BlcnR5KG1hdGNoZWQpKSB7XG4gICAgICAgICAgICByZXNvbHZlZCA9IHRydWU7XG4gICAgICAgICAgfVxuICAgICAgICAgIHJldHVybiB0aGlzLmxvY2FsZUNvbmZpZ1ttYXRjaGVkXTtcbiAgICAgICAgfSk7XG4gICAgICAgIGlmICghcmVzb2x2ZWQpIHtcbiAgICAgICAgICBwLnJlc29sdmVkID0gdW5kZWZpbmVkO1xuICAgICAgICB9XG4gICAgICB9KTtcbiAgICB9KTtcbiAgfVxuXG4gIHByb2Nlc3NUcmFuc2xhdGlvbih0KSB7XG4gICAgcmV0dXJuIG5ldyBQcm9taXNlKChyZXNvbHZlLCByZWplY3QpID0+IHtcbiAgICAgIGxldCBzcmNHbG9iID0gdC5zcmMgfHwgJyoqLyonO1xuICAgICAgbGV0IHNyY1BhdGhzID0gcGF0aC5qb2luKHRoaXMub3B0aW9ucy5kZXN0LCBzcmNHbG9iKTtcbiAgICAgIGdsb2Ioc3JjUGF0aHMsIG51bGwsIChlcnIsIGZpbGVzKSA9PiB7XG4gICAgICAgIGlmIChlcnIpIHtcbiAgICAgICAgICByZWplY3QoZXJyKTtcbiAgICAgICAgICByZXR1cm47XG4gICAgICAgIH1cbiAgICAgICAgUHJvbWlzZS5hbGwoZmlsZXMubWFwKChmaWxlKSA9PiB7XG4gICAgICAgICAgcmV0dXJuIHRoaXMucHJvY2Vzc0ZpbGUodCwgZmlsZSk7XG4gICAgICAgIH0pKVxuICAgICAgICAuY2F0Y2goKGVycikgPT4ge1xuICAgICAgICAgIHJlamVjdChlcnIpO1xuICAgICAgICB9KVxuICAgICAgICAudGhlbigoZmlsZSkgPT4ge1xuICAgICAgICAgIHJlc29sdmUoZmlsZSk7XG4gICAgICAgIH0pO1xuICAgICAgfSk7XG4gICAgfSk7XG4gIH1cblxuICBwcm9jZXNzRmlsZSh0LCBmaWxlKSB7XG4gICAgcmV0dXJuIG5ldyBQcm9taXNlKChyZXNvbHZlLCByZWplY3QpID0+IHtcbiAgICAgIGxldCBtYXRjaGVkID0gZmFsc2U7XG4gICAgICBsZXQgZXJyb3I7XG4gICAgICBsZXQgbHIgPSBybC5jcmVhdGVJbnRlcmZhY2Uoe1xuICAgICAgICBpbnB1dDogZnMuY3JlYXRlUmVhZFN0cmVhbShmaWxlKVxuICAgICAgfSk7XG4gICAgICBsZXQgb3V0ID0gdGVtcC5jcmVhdGVXcml0ZVN0cmVhbSgpXG4gICAgICAub24oJ2Vycm9yJywgKGVycikgPT4ge1xuICAgICAgICByZWplY3QoZXJyKTtcbiAgICAgIH0pXG4gICAgICAub24oJ2Nsb3NlJywgKCkgPT4ge1xuICAgICAgICBpZiAoZXJyb3IpIHtcbiAgICAgICAgICAvLyBUaGlzIGNhbiBiZSBzZXQgaW4gJ2Vycm9yJyBjYWxsYmFjayBvZiBsclxuICAgICAgICAgIHJldHVybjtcbiAgICAgICAgfVxuICAgICAgICBpZiAobWF0Y2hlZCkge1xuICAgICAgICAgIC8vIFRPRE8gUHJlc2VydmUgb3JpZ2luYWwgZmlsZSBzdGF0c1xuICAgICAgICAgIGZzLmNvcHlTeW5jKG91dC5wYXRoLCBmaWxlKTtcbiAgICAgICAgfVxuICAgICAgICByZXNvbHZlKGZpbGUpO1xuICAgICAgfSk7XG4gICAgICBsci5vbignbGluZScsIChsaW5lKSA9PiB7XG4gICAgICAgIGxldCByZXN1bHQgPSBsaW5lO1xuICAgICAgICB0LnBhdHRlcm5zLmZvckVhY2goKHApID0+IHtcbiAgICAgICAgICBsZXQgYmVmb3JlID0gcmVzdWx0O1xuICAgICAgICAgIGlmIChwLnJlc29sdmVkKSB7XG4gICAgICAgICAgICByZXN1bHQgPSByZXN1bHQucmVwbGFjZShwLnBhdHRlcm4sIHAucmVzb2x2ZWQpO1xuICAgICAgICAgIH1cbiAgICAgICAgICBpZiAoYmVmb3JlICE9PSByZXN1bHQpIHtcbiAgICAgICAgICAgIG1hdGNoZWQgPSB0cnVlO1xuICAgICAgICAgIH1cbiAgICAgICAgfSk7XG4gICAgICAgIC8vIFRPRE8gUHJlc2VydmUgb3JpZ2luYWwgbmV3bGluZSBpZiBwb3NzaWJsZVxuICAgICAgICBvdXQud3JpdGUoYCR7cmVzdWx0fVxcbmApO1xuICAgICAgfSlcbiAgICAgIC5vbignZXJyb3InLCAoZXJyKSA9PiB7XG4gICAgICAgIGVycm9yID0gZXJyO1xuICAgICAgICBvdXQuZW5kKCk7XG4gICAgICAgIHJlamVjdChlcnIpO1xuICAgICAgfSlcbiAgICAgIC5vbignY2xvc2UnLCAoKSA9PiB7XG4gICAgICAgIG91dC5lbmQoKTtcbiAgICAgIH0pO1xuICAgIH0pO1xuICB9XG59XG4iXX0= |
{ | ||
"name": "i18n-patch", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Replacing codes for i18n with patterns.", | ||
@@ -43,3 +43,4 @@ "license": "MIT", | ||
"babel-preset-es2015": "^6.6.0", | ||
"eslint": "^2.5.3" | ||
"eslint": "^2.5.3", | ||
"rimraf": "^2.5.2" | ||
}, | ||
@@ -57,3 +58,3 @@ "babel": { | ||
"prepublish": "npm run build", | ||
"start": "node ./lib/cli", | ||
"start": "rimraf example/out && node ./lib/cli --config example ja example/src example/out", | ||
"build": "babel src -d lib -s inline", | ||
@@ -60,0 +61,0 @@ "watch": "babel src -d lib -s inline -w", |
#!/usr/bin/env node | ||
'use strict'; | ||
// Note for development: | ||
// $ npm run watch | ||
// $ node lib/cli.js --config example --src example/src --out example/out ja | ||
import meow from 'meow'; | ||
@@ -13,3 +9,3 @@ import I18nPatch from './'; | ||
Usage | ||
$ i18n-patch <locale> | ||
$ i18n-patch <locale> <src> [<dest>] | ||
@@ -19,17 +15,14 @@ Options | ||
i18n.json and <locale>.json is required. | ||
--src Base path for source files. | ||
Current directory by default. | ||
--out Base path for output files. 'out' by default. | ||
This directory should be clean, | ||
but this tool does not clean it. | ||
You must remove the directory by yourself. | ||
'config' by default. | ||
Examples | ||
$ i18n-patch --config example --src example/src --out example/out ja | ||
$ i18n-patch --config example/config ja example/src example/out | ||
`); | ||
const locale = cli.input[0]; | ||
const opts = cli.flags; | ||
opts.locale = cli.input[0]; | ||
opts.dest = cli.input[2]; | ||
const src = cli.input[1]; | ||
if (!locale) { | ||
if (!opts.locale || !src) { | ||
cli.showHelp(); | ||
@@ -39,3 +32,3 @@ process.exit(0); | ||
new I18nPatch(locale, opts) | ||
new I18nPatch(src, opts) | ||
.generate() | ||
@@ -42,0 +35,0 @@ .catch((err) => { |
@@ -10,12 +10,20 @@ 'use strict'; | ||
export default class I18nPatch { | ||
constructor(locale, options) { | ||
this.locale = locale; | ||
constructor(src, options) { | ||
if (!src) { | ||
throw new Error('src is required'); | ||
} | ||
this.src = src; | ||
this.options = options || {}; | ||
this.options.dest = this.options.dest || this.src; | ||
this.options.config = this.options.config || 'config'; | ||
} | ||
generate() { | ||
this.config = this.readConfigFile('i18n.json'); | ||
this.localeConfig = this.readConfigFile(`${this.locale}.json`); | ||
this.buildPatterns(); | ||
generate(config, localeConfig) { | ||
return new Promise((resolve, reject) => { | ||
this.setConfigs(config, localeConfig); | ||
this.buildPatterns(); | ||
if (this.hasDest()) { | ||
fs.copySync(this.src, this.options.dest); | ||
} | ||
Promise.all(this.config.translations.map((t) => { | ||
@@ -33,5 +41,20 @@ return this.processTranslation(t); | ||
hasDest() { | ||
return this.src !== this.options.dest; | ||
} | ||
setConfigs(config, localeConfig) { | ||
this.config = config || this.readConfigFile('i18n.json'); | ||
if (localeConfig) { | ||
this.localeConfig = localeConfig; | ||
} else { | ||
if (!this.options.locale) { | ||
throw new Error('Could not determine locale'); | ||
} | ||
this.localeConfig = this.readConfigFile(`${this.options.locale}.json`); | ||
} | ||
} | ||
readConfigFile(name) { | ||
const basePath = this.options.config || '.'; | ||
let configPath = path.join(basePath, name); | ||
let configPath = path.join(this.options.config, name); | ||
let configFile; | ||
@@ -50,5 +73,12 @@ try { | ||
t.patterns.forEach((p) => { | ||
let resolved = false; | ||
p.resolved = p.replace.replace(/\${([^}]*)}/g, (all, matched) => { | ||
if (this.localeConfig.hasOwnProperty(matched)) { | ||
resolved = true; | ||
} | ||
return this.localeConfig[matched]; | ||
}); | ||
if (!resolved) { | ||
p.resolved = undefined; | ||
} | ||
}); | ||
@@ -60,4 +90,4 @@ }); | ||
return new Promise((resolve, reject) => { | ||
const basePath = this.options.src || '.'; | ||
let srcPaths = t.src ? path.join(basePath, t.src) : basePath; | ||
let srcGlob = t.src || '**/*'; | ||
let srcPaths = path.join(this.options.dest, srcGlob); | ||
glob(srcPaths, null, (err, files) => { | ||
@@ -85,5 +115,2 @@ if (err) { | ||
let error; | ||
let dest = path.join(this.options.out || 'out', | ||
path.relative(this.options.src, file)); | ||
fs.mkdirsSync(path.dirname(dest)); | ||
let lr = rl.createInterface({ | ||
@@ -103,6 +130,3 @@ input: fs.createReadStream(file) | ||
// TODO Preserve original file stats | ||
fs.copySync(out.path, dest); | ||
} else { | ||
// Just copy original file | ||
fs.copySync(file, dest); | ||
fs.copySync(out.path, file); | ||
} | ||
@@ -115,3 +139,5 @@ resolve(file); | ||
let before = result; | ||
result = result.replace(p.pattern, p.resolved); | ||
if (p.resolved) { | ||
result = result.replace(p.pattern, p.resolved); | ||
} | ||
if (before !== result) { | ||
@@ -118,0 +144,0 @@ matched = true; |
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
28834
356
5