Skip to content

Commit

Permalink
switch to esm
Browse files Browse the repository at this point in the history
  • Loading branch information
smhg committed Feb 9, 2024
1 parent ce11793 commit ff57136
Show file tree
Hide file tree
Showing 12 changed files with 592 additions and 423 deletions.
16 changes: 0 additions & 16 deletions .eslintrc.js

This file was deleted.

14 changes: 14 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"env": {
"es2021": true,
"node": true
},
"extends": "standard",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
"semi": ["error", "always"]
}
}
26 changes: 18 additions & 8 deletions bin/xgettext-template
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
#!/usr/bin/env node
'use strict';

const xgettext = require('..');
const pkg = require('../package.json');
import xgettext from '../index.js';
import yargs from 'yargs';
import { readFile } from 'fs/promises';

const pkg = JSON.parse(
await readFile(
new URL('../package.json', import.meta.url)
)
);

const name = Object.keys(pkg.bin)[0];

const languages = xgettext.languages;
const encodings = ['utf8', 'ascii', 'base64'];

const argv = require('yargs')
.usage([
'Usage: ' + name + ' [OPTION] [INPUTFILE]...',
'',
pkg.description
].join('\n'))
const argv = yargs(process.argv.slice(2))
.usage(
[
'Usage: ' + name + ' [OPTION] [INPUTFILE]...',
'',
pkg.description
].join('\n')
)
.alias({
f: 'files-from',
D: 'directory',
Expand Down
28 changes: 20 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
'use strict';

const fs = require('fs');
const path = require('path');
const gt = require('gettext-parser');
const async = require('async');
const createKeywordSpec = require('./src/keyword-spec');
const objectAssign = require('object-assign');
import fs from 'fs';
import path from 'path';
import gt from 'gettext-parser';
import async from 'async';
import createKeywordSpec from './src/keyword-spec.js';
import objectAssign from 'object-assign';

import ejs from 'gettext-ejs';
import handlebars from 'gettext-handlebars';
import swig from 'gettext-swig';
import volt from 'gettext-volt';

const PARSERS = {
ejs,
handlebars,
swig,
volt
};

/**
* Simple is object check.
Expand Down Expand Up @@ -89,7 +101,7 @@ function xgettext (input, options, cb) {
name = name.trim().toLowerCase();

if (!parsers[name]) {
const Parser = require(`gettext-${name}`);
const Parser = PARSERS[name];

if (Object.keys(keywordSpec).length > 0) {
parsers[name] = new Parser(keywordSpec);
Expand Down Expand Up @@ -234,4 +246,4 @@ xgettext.languages = {
'.ejs': 'EJS'
};

module.exports = xgettext;
export default xgettext;
Loading

0 comments on commit ff57136

Please sign in to comment.