कैसे देख सकते हैं और सभी टाइपप्रति सूत्रों संकलित करने के लिए?

वोट
48

मैं टाइपप्रति को एक पालतू परियोजना कन्वर्ट करने के लिए कोशिश कर रहा हूँ और उपयोग करने के लिए सक्षम होने के लिए नहीं लग रहे tscदेख सकते हैं और अपनी फ़ाइलें संकलित करने के लिए उपयोगिता। मदद का उपयोग करना चाहिए कहते हैं -wस्विच, लेकिन जैसे कि यह देख सकते हैं और संकलन नहीं कर सकते सब यह लग रहा है *.tsरिकर्सिवली कुछ निर्देशिका में फ़ाइलों। यह लगता है जैसे कुछ tscको संभालने के लिए सक्षम होना चाहिए। मेरे विकल्प क्या हैं?

09/10/2012 को 12:39
का स्रोत उपयोगकर्ता
अन्य भाषाओं में...                            


8 जवाब

वोट
74

नाम की एक फ़ाइल बनाएं tsconfig.jsonअपनी परियोजना जड़ में और उस में लाइनों में शामिल हैं:

{
    "compilerOptions": {
        "emitDecoratorMetadata": true,
        "module": "commonjs",
        "target": "ES5",
        "outDir": "ts-built",
        "rootDir": "src"
    }
}

कृपया ध्यान दें कि outDirनिर्देशिका संकलित जे एस फ़ाइलें प्राप्त करने के मार्ग का होना चाहिए, और rootDirनिर्देशिका अपने स्रोत (.ts) फ़ाइलों से युक्त के पथ होना चाहिए।

टर्मिनल खोलें और चलाने tsc -w, यह किसी भी संकलन करेंगे .tsमें फ़ाइल srcमें निर्देशिका .jsऔर उन्हें में स्टोर ts-builtनिर्देशिका।

10/05/2015 को 06:25
का स्रोत उपयोगकर्ता

वोट
20

टाइपप्रति 1.5 बीटा एक विन्यास tsconfig.json बुलाया फ़ाइल के लिए समर्थन शुरू की है। उस फ़ाइल में आप, संकलक कॉन्फ़िगर कर सकते हैं आप के लिए कोड का प्रारूपण नियमों को परिभाषित और अधिक महत्वपूर्ण अपनी परियोजना में टीएस फ़ाइलों के बारे में जानकारी के साथ प्रदान करते हैं।

एक बार ठीक से कॉन्फ़िगर किया, तो आप बस tsc आदेश चला सकते हैं और यह अपनी परियोजना में सभी टाइपप्रति कोड संकलन है।

आप इसे परिवर्तन के लिए फ़ाइलों को देखने के लिए चाहते हैं, तो आप बस tsc आदेश को --watch जोड़ सकते हैं।

यहाँ एक उदाहरण tsconfig.json फ़ाइल है

{
"compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "declaration": false,
    "noImplicitAny": false,
    "removeComments": true,
    "noLib": false
},
"include": [
    "**/*"
],
"exclude": [
    "node_modules",
    "**/*.spec.ts"
]}

उपरोक्त उदाहरण में, मैं अपने प्रोजेक्ट (रिकर्सिवली) के सभी .ts फ़ाइलों में शामिल हैं। ध्यान दें कि आप भी एक सरणी के साथ एक "बहिष्कृत" संपत्ति का उपयोग करके फ़ाइलें हटा सकते हैं।

अधिक जानकारी के लिए दस्तावेज़ देखें: http://www.typescriptlang.org/docs/handbook/tsconfig-json.html

10/06/2015 को 08:45
का स्रोत उपयोगकर्ता

वोट
8

तकनीकी रूप से आप यहाँ कुछ विकल्प हैं:

आप उदात्त पाठ की तरह एक IDE का उपयोग कर और टाइपप्रति के लिए एमएसएन प्लगइन एकीकृत कर रहे हैं, तो: http://blogs.msdn.com/b/interoperability/archive/2012/10/01/sublime-text-vi-emacs-typescript-enabled। aspx आप एक निर्माण प्रणाली है जो संकलन बना सकते हैं .tsस्रोत के लिए .jsस्वचालित रूप से। यहाँ विवरण है कि कैसे आप यह कर सकते हैं: टाइपप्रति के लिए एक उदात्त बिल्ड सिस्टम को कैसे कॉन्फ़िगर करें

आप गंतव्य के लिए स्रोत कोड को संकलित करने के भी परिभाषित कर सकते हैं .jsफ़ाइल को बचाने पर फ़ाइल। : वहाँ GitHub पर आयोजित एक उदात्त पैकेज है https://github.com/alexnj/SublimeOnSaveBuild जो केवल आपको शामिल करने चाहिए ऐसा करने के, tsमें विस्तार SublimeOnSaveBuild.sublime-settingsफ़ाइल।

एक और संभावना कमांड लाइन में प्रत्येक फ़ाइल को संकलित करने के लिए होगा। आप उन्हें तो जैसे स्थानों के द्वारा अलग करके एक बार में भी एक से अधिक फ़ाइलों को संकलित कर सकते हैं: tsc foo.ts bar.ts। इस सूत्र की जाँच करें: मैं कैसे टाइपप्रति संकलक करने के लिए कई स्रोत फ़ाइलों पारित कर सकते हैं? है, लेकिन मुझे लगता है कि पहला विकल्प अधिक उपयोगी है।

09/10/2012 को 13:30
का स्रोत उपयोगकर्ता

वोट
6

घुरघुराना का उपयोग कर इस स्वचालित करने के लिए में देखो, वहाँ कई ट्यूटोरियल के आसपास हैं, लेकिन यहां एक जल्दी शुरू है।

एक फ़ोल्डर संरचना के लिए की तरह:

blah/
blah/one.ts
blah/two.ts
blah/example/
blah/example/example.ts
blah/example/package.json
blah/example/Gruntfile.js
blah/example/index.html

आप देख सकते हैं और साथ उदाहरण फ़ोल्डर से आसानी से टाइपप्रति के साथ काम कर सकते हैं:

npm install
grunt

package.json के साथ:

{
  "name": "PROJECT",
  "version": "0.0.1",
  "author": "",
  "description": "",
  "homepage": "",
  "private": true,
  "devDependencies": {
    "typescript": "~0.9.5",
    "connect": "~2.12.0",
    "grunt-ts": "~1.6.4",
    "grunt-contrib-watch": "~0.5.3",
    "grunt-contrib-connect": "~0.6.0",
    "grunt-open": "~0.2.3"
  }
}

और एक घुरघुराना फ़ाइल:

module.exports = function (grunt) {

  // Import dependencies
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-connect');
  grunt.loadNpmTasks('grunt-open');
  grunt.loadNpmTasks('grunt-ts');

  grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    connect: {
      server: {  // <--- Run a local server on :8089
        options: {
          port: 8089,
          base: './'
        }
      }
    },
    ts: {
      lib: { // <-- compile all the files in ../ to PROJECT.js
        src: ['../*.ts'],
        out: 'PROJECT.js',
        options: {
          target: 'es3',
          sourceMaps: false,
          declaration: true,
          removeComments: false
        }
      },
      example: {  // <--- compile all the files in . to example.js
        src: ['*.ts'],
        out: 'example.js',
        options: {
          target: 'es3',
          sourceMaps: false,
          declaration: false,
          removeComments: false
        }
      }
    },
    watch: { 
      lib: { // <-- Watch for changes on the library and rebuild both
        files: '../*.ts',
        tasks: ['ts:lib', 'ts:example']
      },
      example: { // <--- Watch for change on example and rebuild
        files: ['*.ts', '!*.d.ts'],
        tasks: ['ts:example']
      }
    },
    open: { // <--- Launch index.html in browser when you run grunt
      dev: {
        path: 'http://localhost:8089/index.html'
      }
    }
  });

  // Register the default tasks to run when you run grunt
  grunt.registerTask('default', ['ts', 'connect', 'open', 'watch']);
}
29/01/2014 को 09:36
का स्रोत उपयोगकर्ता

वोट
6

Tsc संकलक केवल उन फ़ाइलों है कि आप कमांड लाइन पर गुजरती हैं देखेंगे। यह होगा नहीं फ़ाइलें है कि एक का उपयोग कर शामिल किए गए हैं घड़ी /// <sourcefile>संदर्भ। अपने बैश के साथ काम करने हैं, तो आप रिकर्सिवली सभी को खोजने के लिए खोजने के इस्तेमाल कर सकते हैं *.tsफ़ाइलों और उन्हें संकलन:

find . -name "*.ts" | xargs tsc -w
09/10/2012 को 13:30
का स्रोत उपयोगकर्ता

वोट
4

आप इस तरह से सभी फाइलों को देख सकते हैं

tsc *.ts --watch
23/11/2017 को 12:32
का स्रोत उपयोगकर्ता

वोट
3

tsc 0.9.1.1 एक है प्रतीत नहीं होता घड़ी सुविधा।

यदि आप एक इस्तेमाल कर सकते हैं PowerShell एक मैं इस पोस्ट पर किए गए की तरह स्क्रिप्ट:

स्वचालित रूप से देख सकते हैं और टाइपप्रति फ़ाइलें संकलन

09/09/2013 को 14:05
का स्रोत उपयोगकर्ता

वोट
1

आज मैं तुम्हारा के रूप में एक ही समस्या के लिए इस चींटी MacroDef तैयार किया गया है:

    <!--
    Recursively read a source directory for TypeScript files, generate a compile list in the
    format needed by the TypeScript compiler adding every parameters it take.
-->
<macrodef name="TypeScriptCompileDir">

    <!-- required attribute -->
    <attribute name="src" />

    <!-- optional attributes -->
    <attribute name="out" default="" />
    <attribute name="module" default="" />
    <attribute name="comments" default="" />
    <attribute name="declarations" default="" />
    <attribute name="nolib" default="" />
    <attribute name="target" default="" />

    <sequential>

        <!-- local properties -->
        <local name="out.arg"/>
        <local name="module.arg"/>
        <local name="comments.arg"/>
        <local name="declarations.arg"/>
        <local name="nolib.arg"/>
        <local name="target.arg"/>
        <local name="typescript.file.list"/>
        <local name="tsc.compile.file"/>

        <property name="tsc.compile.file" value="@{src}compile.list" />

        <!-- Optional arguments are not written to compile file when attributes not set -->
        <condition property="out.arg" value="" else='--out "@{out}"'>
            <equals arg1="@{out}" arg2="" />
        </condition>

        <condition property="module.arg" value="" else="--module @{module}">
            <equals arg1="@{module}" arg2="" />
        </condition>

        <condition property="comments.arg" value="" else="--comments">
            <equals arg1="@{comments}" arg2="" />
        </condition>

        <condition property="declarations.arg" value="" else="--declarations">
            <equals arg1="@{declarations}" arg2="" />
        </condition>

        <condition property="nolib.arg" value="" else="--nolib">
            <equals arg1="@{nolib}" arg2="" />
        </condition>

        <!-- Could have been defaulted to ES3 but let the compiler uses its own default is quite better -->
        <condition property="target.arg" value="" else="--target @{target}">
            <equals arg1="@{target}" arg2="" />
        </condition>

        <!-- Recursively read TypeScript source directory and generate a compile list -->
        <pathconvert property="typescript.file.list" dirsep="\" pathsep="${line.separator}">

            <fileset dir="@{src}">
                <include name="**/*.ts" />
            </fileset>

            <!-- In case regexp doesn't work on your computer, comment <mapper /> and uncomment <regexpmapper /> -->
            <mapper type="regexp" from="^(.*)$" to='"\1"' />
            <!--regexpmapper from="^(.*)$" to='"\1"' /-->

        </pathconvert>


        <!-- Write to the file -->
        <echo message="Writing tsc command line arguments to : ${tsc.compile.file}" />
        <echo file="${tsc.compile.file}" message="${typescript.file.list}${line.separator}${out.arg}${line.separator}${module.arg}${line.separator}${comments.arg}${line.separator}${declarations.arg}${line.separator}${nolib.arg}${line.separator}${target.arg}" append="false" />

        <!-- Compile using the generated compile file -->
        <echo message="Calling ${typescript.compiler.path} with ${tsc.compile.file}" />
        <exec dir="@{src}" executable="${typescript.compiler.path}">
            <arg value="@${tsc.compile.file}"/>
        </exec>

        <!-- Finally delete the compile file -->
        <echo message="${tsc.compile.file} deleted" />
        <delete file="${tsc.compile.file}" />

    </sequential>

</macrodef>

साथ अपने निर्माण फ़ाइल में उपयोग करें:

    <!-- Compile a single JavaScript file in the bin dir for release -->
    <TypeScriptCompileDir
        src="${src-js.dir}"
        out="${release-file-path}"
        module="amd"
    />

यह परियोजना में प्रयोग किया जाता है PureMVC टाइपप्रति के लिए मैं Webstorm का उपयोग कर समय पर काम कर रहा हूँ।

24/10/2012 को 23:37
का स्रोत उपयोगकर्ता

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more